Fix rejoining and zspawning as human if player was zombie this round.

This commit is contained in:
BotoX 2020-12-05 20:38:16 +01:00
parent e2e15972e2
commit d15957de1b
3 changed files with 48 additions and 0 deletions

View File

@ -326,6 +326,7 @@ public OnClientPutInServer(client)
ZTele_OnClientPutInServer(client);
ZHPClientInit(client);
ImmunityClientInit(client);
ZSpawnOnClientPutInServer(client);
}
/**

View File

@ -63,6 +63,32 @@ stock bool:SteamidCacheAddClient(Handle:steamidcache, client)
return true;
}
/**
* Remove client serial number from the SteamID cache.
*
* @param steamidcache The SteamID cache to remove the client from.
* @param client The client index.
* @return True if the client was removed successfully, false if the client doesn't exist.
*/
stock bool:SteamidCacheRemoveClient(Handle:steamidcache, client)
{
// Get client's SteamID.
new steamid = GetSteamAccountID(client);
if (!steamid)
return false;
// Find the client in the cache.
int idx = FindValueInArray(steamidcache, steamid);
if (idx == -1)
return false;
// Remove index from the SteamID cache.
RemoveFromArray(steamidcache, idx);
// Client removed successfully.
return true;
}
/**
* Check if a client is in the SteamID cache.
*

View File

@ -44,6 +44,7 @@ new Handle:tZSpawn = INVALID_HANDLE;
* Global variable to store SteamID cache handle.
*/
new Handle:g_hZSpawnSteamIDCache = INVALID_HANDLE;
new Handle:g_hZspawnInfectedSteamIDCache = INVALID_HANDLE;
new bool:g_bZSpawnClientInfected[MAXPLAYERS + 1] = {false, ...};
@ -72,14 +73,29 @@ ZSpawnOnMapStart()
{
g_hZSpawnSteamIDCache = SteamidCacheCreate();
}
if (g_hZspawnInfectedSteamIDCache == INVALID_HANDLE)
{
g_hZspawnInfectedSteamIDCache = SteamidCacheCreate();
}
// Reset the SteamID cache.
SteamidCacheReset(g_hZSpawnSteamIDCache);
SteamidCacheReset(g_hZspawnInfectedSteamIDCache);
for(new client = 1; client <= MAXPLAYERS; client++)
g_bZSpawnClientInfected[client] = false;
}
/**
* Client is joining the server.
*
* @param client The client index.
*/
ZSpawnOnClientPutInServer(client)
{
g_bZSpawnClientInfected[client] = SteamidCacheRemoveClient(g_hZspawnInfectedSteamIDCache, client);
}
/**
* Client is leaving the server.
*
@ -102,6 +118,10 @@ ZSpawnOnClientDisconnect(client)
// Add client to the SteamID cache.
SteamidCacheAddClient(g_hZSpawnSteamIDCache, client);
// If this client was infected, remember until the next round or until they rejoin.
if(g_bZSpawnClientInfected[client])
SteamidCacheAddClient(g_hZspawnInfectedSteamIDCache, client);
g_bZSpawnClientInfected[client] = false;
}
@ -210,6 +230,7 @@ ZSpawnOnRoundStart()
{
// Reset the SteamID cache.
SteamidCacheReset(g_hZSpawnSteamIDCache);
SteamidCacheReset(g_hZspawnInfectedSteamIDCache);
for(new client = 1; client <= MAXPLAYERS; client++)
g_bZSpawnClientInfected[client] = false;