PHP Code:
public void OnPlayerSpawn(Event event, const char[] name, bool dontBroadcast)
{
int iClient = GetClientOfUserId( event.GetInt( "userid" ) );
if ( !iClient ) // if client is not connected
return;
// we have a connected client (if he's in game or not, we don't know)
if ( GetClientTeam( iClient ) == TEAM_BLUE && iClient != g_iLastDeath ) {
ChangeAliveClientTeam( iClient, TEAM_RED );
CreateTimer( 0.2, RespawnRebalanced, GetClientUserId( iClient ) ); // GetClientUserId returns the userid of a connected client, it doesn't need to be in game
}
}
PHP Code:
public Action RespawnRebalanced(Handle timer, any data) {
int iClient = GetClientOfUserId( data );
if ( iClient && !IsPlayerAlive( iClient ) ) // if the client is connected, we don't know if he's in game
TF2_RespawnPlayer( iClient );
}
GetClientOfUserId - a connected client from an userid
GetClientUserId - an userid from a connected client
those functions doesn't care if the client is in game or not
you check if the client is in game only in that iteration (code part 2).
maybe the client disconnected and he's still connected but not in game.
the solution for your problem:
PHP Code:
public Action RespawnRebalanced(Handle timer, any data) {
int iClient = GetClientOfUserId( data );
if ( iClient && IsClientInGame(iClient) && !IsPlayerAlive( iClient ) )
TF2_RespawnPlayer( iClient );
}
__________________