I am trying to hook an event for a person joining the server, when they are alive and have control over a character. In other words, I don't want anything to happen until the person who joined is not spectating, and is alive (not dead).
"player_spawn" fires when somebody joins, even if they are dead. So I hooked player_spawn and then did a check using GetClientHealth
PHP Code:
public void playerspawn(Event event, const char[] name, bool dontBroadcast)
{
int userid = GetEventInt(event, "userid");
int clientid = GetClientOfUserId(userid);
PrintToChatAll("clientID %i (%N) spawned; health %i", clientid, clientid, GetClientHealth(clientid));
if (GetClientHealth(clientid) >= 1){
//Should only happen if the person is alive.. Assuming GetClientHealth reports correct values (which it doesn't appear to be doing)
}
}
With the 3 bots dead, someone joined and the health of their dead character (Coach) was reported as 1 (not 0). Then, they left the game, and "player_spawn" fired again this time saying the dead Coach had 100 health (even though it was still dead). The only time it appeared to work correctly was when the round first began and everyone was alive, it reported everyone (me and the 3 bots) had 100 health.
Can anyone think of a better way to do this since GetClientHealth doesn't appear to be reporting correct values all the time?