Moved spawn protect to its own module.
This commit is contained in:
parent
8d9d45790b
commit
c8989eb544
@ -42,6 +42,9 @@
|
|||||||
// Knockback
|
// Knockback
|
||||||
#include "zr/knockback"
|
#include "zr/knockback"
|
||||||
|
|
||||||
|
// Spawn protect
|
||||||
|
#include "zr/spawnprotect"
|
||||||
|
|
||||||
#include "zr/zadmin"
|
#include "zr/zadmin"
|
||||||
#include "zr/damagecontrol"
|
#include "zr/damagecontrol"
|
||||||
#include "zr/commands"
|
#include "zr/commands"
|
||||||
|
@ -139,23 +139,23 @@ public Action:AntiStickTimer(Handle:timer)
|
|||||||
* Re-solidifies a player being unstuck.
|
* Re-solidifies a player being unstuck.
|
||||||
*
|
*
|
||||||
* @param timer The timer handle.
|
* @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.
|
// 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;
|
return Plugin_Stop;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Stop if the player is still stuck.
|
// Stop if the player is still stuck.
|
||||||
if (AntiStickIsStuck(index) > -1)
|
if (AntiStickIsStuck(client) > -1)
|
||||||
{
|
{
|
||||||
return Plugin_Continue;
|
return Plugin_Continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
NoCollide(index, false);
|
NoCollide(client, false);
|
||||||
|
|
||||||
return Plugin_Stop;
|
return Plugin_Stop;
|
||||||
}
|
}
|
||||||
|
@ -169,6 +169,7 @@ public Action:PlayerSpawn(Handle:event, const String:name[], bool:dontBroadcast)
|
|||||||
SetPlayerFOV(index, 90);
|
SetPlayerFOV(index, 90);
|
||||||
ClientCommand(index, "r_screenoverlay \"\"");
|
ClientCommand(index, "r_screenoverlay \"\"");
|
||||||
|
|
||||||
|
// Stop here if client isn't on a team.
|
||||||
new team = GetClientTeam(index);
|
new team = GetClientTeam(index);
|
||||||
if (team != CS_TEAM_T && team != CS_TEAM_CT)
|
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);
|
NightVisionOn(index, false);
|
||||||
NightVision(index, false);
|
NightVision(index, false);
|
||||||
|
|
||||||
pProtect[index] = false;
|
|
||||||
if (zombieSpawned)
|
if (zombieSpawned)
|
||||||
{
|
{
|
||||||
if (team == CS_TEAM_T)
|
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_SwitchTeam(index, CS_TEAM_CT);
|
||||||
CS_RespawnPlayer(index);
|
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
|
else
|
||||||
{
|
{
|
||||||
@ -230,6 +202,7 @@ public Action:PlayerSpawn(Handle:event, const String:name[], bool:dontBroadcast)
|
|||||||
|
|
||||||
// Forward event to modules.
|
// Forward event to modules.
|
||||||
ClassOnClientSpawn(index);
|
ClassOnClientSpawn(index);
|
||||||
|
SpawnProtectPlayerSpawn(index);
|
||||||
ZTeleClientSpawned(index);
|
ZTeleClientSpawned(index);
|
||||||
|
|
||||||
ZR_PrintToChat(index, "!zmenu reminder");
|
ZR_PrintToChat(index, "!zmenu reminder");
|
||||||
|
145
src/zr/spawnprotect.inc
Normal file
145
src/zr/spawnprotect.inc
Normal file
@ -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;
|
||||||
|
}
|
@ -194,14 +194,6 @@ Zombify_Mother(client)
|
|||||||
tHandles[client][TMOAN] = CreateTimer(interval, ZombieMoanTimer, client, TIMER_REPEAT);
|
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)
|
if (tHandles[client][TZHP] != INVALID_HANDLE)
|
||||||
{
|
{
|
||||||
KillTimer(tHandles[client][TZHP]);
|
KillTimer(tHandles[client][TZHP]);
|
||||||
@ -270,15 +262,6 @@ Zombify(client, attacker = -1, bool:motherinfect = false)
|
|||||||
tHandles[client][TMOAN] = CreateTimer(interval, ZombieMoanTimer, client, TIMER_REPEAT);
|
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.
|
// Kill HP display timer.
|
||||||
if (tHandles[client][TZHP] != INVALID_HANDLE)
|
if (tHandles[client][TZHP] != INVALID_HANDLE)
|
||||||
{
|
{
|
||||||
@ -635,36 +618,6 @@ public Action:ZHPTimer(Handle:timer, any:index)
|
|||||||
return Plugin_Continue;
|
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)
|
RespawnPlayer(client)
|
||||||
{
|
{
|
||||||
if (!IsClientInGame(client))
|
if (!IsClientInGame(client))
|
||||||
|
@ -77,8 +77,6 @@ new bool:dispHP[MAXPLAYERS + 1];
|
|||||||
new bool:pProtect[MAXPLAYERS + 1];
|
new bool:pProtect[MAXPLAYERS + 1];
|
||||||
new bool:gKilledByWorld[MAXPLAYERS + 1] = {false, ...};
|
new bool:gKilledByWorld[MAXPLAYERS + 1] = {false, ...};
|
||||||
|
|
||||||
new pTimeLeft[MAXPLAYERS + 1];
|
|
||||||
|
|
||||||
new Float:spawnLoc[MAXPLAYERS + 1][3];
|
new Float:spawnLoc[MAXPLAYERS + 1][3];
|
||||||
new Float:bufferLoc[MAXPLAYERS + 1][3];
|
new Float:bufferLoc[MAXPLAYERS + 1][3];
|
||||||
new bool:ztele_spawned[MAXPLAYERS + 1] = {false, ...};
|
new bool:ztele_spawned[MAXPLAYERS + 1] = {false, ...};
|
||||||
@ -97,15 +95,14 @@ new Handle:tInfect = INVALID_HANDLE;
|
|||||||
|
|
||||||
new Handle:pList = INVALID_HANDLE;
|
new Handle:pList = INVALID_HANDLE;
|
||||||
|
|
||||||
#define MAXTIMERS 7
|
#define MAXTIMERS 6
|
||||||
|
|
||||||
#define TMOAN 0
|
#define TMOAN 0
|
||||||
#define TREGEN 1
|
#define TREGEN 1
|
||||||
#define TTELE 2
|
#define TTELE 2
|
||||||
#define TZHP 3
|
#define TZHP 3
|
||||||
#define TPROTECT 4
|
#define TRESPAWN 4
|
||||||
#define TRESPAWN 5
|
#define TZVISION 5
|
||||||
#define TZVISION 6
|
|
||||||
|
|
||||||
new Handle:tHandles[MAXPLAYERS + 1][MAXTIMERS];
|
new Handle:tHandles[MAXPLAYERS + 1][MAXTIMERS];
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user