From cec31406d055fdf63e632ca416b2e5cff1601b6d Mon Sep 17 00:00:00 2001 From: Greyscale Date: Wed, 6 May 2009 03:04:55 +0200 Subject: [PATCH] Added a timelimit to zspawn. --- .../translations/zombiereloaded.phrases.txt | 11 ++ src/zombiereloaded.sp | 1 + src/zr/cvars.inc | 4 + src/zr/event.inc | 3 + src/zr/zspawn.inc | 125 +++++++++++++++++- 5 files changed, 142 insertions(+), 2 deletions(-) diff --git a/cstrike/addons/sourcemod/translations/zombiereloaded.phrases.txt b/cstrike/addons/sourcemod/translations/zombiereloaded.phrases.txt index fe29759..2c5b5e0 100644 --- a/cstrike/addons/sourcemod/translations/zombiereloaded.phrases.txt +++ b/cstrike/addons/sourcemod/translations/zombiereloaded.phrases.txt @@ -66,6 +66,11 @@ "en" "This feature requires that you are dead." } + "Must be on team" + { + "en" "This feature requires that you are on a team." + } + "Must be zombie" { "en" "This feature requires that you are a zombie. @@ -368,6 +373,12 @@ "en" "ZSpawn can only be used if you joined late during a round in progress." } + "ZSpawn timelimit" + { + "#format" "{1:d}" + "en" "The timelimit, to use ZSpawn, ({1} seconds) has already expired." + } + // =========================== // ZTele // =========================== diff --git a/src/zombiereloaded.sp b/src/zombiereloaded.sp index 425db11..09cd2cd 100644 --- a/src/zombiereloaded.sp +++ b/src/zombiereloaded.sp @@ -173,6 +173,7 @@ public OnMapStart() InfectOnMapStart(); SEffectsOnMapStart(); AntiStickOnMapStart(); + ZSpawnOnMapStart(); Anticamp_Startup(); } diff --git a/src/zr/cvars.inc b/src/zr/cvars.inc index b94781e..9bcf50f 100644 --- a/src/zr/cvars.inc +++ b/src/zr/cvars.inc @@ -96,6 +96,8 @@ enum CvarsList Handle:CVAR_RESPAWN_ZOMBIE, Handle:CVAR_RESPAWN_ZOMBIE_WORLD, Handle:CVAR_ZSPAWN, + Handle:CVAR_ZSPAWN_TIMELIMIT, + Handle:CVAR_ZSPAWN_TIMELIMIT_TIME, Handle:CVAR_ZTELE_ZOMBIE, Handle:CVAR_ZTELE_HUMAN_BEFORE, Handle:CVAR_ZTELE_HUMAN_AFTER, @@ -432,6 +434,8 @@ CvarsCreate() g_hCvarsList[CVAR_ZSPAWN] = CreateConVar("zr_zspawn", "1", ""); // Old Desc: Allow players to spawn if they just joined the game (0: Disable) + g_hCvarsList[CVAR_ZSPAWN_TIMELIMIT] = CreateConVar("zr_zspawn_timelimit", "1", ""); + g_hCvarsList[CVAR_ZSPAWN_TIMELIMIT_TIME] = CreateConVar("zr_zspawn_timelimit_time", "120", ""); // =========================== // ZTele (module) // =========================== diff --git a/src/zr/event.inc b/src/zr/event.inc index 7bf0ffc..315f673 100644 --- a/src/zr/event.inc +++ b/src/zr/event.inc @@ -92,6 +92,7 @@ public Action:EventRoundFreezeEnd(Handle:event, const String:name[], bool:dontBr // Forward events to modules. RoundEndOnRoundFreezeEnd(); InfectOnRoundFreezeEnd(); + ZSpawnOnRoundFreezeEnd(); } /** @@ -112,6 +113,7 @@ public Action:EventRoundEnd(Handle:event, const String:name[], bool:dontBroadcas InfectOnRoundEnd(); SEffectsOnRoundEnd(); RespawnOnRoundEnd(); + ZSpawnOnRoundEnd(); } /** @@ -258,6 +260,7 @@ public Action:EventPlayerDeath(Handle:event, const String:name[], bool:dontBroad SEffectsOnClientDeath(index); SpawnProtectOnClientDeath(index); RespawnOnClientDeath(index, attacker, weapon); + ZSpawnOnClientDeath(index); ZTeleOnClientDeath(index); ZHPOnClientDeath(index); } diff --git a/src/zr/zspawn.inc b/src/zr/zspawn.inc index 9ebfb5a..904fc7a 100644 --- a/src/zr/zspawn.inc +++ b/src/zr/zspawn.inc @@ -10,11 +10,25 @@ * ============================================================================ */ +/** + * Global variable to store infect timer handle. + */ +new Handle:tZSpawn = INVALID_HANDLE; + /** * Array to block zspawn for a unique client serial number. */ new bool:g_bZSpawnBlock[MAXPLAYERS + 1]; +/** + * Map is starting. + */ +ZSpawnOnMapStart() +{ + // Reset timer handle. + tZSpawn = INVALID_HANDLE; +} + /** * Client is leaving the server. * @@ -29,6 +43,20 @@ ZSpawnOnClientDisconnect(client) g_bZSpawnBlock[serial] = true; } +/** + * Client has been killed. + * + * @param client The client index. + */ +ZSpawnOnClientDeath(client) +{ + // Get client's unique serial number. + new serial = GetClientSerial(client); + + // Block zspawn. + g_bZSpawnBlock[serial] = true; +} + /** * The round is starting. */ @@ -41,6 +69,65 @@ ZSpawnOnRoundStart() // Unblock zspawn. g_bZSpawnBlock[x] = false; } + + // If zspawn timer is running, then kill it. + if (tZSpawn != INVALID_HANDLE) + { + // Kill timer. + KillTimer(tZSpawn); + + // Reset timer handle. + tZSpawn = INVALID_HANDLE; + } +} + +/** + * The freeze time is ending. + */ +ZSpawnOnRoundFreezeEnd() +{ + // If infect timer is running, then kill it. + if (tZSpawn != INVALID_HANDLE) + { + // Kill timer. + KillTimer(tZSpawn); + } + + // If zspawn is disabled, then stop. + new bool:zspawn = GetConVarBool(g_hCvarsList[CVAR_ZSPAWN]); + if (!zspawn) + { + return; + } + + // If timelimit is disabled, then stop. + new bool:zspawntimelimit = GetConVarBool(g_hCvarsList[CVAR_ZSPAWN_TIMELIMIT]); + if (!zspawntimelimit) + { + return; + } + + // Get timelimit + new Float:zspawntime = GetConVarFloat(g_hCvarsList[CVAR_ZSPAWN_TIMELIMIT_TIME]); + + // Start timer. + tZSpawn = CreateTimer(zspawntime, ZSpawnTimer, _, TIMER_FLAG_NO_MAPCHANGE); +} + +/** + * The round is ending. + */ +ZSpawnOnRoundEnd() +{ + // If zspawn timer is running, then kill it. + if (tZSpawn != INVALID_HANDLE) + { + // Kill timer. + KillTimer(tZSpawn); + + // Reset timer handle. + tZSpawn = INVALID_HANDLE; + } } /** @@ -59,11 +146,19 @@ bool:ZSpawnClient(client) return false; } + // If client isn't on a team, then stop. + if (!ZRIsClientOnTeam(client)) + { + // Tell client the command may only be used when on a team. + ZR_PrintToChat(client, "Must be on team"); + return false; + } + // If client is alive, then stop. if (IsPlayerAlive(client)) { - // Tell client the command may only be used when joining late. - ZR_PrintToChat(client, "Must be alive"); + // Tell client the command may only be used when dead. + ZR_PrintToChat(client, "Must be dead"); return false; } @@ -76,8 +171,34 @@ bool:ZSpawnClient(client) return false; } + // Block is the time limit is up. + new bool:zspawntimelimit = GetConVarBool(g_hCvarsList[CVAR_ZSPAWN_TIMELIMIT]); + if (zspawntimelimit) + { + if (tZSpawn == INVALID_HANDLE) + { + // Get timelimit + new Float:zspawntime = GetConVarFloat(g_hCvarsList[CVAR_ZSPAWN_TIMELIMIT_TIME]); + + // Tell client the timelimit for this command has expired. + ZR_PrintToChat(client, "ZSpawn timelimit", RoundToNearest(zspawntime)); + return false; + } + } + // Tell respawn module to respawn client. RespawnSpawnClient(client); return true; } + +/** + * Timer callback, resets handle. + * + * @param timer The timer handle. + */ +public Action:ZSpawnTimer(Handle:timer) +{ + // Reset timer handle. + tZSpawn = INVALID_HANDLE; +} \ No newline at end of file