From 5b59f20858e868f51d0babb1659946596352812d Mon Sep 17 00:00:00 2001 From: Richard Helgeby Date: Sun, 22 Mar 2015 18:39:45 +0100 Subject: [PATCH] Extract function ZTeleHasReachedLimit. --- src/zr/ztele.inc | 37 ++++++++++++++++++++++++++++++++----- 1 file changed, 32 insertions(+), 5 deletions(-) diff --git a/src/zr/ztele.inc b/src/zr/ztele.inc index 1aa1577..fbdef2a 100644 --- a/src/zr/ztele.inc +++ b/src/zr/ztele.inc @@ -145,12 +145,11 @@ bool:ZTeleClient(client, bool:force = false) return false; } - // If the tele limit has been reached, then stop. - new ztelemax = infected ? GetConVarInt(g_hCvarsList[CVAR_ZTELE_MAX_ZOMBIE]) : GetConVarInt(g_hCvarsList[CVAR_ZTELE_MAX_HUMAN]); - if (!force && g_iZTeleCount[client] >= ztelemax) + if (!force && ZTeleHasReachedLimit(client)) { // Tell client that they have already reached their limit. - TranslationPrintToChat(client, "ZTele max", ztelemax); + int maxTeleports = ZTeleGetClientLimit(client); + TranslationPrintToChat(client, "ZTele max", maxTeleports); return false; } @@ -197,7 +196,8 @@ bool:ZTeleClient(client, bool:force = false) // If we're forcing the ZTele, then don't increment the count or print how many teleports they have used. // Tell client they've been teleported. - TranslationPrintCenterText(client, "ZTele countdown end", g_iZTeleCount[client], ztelemax); + int maxTeleports = ZTeleGetClientLimit(client); + TranslationPrintCenterText(client, "ZTele countdown end", g_iZTeleCount[client], maxTeleports); } return true; @@ -462,3 +462,30 @@ ZTeleCanHumanTeleport() // after zombies have spawned. return InfectHasZombieSpawned() ? GetConVarBool(g_hCvarsList[CVAR_ZTELE_HUMAN_AFTER]) : GetConVarBool(g_hCvarsList[CVAR_ZTELE_HUMAN_BEFORE]); } + +int ZTeleGetZombieLimit() +{ + return GetConVarInt(g_hCvarsList[CVAR_ZTELE_MAX_ZOMBIE]); +} + +int ZTeleGetHumanLimit() +{ + return GetConVarInt(g_hCvarsList[CVAR_ZTELE_MAX_HUMAN]); +} + +int ZTeleGetTeleportCount(int client) +{ + return g_iZTeleCount[client]; +} + +int ZTeleGetClientLimit(int client) +{ + return InfectIsClientInfected(client) ? ZTeleGetZombieLimit() : ZTeleGetHumanLimit(); +} + +bool ZTeleHasReachedLimit(int client) +{ + int teleportCount = ZTeleGetTeleportCount(client); + int maxTeleports = ZTeleGetClientLimit(client); + return teleportCount >= maxTeleports; +}