Raised This Month: $12 Target: $400
 3% 

Trying to target a client that is not ingame after verification


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
andrept4
Senior Member
Join Date: Dec 2012
Location: Portugal
Old 03-29-2020 , 21:23   Trying to target a client that is not ingame after verification
Reply With Quote #1

I made this plugin:

Code:
#pragma semicolon 1

#include <sourcemod>
#include <cstrike>
#include <sdktools>
#include <colors.inc>

#pragma newdecls required

public void OnPluginStart()
{
	HookEvent("round_start", OnRoundStart);
	HookEvent("round_end", OnRoundEnd);
}

public Action OnRoundStart(Event event, const char[] name, bool dontBroadcast) {
	for (int i = 1; i <= MaxClients; i++) {
		if(IsPlayerAlive(i) && IsClientInGame(i)) {
			if((GetUserFlagBits(i) & ADMFLAG_RESERVATION) == ADMFLAG_RESERVATION) {
				SetEntProp(i, Prop_Send, "m_ArmorValue", 100.0, 1);
				if((GetUserFlagBits(i) & ADMFLAG_CUSTOM1) == ADMFLAG_CUSTOM1) {
					if(GetClientTeam(i) == CS_TEAM_CT) {
						if(!GetEntProp(i, Prop_Data, "m_bHasDefuser")) {
							GivePlayerItem(i, "item_defuser");
							CPrintToChat(i, "{darkred}[PUNT]{default} Recebeste o defuse kit por seres Sponsor!!!");
						}
					}
					SetEntProp(i, Prop_Send, "m_bHasHelmet", 1);
				}
				GivePlayerItem(i, "weapon_hegrenade");
				GivePlayerItem(i, "weapon_flashbang");
				GivePlayerItem(i, "weapon_smokegrenade");
				if(GetClientTeam(i) == CS_TEAM_CT) {
					GivePlayerItem(i, "weapon_incgrenade");
				} else if(GetClientTeam(i) == CS_TEAM_T) {
					GivePlayerItem(i, "weapon_molotov");
				}
				
				CPrintToChat(i, "{darkred}[PUNT]{default} Recebeste granadas por seres VIP!!!");
			}
		}
	}
	
	return Plugin_Handled;
}

public Action OnRoundEnd(Event event, const char[] name, bool dontBroadcast) {
	
	for (int i = 1; i <= MaxClients; i++) {
		if(IsPlayerAlive(i) && IsClientInGame(i)) {
			if((GetUserFlagBits(i) & ADMFLAG_RESERVATION) == ADMFLAG_RESERVATION) {
				int ent = -1;
				while((ent = GetPlayerWeaponSlot(i, CS_SLOT_GRENADE)) != -1) {
					if(IsValidEntity(ent)) {
						RemovePlayerItem(i, ent);
						AcceptEntityInput(ent, "Kill");
					}
				}
			}
		}
	}
	
	return Plugin_Handled;
}
and it stops working after first round and this error shows up in the log:

Spoiler
__________________
andrept4 is offline
ddhoward
Veteran Member
Join Date: May 2012
Location: California
Old 03-30-2020 , 01:12   Re: Trying to target a client that is not ingame after verification
Reply With Quote #2

When you say "after", you are mistaken.

Look at the 4th line of your error. The error is happening because of IsPlayerAlive and IsPlayerAlive is complaining that the client is not in game. That's because the client is not in game. You need to check that the client is in game BEFORE you check is the player is alive.

Switch around your IsPlayerAlive(i) and IsClientInGame(i) checks.
__________________
ddhoward is offline
andrept4
Senior Member
Join Date: Dec 2012
Location: Portugal
Old 03-30-2020 , 04:05   Re: Trying to target a client that is not ingame after verification
Reply With Quote #3

Quote:
Originally Posted by ddhoward View Post
When you say "after", you are mistaken.

Look at the 4th line of your error. The error is happening because of IsPlayerAlive and IsPlayerAlive is complaining that the client is not in game. That's because the client is not in game. You need to check that the client is in game BEFORE you check is the player is alive.

Switch around your IsPlayerAlive(i) and IsClientInGame(i) checks.
OH wow, I'm so dumb sometimes.. thanks! xD
__________________
andrept4 is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 05:43.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode