View Single Post
ThatKidWhoGames
Veteran Member
Join Date: Jun 2013
Location: IsValidClient()
Old 02-06-2019 , 10:39   Re: [REQ] CVar change when all players die
Reply With Quote #4

Quote:
Originally Posted by CliptonHeist View Post
Untested, lemme know if this does/doesn't work.
PHP Code:
#include <sourcemod>

#pragma semicolon 1
#pragma newdecls required

public void OnPluginStart()
{
    
HookEvent("round_start"Event_RoundStart);
    
HookEvent("player_death"Event_PlayerDeathEventHookMode_Post);
}

public 
void Event_RoundStart(Event event, const char[] namebool dontBroadcast)
{
    
SetConVarInt(FindConVar("mp_ignore_round_win_conditions"), 1);
}

public 
void Event_PlayerDeath(Event event, const char[] namebool dontBroadcast)
{
    
bool bDead true;
    for(
int i 1<= MaxClientsi++)
    {
        if(!
IsValidClient(i)) continue;

        if(
IsPlayerAlive(i)) 
        {
            
bDead false;
            break;
        }
    }

    if(
bDeadSetConVarInt(FindConVar("mp_ignore_round_win_conditions"), 0);
}

stock bool IsValidClient(int client)
{
    return 
client >= && 
    
client <= MaxClients && 
    
IsClientConnected(client) && 
    
IsClientAuthorized(client) && 
    
IsClientInGame(client);

The IsValidClient check is unnecessary. You can simply just run IsClientInGame since the client is guaranteed to be >= 1 and <= MaxClients. Also, IsClientInGame already checks if IsClientConnected is true.
ThatKidWhoGames is offline