From d15957de1b7dfdde200c6cc7a9490c8447248b9d Mon Sep 17 00:00:00 2001 From: BotoX Date: Sat, 5 Dec 2020 20:38:16 +0100 Subject: [PATCH] Fix rejoining and zspawning as human if player was zombie this round. --- src/zombiereloaded.sp | 1 + src/zr/steamidcache.inc | 26 ++++++++++++++++++++++++++ src/zr/zspawn.inc | 21 +++++++++++++++++++++ 3 files changed, 48 insertions(+) diff --git a/src/zombiereloaded.sp b/src/zombiereloaded.sp index 9ffaf2c..593fa24 100644 --- a/src/zombiereloaded.sp +++ b/src/zombiereloaded.sp @@ -326,6 +326,7 @@ public OnClientPutInServer(client) ZTele_OnClientPutInServer(client); ZHPClientInit(client); ImmunityClientInit(client); + ZSpawnOnClientPutInServer(client); } /** diff --git a/src/zr/steamidcache.inc b/src/zr/steamidcache.inc index 3eb9e5e..e924855 100644 --- a/src/zr/steamidcache.inc +++ b/src/zr/steamidcache.inc @@ -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. * diff --git a/src/zr/zspawn.inc b/src/zr/zspawn.inc index ef94d20..ba59f2e 100644 --- a/src/zr/zspawn.inc +++ b/src/zr/zspawn.inc @@ -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;