Add ZTeleStopTimer to reduce duplicated code.

This change also requires that timers are stopped when clients disconnects.
This commit is contained in:
Richard Helgeby 2015-03-22 17:42:02 +01:00
parent 8e6d4f0f35
commit 918dd3100b
2 changed files with 19 additions and 26 deletions

View File

@ -335,6 +335,7 @@ public OnClientDisconnect(client)
ZSpawnOnClientDisconnect(client); ZSpawnOnClientDisconnect(client);
VolOnPlayerDisconnect(client); VolOnPlayerDisconnect(client);
ImmunityOnClientDisconnect(client); ImmunityOnClientDisconnect(client);
ZTeleOnClientDisconnect(client);
} }
/** /**

View File

@ -69,8 +69,7 @@ ZTeleOnCommandsCreate()
*/ */
ZTeleClientInit(client) ZTeleClientInit(client)
{ {
// Reset timer handle. ZTeleStopTimer(client);
tZTele[client] = INVALID_HANDLE;
} }
/** /**
@ -86,14 +85,7 @@ ZTeleOnClientSpawn(client)
// Get spawn location. // Get spawn location.
GetClientAbsOrigin(client, g_vecZTeleSpawn[client]); GetClientAbsOrigin(client, g_vecZTeleSpawn[client]);
// If timer is running, kill it. ZTeleStopTimer(client);
if (tZTele[client] != INVALID_HANDLE)
{
KillTimer(tZTele[client]);
}
// Reset timer handle.
tZTele[client] = INVALID_HANDLE;
} }
/** /**
@ -103,14 +95,12 @@ ZTeleOnClientSpawn(client)
*/ */
ZTeleOnClientDeath(client) ZTeleOnClientDeath(client)
{ {
// If timer is running, kill it. ZTeleStopTimer(client);
if (tZTele[client] != INVALID_HANDLE) }
{
KillTimer(tZTele[client]); ZTeleOnClientDisconnect(client)
} {
ZTeleStopTimer(client);
// Reset timer handle.
tZTele[client] = INVALID_HANDLE;
} }
/** /**
@ -120,14 +110,7 @@ ZTeleOnClientDeath(client)
*/ */
ZTeleOnClientInfected(client) ZTeleOnClientInfected(client)
{ {
// If timer is running, kill it. ZTeleStopTimer(client);
if (tZTele[client] != INVALID_HANDLE)
{
KillTimer(tZTele[client]);
}
// Reset timer handle.
tZTele[client] = INVALID_HANDLE;
} }
/** /**
@ -460,3 +443,12 @@ public Action:ZTeleTimer(Handle:timer, any:client)
// Allow timer to continue repeating. // Allow timer to continue repeating.
return Plugin_Continue; return Plugin_Continue;
} }
ZTeleStopTimer(client)
{
if (tZTele[client] != INVALID_HANDLE)
{
KillTimer(tZTele[client]);
}
tZTele[client] = INVALID_HANDLE;
}