From c8989eb544cd79db53a627df2c37c131cd27fe2e Mon Sep 17 00:00:00 2001 From: Greyscale Date: Wed, 15 Apr 2009 11:27:03 +0200 Subject: [PATCH] Moved spawn protect to its own module. --- src/zombiereloaded.sp | 3 + src/zr/antistick.inc | 10 +-- src/zr/event.inc | 31 +------- src/zr/spawnprotect.inc | 145 ++++++++++++++++++++++++++++++++++++++ src/zr/zombie.inc | 47 ------------ src/zr/zombiereloaded.inc | 9 +-- 6 files changed, 158 insertions(+), 87 deletions(-) create mode 100644 src/zr/spawnprotect.inc diff --git a/src/zombiereloaded.sp b/src/zombiereloaded.sp index c5bd428..f43dd42 100644 --- a/src/zombiereloaded.sp +++ b/src/zombiereloaded.sp @@ -42,6 +42,9 @@ // Knockback #include "zr/knockback" +// Spawn protect +#include "zr/spawnprotect" + #include "zr/zadmin" #include "zr/damagecontrol" #include "zr/commands" diff --git a/src/zr/antistick.inc b/src/zr/antistick.inc index 9ac1473..7071189 100644 --- a/src/zr/antistick.inc +++ b/src/zr/antistick.inc @@ -139,23 +139,23 @@ public Action:AntiStickTimer(Handle:timer) * Re-solidifies a player being unstuck. * * @param timer The timer handle. - * @param index The client index. + * @param client The client index. */ -public Action:AntiStickSolidify(Handle:timer, any:index) +public Action:AntiStickSolidify(Handle:timer, any:client) { // Validate player is in-game, alive, and is being unstuck. - if (!IsClientInGame(index) || !IsPlayerAlive(index) || CanCollide(index)) + if (!IsClientInGame(client) || !IsPlayerAlive(client) || CanCollide(client)) { return Plugin_Stop; } // Stop if the player is still stuck. - if (AntiStickIsStuck(index) > -1) + if (AntiStickIsStuck(client) > -1) { return Plugin_Continue; } - NoCollide(index, false); + NoCollide(client, false); return Plugin_Stop; } diff --git a/src/zr/event.inc b/src/zr/event.inc index be9ed29..9936754 100644 --- a/src/zr/event.inc +++ b/src/zr/event.inc @@ -169,6 +169,7 @@ public Action:PlayerSpawn(Handle:event, const String:name[], bool:dontBroadcast) SetPlayerFOV(index, 90); ClientCommand(index, "r_screenoverlay \"\""); + // Stop here if client isn't on a team. new team = GetClientTeam(index); if (team != CS_TEAM_T && team != CS_TEAM_CT) { @@ -186,7 +187,6 @@ public Action:PlayerSpawn(Handle:event, const String:name[], bool:dontBroadcast) NightVisionOn(index, false); NightVision(index, false); - pProtect[index] = false; if (zombieSpawned) { if (team == CS_TEAM_T) @@ -194,34 +194,6 @@ public Action:PlayerSpawn(Handle:event, const String:name[], bool:dontBroadcast) CS_SwitchTeam(index, CS_TEAM_CT); CS_RespawnPlayer(index); } - - new protect = GetConVarInt(gCvars[CVAR_PROTECT]); - if (protect > 0) - { - decl String:respawnteam[32]; - GetConVarString(gCvars[CVAR_RESPAWN_TEAM], respawnteam, sizeof(respawnteam)); - - if (!StrEqual(respawnteam, "zombie", false) && !(GetConVarBool(gCvars[CVAR_SUICIDE_WORLD_DAMAGE]) && gKilledByWorld[index])) - { - SetPlayerAlpha(index, 0); - SetPlayerSpeed(index, 600.0); - pProtect[index] = true; - - ZR_PrintToChat(index, "Spawn protection begin", protect); - ZR_PrintCenterText(index, "Spawn protection begin", protect); - - if (tHandles[index][TPROTECT] != INVALID_HANDLE) - { - KillTimer(tHandles[index][TPROTECT]); - } - - pTimeLeft[index] = protect; - - PrintHintText(index, "%d", pTimeLeft[index]); - - tHandles[index][TPROTECT] = CreateTimer(1.0, ProtectTimer, index, TIMER_FLAG_NO_MAPCHANGE|TIMER_REPEAT); - } - } } else { @@ -230,6 +202,7 @@ public Action:PlayerSpawn(Handle:event, const String:name[], bool:dontBroadcast) // Forward event to modules. ClassOnClientSpawn(index); + SpawnProtectPlayerSpawn(index); ZTeleClientSpawned(index); ZR_PrintToChat(index, "!zmenu reminder"); diff --git a/src/zr/spawnprotect.inc b/src/zr/spawnprotect.inc new file mode 100644 index 0000000..9104129 --- /dev/null +++ b/src/zr/spawnprotect.inc @@ -0,0 +1,145 @@ +/* + * ============================================================================ + * + * Zombie:Reloaded + * + * File: spawnprotect.inc + * Description: Protects late-joining players from zombies for x seconds. + * + * ============================================================================ + */ + +/** + * Array for storing spawn protect timer handles per client. + */ +new Handle:tSpawnProtect[MAXPLAYERS + 1]; + +/** + * Array for flagging client to be protected. + */ +new bool:pSpawnProtect[MAXPLAYERS + 1]; + +/** + * Array for storing time left for spawn protection per client. + */ +new pSpawnProtectTime[MAXPLAYERS + 1]; + +/** + * Client is joining the server. + * + * @param client The client index. + */ +SpawnProtectClientInit(client) +{ + tSpawnProtect[client] = INVALID_HANDLE; +} + +/** + * Player is spawning into the game. + * + * @param client The client index. + */ +SpawnProtectPlayerSpawn(client) +{ + // Disable spawn protection on client. + pSpawnProtect[client] = false; + + // If zombie hasn't spawned, then stop. + if (!zombieSpawned) + { + return; + } + + // If protect cvar is invalid or 0, then stop. + new protect = GetConVarInt(gCvars[CVAR_PROTECT]); + if (protect <= 0) + { + return; + } + + // Get respawn team. + decl String:respawnteam[32]; + GetConVarString(gCvars[CVAR_RESPAWN_TEAM], respawnteam, sizeof(respawnteam)); + + // If the respawn team is not set to zombie, and either cvar zr_suicide_world_damage or the client + // wasn't killed by world is false, then continue to protect client. + if (!StrEqual(respawnteam, "zombie", false) && !(GetConVarBool(gCvars[CVAR_SUICIDE_WORLD_DAMAGE]) && gKilledByWorld[client])) + { + // Set spawn protect flag on client. + pSpawnProtect[client] = true; + + // Set improved attributes + // (Move to cvar?) + SetPlayerAlpha(client, 0); + SetPlayerSpeed(client, 600.0); + + // Set time left to zr_protect's value. + pSpawnProtectTime[client] = protect; + + // Tell client they are being protected. + ZR_PrintToChat(client, "Spawn protection begin", protect); + + // Send time left in a hud message. + ZR_HudHint(client, "Spawn Protect", pSpawnProtectTime[client]); + + // If timer is currently running, kill it. + if (tSpawnProtect[client] != INVALID_HANDLE) + { + KillTimer(tSpawnProtect[client]); + } + + // Start repeating timer. + tSpawnProtect[client] = CreateTimer(1.0, SpawnProtectTimer, client, TIMER_FLAG_NO_MAPCHANGE|TIMER_REPEAT); + } +} + +/** + * Timer callback function, countdown for spawn protection. + * + * @param timer The timer handle. + * @param client The client index. + */ +public Action:SpawnProtectTimer(Handle:timer, any:client) +{ + // If client leaves, then stop timer. + if (!IsClientInGame(client)) + { + return Plugin_Stop; + } + + // If client has become a zombie, then stop timer. + if (!IsPlayerHuman(client)) + { + return Plugin_Stop; + } + + // Decrement time left. + pSpawnProtectTime[client]--; + + // Print time left to client. + ZR_HudHint(client, "Spawn Protect", pSpawnProtectTime[client]); + + // Time has expired. + if (pSpawnProtectTime[client] <= 0) + { + // Remove protect flag. + pSpawnProtect[client] = false; + + // Tell client spawn protection is over. + ZR_HudHint(client, "Spawn protection end"); + + // Fix attributes. + // TODO: Set class attributes. + SetPlayerAlpha(client, 255); + SetPlayerSpeed(client, 300.0); + + // Clear timer handle. + tSpawnProtect[client] = INVALID_HANDLE; + + // Stop timer. + return Plugin_Stop; + } + + // Allow timer to continue repeating. + return Plugin_Continue; +} \ No newline at end of file diff --git a/src/zr/zombie.inc b/src/zr/zombie.inc index 27f5cb5..0b00983 100644 --- a/src/zr/zombie.inc +++ b/src/zr/zombie.inc @@ -194,14 +194,6 @@ Zombify_Mother(client) tHandles[client][TMOAN] = CreateTimer(interval, ZombieMoanTimer, client, TIMER_REPEAT); } - if (tHandles[client][TPROTECT] != INVALID_HANDLE) - { - pProtect[client] = false; - - KillTimer(tHandles[client][TPROTECT]); - tHandles[client][TPROTECT] = INVALID_HANDLE; - } - if (tHandles[client][TZHP] != INVALID_HANDLE) { KillTimer(tHandles[client][TZHP]); @@ -270,15 +262,6 @@ Zombify(client, attacker = -1, bool:motherinfect = false) tHandles[client][TMOAN] = CreateTimer(interval, ZombieMoanTimer, client, TIMER_REPEAT); } - // Kill spawn protection timer. - if (tHandles[client][TPROTECT] != INVALID_HANDLE) - { - pProtect[client] = false; - - KillTimer(tHandles[client][TPROTECT]); - tHandles[client][TPROTECT] = INVALID_HANDLE; - } - // Kill HP display timer. if (tHandles[client][TZHP] != INVALID_HANDLE) { @@ -635,36 +618,6 @@ public Action:ZHPTimer(Handle:timer, any:index) return Plugin_Continue; } -public Action:ProtectTimer(Handle:timer, any:index) -{ - if (!IsClientInGame(index)) - { - tHandles[index][TPROTECT] = INVALID_HANDLE; - return Plugin_Stop; - } - - pTimeLeft[index]--; - ZR_HudHint(index, "Spawn Protect", pTimeLeft[index]); - - if (pTimeLeft[index] <= 0) - { - pProtect[index] = false; - - if (IsPlayerHuman(index)) - { - ZR_HudHint(index, "Spawn protection end"); - SetPlayerAlpha(index, 255); - SetPlayerSpeed(index, 300.0); - } - - tHandles[index][TPROTECT] = INVALID_HANDLE; - - return Plugin_Stop; - } - - return Plugin_Continue; -} - RespawnPlayer(client) { if (!IsClientInGame(client)) diff --git a/src/zr/zombiereloaded.inc b/src/zr/zombiereloaded.inc index d8fb5b7..6896e6e 100644 --- a/src/zr/zombiereloaded.inc +++ b/src/zr/zombiereloaded.inc @@ -77,8 +77,6 @@ new bool:dispHP[MAXPLAYERS + 1]; new bool:pProtect[MAXPLAYERS + 1]; new bool:gKilledByWorld[MAXPLAYERS + 1] = {false, ...}; -new pTimeLeft[MAXPLAYERS + 1]; - new Float:spawnLoc[MAXPLAYERS + 1][3]; new Float:bufferLoc[MAXPLAYERS + 1][3]; new bool:ztele_spawned[MAXPLAYERS + 1] = {false, ...}; @@ -97,15 +95,14 @@ new Handle:tInfect = INVALID_HANDLE; new Handle:pList = INVALID_HANDLE; -#define MAXTIMERS 7 +#define MAXTIMERS 6 #define TMOAN 0 #define TREGEN 1 #define TTELE 2 #define TZHP 3 -#define TPROTECT 4 -#define TRESPAWN 5 -#define TZVISION 6 +#define TRESPAWN 4 +#define TZVISION 5 new Handle:tHandles[MAXPLAYERS + 1][MAXTIMERS];