AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   Trying to target a client that is not ingame after verification (https://forums.alliedmods.net/showthread.php?t=322553)

andrept4 03-29-2020 21:23

Trying to target a client that is not ingame after verification
 
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

ddhoward 03-30-2020 01:12

Re: Trying to target a client that is not ingame after verification
 
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.

andrept4 03-30-2020 04:05

Re: Trying to target a client that is not ingame after verification
 
Quote:

Originally Posted by ddhoward (Post 2689385)
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


All times are GMT -4. The time now is 23:35.

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