From 918dd3100b88ad1cf00810781d0aee45e8db17ed Mon Sep 17 00:00:00 2001 From: Richard Helgeby Date: Sun, 22 Mar 2015 17:42:02 +0100 Subject: [PATCH] Add ZTeleStopTimer to reduce duplicated code. This change also requires that timers are stopped when clients disconnects. --- src/zombiereloaded.sp | 1 + src/zr/ztele.inc | 44 ++++++++++++++++++------------------------- 2 files changed, 19 insertions(+), 26 deletions(-) diff --git a/src/zombiereloaded.sp b/src/zombiereloaded.sp index 08b8c5f..5163d1c 100644 --- a/src/zombiereloaded.sp +++ b/src/zombiereloaded.sp @@ -335,6 +335,7 @@ public OnClientDisconnect(client) ZSpawnOnClientDisconnect(client); VolOnPlayerDisconnect(client); ImmunityOnClientDisconnect(client); + ZTeleOnClientDisconnect(client); } /** diff --git a/src/zr/ztele.inc b/src/zr/ztele.inc index 33e858b..32bfef8 100644 --- a/src/zr/ztele.inc +++ b/src/zr/ztele.inc @@ -69,8 +69,7 @@ ZTeleOnCommandsCreate() */ ZTeleClientInit(client) { - // Reset timer handle. - tZTele[client] = INVALID_HANDLE; + ZTeleStopTimer(client); } /** @@ -86,14 +85,7 @@ ZTeleOnClientSpawn(client) // Get spawn location. GetClientAbsOrigin(client, g_vecZTeleSpawn[client]); - // If timer is running, kill it. - if (tZTele[client] != INVALID_HANDLE) - { - KillTimer(tZTele[client]); - } - - // Reset timer handle. - tZTele[client] = INVALID_HANDLE; + ZTeleStopTimer(client); } /** @@ -103,14 +95,12 @@ ZTeleOnClientSpawn(client) */ ZTeleOnClientDeath(client) { - // If timer is running, kill it. - if (tZTele[client] != INVALID_HANDLE) - { - KillTimer(tZTele[client]); - } - - // Reset timer handle. - tZTele[client] = INVALID_HANDLE; + ZTeleStopTimer(client); +} + +ZTeleOnClientDisconnect(client) +{ + ZTeleStopTimer(client); } /** @@ -120,14 +110,7 @@ ZTeleOnClientDeath(client) */ ZTeleOnClientInfected(client) { - // If timer is running, kill it. - if (tZTele[client] != INVALID_HANDLE) - { - KillTimer(tZTele[client]); - } - - // Reset timer handle. - tZTele[client] = INVALID_HANDLE; + ZTeleStopTimer(client); } /** @@ -460,3 +443,12 @@ public Action:ZTeleTimer(Handle:timer, any:client) // Allow timer to continue repeating. return Plugin_Continue; } + +ZTeleStopTimer(client) +{ + if (tZTele[client] != INVALID_HANDLE) + { + KillTimer(tZTele[client]); + } + tZTele[client] = INVALID_HANDLE; +}