Change:
PHP Code:
int tank = GetClientOfUserId(g_tank);
if(!IsClientInGame(tank)) return;
To:
PHP Code:
int tank = GetClientOfUserId(g_tank); // Returns 0 when the client no longer exists.
if(!g_tank || !IsClientInGame(tank)) return; // IsClientInGame(0) errors with "Client index 0 is invalid" on dedicated servers, validate g_tank is not 0 first.
// I actually think the IsClientInGame check might not be needed here because the client serial is already validated by not being 0.
Everywhere you have this, replace with the above check:
PHP Code:
int tank = GetClientOfUserId(g_tank); // GetClientOfUserId returns 0 when invalid.
if(IsValidEdict(tank)) // IsValidEdict(0) will return true because the server 0 is valid. Also IsValidEdict is for entities not clients.
EntIndexToEntRef - "Converts an entity index into a serial encoded entity reference."
EntRefToEntIndex - Retrieves the entity index from a reference.
You must use EntIndexToEntRef when storing entity indexes or putting them in a timer and EntRefToEntIndex when retrieving later. Otherwise you run the risk of affecting the wrong entity. Using EntIndexToEntRef makes a unique ID for the entity, allowing you to validate later that you're affecting the actual entity you intended.
The same must be done with clients, or you run the risk of affecting the wrong client because they disconnected:
GetClientUserId - "Retrieves a client's user id, which is an index incremented for every client that joins the server."
GetClientOfUserId - "Translates an userid index to the real player index."
__________________