From c32cda3fc9c73fb7f97312fd6a13a7574b92a23f Mon Sep 17 00:00:00 2001 From: zaCade Date: Tue, 28 Aug 2018 14:54:42 +0200 Subject: [PATCH] General: Apply ZSpawn logic on late spawners. Improvement on `a45be16399` --- src/zr/infect.inc | 10 +--- src/zr/zspawn.inc | 147 +++++++++++++++++++++++++++++++++++++--------- 2 files changed, 121 insertions(+), 36 deletions(-) diff --git a/src/zr/infect.inc b/src/zr/infect.inc index 970a9c0..b4b97eb 100644 --- a/src/zr/infect.inc +++ b/src/zr/infect.inc @@ -278,14 +278,10 @@ InfectOnClientSpawn(client) // Disable zombie flag on client. g_bZombie[client] = false; - // Check if client is spawning on the terrorist team. - if (ZRIsClientOnTeam(client, CS_TEAM_T) && InfectHasZombieSpawned()) - { - CS_SwitchTeam(client, CS_TEAM_CT); - CS_RespawnPlayer(client); - } - InfectUnglitchKevlar(client); + + // Forward event to modules. + ZSpawnOnClientSpawn(client); } /** diff --git a/src/zr/zspawn.inc b/src/zr/zspawn.inc index dc6658b..1218410 100644 --- a/src/zr/zspawn.inc +++ b/src/zr/zspawn.inc @@ -25,6 +25,16 @@ * ============================================================================ */ +/** + * Conditions for respawning players. + */ +enum ZSpawnCondition +{ + ZSpawn_Block = -1, /** Let ZR decide according to its settings. */ + ZSpawn_Human = 0, /** Respawn as a human. */ + ZSpawn_Zombie /** Respawn as a zombie. */ +} + /** * Global variable to store infect timer handle. */ @@ -106,6 +116,48 @@ ZSpawnOnClientDeath(client) SteamidCacheAddClient(g_hZSpawnSteamIDCache, client); } +/** + * Client is spawning into the game. + * + * @param client The client index. + */ +ZSpawnOnClientSpawn(client) +{ + if (InfectHasZombieSpawned()) + { + // Get our zspawn condition. + new ZSpawnCondition:condition = GetZSpawnCondition(); + + switch(condition) + { + case ZSpawn_Human: + { + // Disable zombie flag on client. + g_bZombie[client] = false; + + // Check if client is spawning on the terrorists team. + if (ZRIsClientOnTeam(client, CS_TEAM_T)) + { + CS_SwitchTeam(client, CS_TEAM_CT); + CS_RespawnPlayer(client); + } + } + case ZSpawn_Zombie: + { + // Enable zombie flag on client. + g_bZombie[client] = true; + + // Check if client is spawning on the counter-terrorists team. + if (ZRIsClientOnTeam(client, CS_TEAM_CT)) + { + CS_SwitchTeam(client, CS_TEAM_T); + CS_RespawnPlayer(client); + } + } + } + } +} + /** * Client has been infected. * @@ -253,48 +305,38 @@ bool:ZSpawnClient(client, bool:force = false, bool:zombie = false) if (!force) { - // Check if zspawn override is enabled, and if so get overidden value. - new bool:teamoverride = GetConVarBool(g_hCvarsList[CVAR_ZSPAWN_TEAM_OVERRIDE]); - teamzombie = teamoverride ? GetConVarBool(g_hCvarsList[CVAR_ZSPAWN_TEAM_ZOMBIE]) : GetConVarBool(g_hCvarsList[CVAR_RESPAWN_TEAM_ZOMBIE]); + // Get our zspawn condition. + new ZSpawnCondition:condition = GetZSpawnCondition(); - // Block is the time limit is up. - new bool:zspawntimelimit = GetConVarBool(g_hCvarsList[CVAR_ZSPAWN_TIMELIMIT]); - if (zspawntimelimit) + switch(condition) { - if (tZSpawn == INVALID_HANDLE) + case ZSpawn_Block: { - new zspawntimelimitzombie = GetConVarInt(g_hCvarsList[CVAR_ZSPAWN_TIMELIMIT_ZOMBIE]); - switch(zspawntimelimitzombie) - { - case -1: - { - // Get timelimit - new Float:zspawntime = GetConVarFloat(g_hCvarsList[CVAR_ZSPAWN_TIMELIMIT_TIME]); + // Get timelimit. + new Float:zspawntime = GetConVarFloat(g_hCvarsList[CVAR_ZSPAWN_TIMELIMIT_TIME]); - // Tell client the timelimit for this command has expired. - TranslationPrintToChat(client, "ZSpawn timelimit", RoundToNearest(zspawntime)); - return false; - } - case 0: - { - teamzombie = false; - } - case 1: - { - teamzombie = true; - } - } + // Tell client the timelimit for this command has expired. + TranslationPrintToChat(client, "ZSpawn timelimit", RoundToNearest(zspawntime)); + return false; + } + case ZSpawn_Human: + { + teamzombie = false; + } + case ZSpawn_Zombie: + { + teamzombie = true; } } - // Client has been infected this round, respawning as a zombie + // Client has been infected this round, respawning as a zombie. if(g_bZSpawnClientInfected[client]) teamzombie = true; } else { // Use the override team in the function if were forcing the spawn. - teamzombie = zombie; + teamzombie = zombie; } // Tell respawn module to respawn client. @@ -488,3 +530,50 @@ public Action:ZSpawnTimer(Handle:timer) // Reset timer handle. tZSpawn = INVALID_HANDLE; } + +/** + * Get ZSpawn condition. + */ +ZSpawnCondition:GetZSpawnCondition() +{ + new ZSpawnCondition:condition; + + // Check if zspawn override is enabled, and if so use overriden value. + if (GetConVarBool(g_hCvarsList[CVAR_ZSPAWN_TEAM_OVERRIDE])) + { + // Convert boolean to zspawn condition. + condition = GetConVarBool(g_hCvarsList[CVAR_ZSPAWN_TEAM_ZOMBIE]) ? ZSpawn_Zombie : ZSpawn_Human; + } + else + { + // Convert boolean to zspawn condition. + condition = GetConVarBool(g_hCvarsList[CVAR_RESPAWN_TEAM_ZOMBIE]) ? ZSpawn_Zombie : ZSpawn_Human; + } + + // Check if zspawn timelimit is enabled. + if (GetConVarBool(g_hCvarsList[CVAR_ZSPAWN_TIMELIMIT])) + { + // Check if zspawn timelimit is expired. + if (!ZRIsTimerRunning(tZSpawn)) + { + new zspawntimelimitzombie = GetConVarInt(g_hCvarsList[CVAR_ZSPAWN_TIMELIMIT_ZOMBIE]); + switch(zspawntimelimitzombie) + { + case -1: + { + condition = ZSpawn_Block; + } + case 0: + { + condition = ZSpawn_Human; + } + case 1: + { + condition = ZSpawn_Zombie; + } + } + } + } + + return condition; +}