2009-04-16 03:57:46 +02:00
|
|
|
/*
|
|
|
|
* ============================================================================
|
|
|
|
*
|
|
|
|
* Zombie:Reloaded
|
|
|
|
*
|
2009-05-06 02:28:09 +02:00
|
|
|
* File: spawnprotect.inc
|
|
|
|
* Type: Module
|
|
|
|
* Description: Protects late-joining players from zombies for x seconds.
|
2009-04-16 03:57:46 +02:00
|
|
|
*
|
|
|
|
* ============================================================================
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Array for storing spawn protect timer handles per client.
|
|
|
|
*/
|
|
|
|
new Handle:tSpawnProtect[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)
|
|
|
|
{
|
|
|
|
// Reset timer handle.
|
|
|
|
tSpawnProtect[client] = INVALID_HANDLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-04-16 05:30:26 +02:00
|
|
|
* Client is spawning into the game.
|
2009-04-16 03:57:46 +02:00
|
|
|
*
|
|
|
|
* @param client The client index.
|
|
|
|
*/
|
2009-04-16 05:30:26 +02:00
|
|
|
SpawnProtectOnClientSpawn(client)
|
2009-04-16 03:57:46 +02:00
|
|
|
{
|
|
|
|
// Disable spawn protection on client.
|
2009-04-22 04:53:19 +02:00
|
|
|
bInfectImmune[client][INFECT_TYPE_NORMAL] = false;
|
2009-04-16 03:57:46 +02:00
|
|
|
|
2009-04-16 05:30:26 +02:00
|
|
|
// If timer is currently running, kill it.
|
|
|
|
if (tSpawnProtect[client] != INVALID_HANDLE)
|
|
|
|
{
|
|
|
|
KillTimer(tSpawnProtect[client]);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Reset timer handle.
|
|
|
|
tSpawnProtect[client] = INVALID_HANDLE;
|
|
|
|
|
|
|
|
// If client isn't on a team, then stop.
|
|
|
|
new team = GetClientTeam(client);
|
|
|
|
if (team != CS_TEAM_T && team != CS_TEAM_CT)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-04-16 03:57:46 +02:00
|
|
|
// If zombie hasn't spawned, then stop.
|
2009-04-17 12:16:44 +02:00
|
|
|
if (!g_bZombieSpawned)
|
2009-04-16 03:57:46 +02:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-04-20 02:56:26 +02:00
|
|
|
// If protect cvar is disabled, then stop.
|
|
|
|
new bool:protect = GetConVarBool(g_hCvarsList[CVAR_SPAWNPROTECT]);
|
|
|
|
if (!protect)
|
2009-04-16 03:57:46 +02:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-04-16 05:30:26 +02:00
|
|
|
// If player respawns as human, and either cvar zr_suicide_world_damage or the client
|
|
|
|
// wasn't killed by world is false, then continue on to protect client.
|
2009-04-20 02:56:26 +02:00
|
|
|
new bool:respawn_zombie = GetConVarBool(g_hCvarsList[CVAR_RESPAWN_ZOMBIE]);
|
2009-04-16 22:21:32 +02:00
|
|
|
if (!respawn_zombie && !RespawnKilledByWorld(client))
|
2009-04-16 03:57:46 +02:00
|
|
|
{
|
|
|
|
// Set spawn protect flag on client.
|
2009-04-22 04:53:19 +02:00
|
|
|
bInfectImmune[client][INFECT_TYPE_NORMAL] = true;
|
2009-04-16 03:57:46 +02:00
|
|
|
|
2009-05-06 07:13:05 +02:00
|
|
|
// Get spawn protect attribute cvars.
|
|
|
|
new Float:speed = GetConVarFloat(g_hCvarsList[CVAR_SPAWNPROTECT_SPEED]);
|
|
|
|
new alpha = GetConVarInt(g_hCvarsList[CVAR_SPAWNPROTECT_ALPHA]);
|
|
|
|
|
|
|
|
// Set spawn protect attributes.
|
|
|
|
ToolsSetClientLMV(client, speed);
|
|
|
|
ToolsSetClientAlpha(client, alpha);
|
2009-04-16 03:57:46 +02:00
|
|
|
|
2009-04-20 02:56:26 +02:00
|
|
|
// Set time left to zr_protect_time's value.
|
|
|
|
new protect_time = GetConVarInt(g_hCvarsList[CVAR_SPAWNPROTECT_TIME]);
|
|
|
|
pSpawnProtectTime[client] = protect_time;
|
2009-04-16 03:57:46 +02:00
|
|
|
|
|
|
|
// Tell client they are being protected.
|
2009-04-20 02:56:26 +02:00
|
|
|
ZR_PrintToChat(client, "Spawn protection begin", protect_time);
|
2009-04-16 03:57:46 +02:00
|
|
|
|
|
|
|
// Send time left in a hud message.
|
|
|
|
ZR_HudHint(client, "Spawn Protect", pSpawnProtectTime[client]);
|
|
|
|
|
|
|
|
// Start repeating timer.
|
|
|
|
tSpawnProtect[client] = CreateTimer(1.0, SpawnProtectTimer, client, TIMER_FLAG_NO_MAPCHANGE|TIMER_REPEAT);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-16 05:30:26 +02:00
|
|
|
/**
|
|
|
|
* Client has been killed.
|
|
|
|
*
|
|
|
|
* @param client The client index.
|
|
|
|
*/
|
|
|
|
SpawnProtectOnClientDeath(client)
|
|
|
|
{
|
|
|
|
// If timer is running, kill it.
|
|
|
|
if (tSpawnProtect[client] != INVALID_HANDLE)
|
|
|
|
{
|
|
|
|
KillTimer(tSpawnProtect[client]);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Reset timer handle.
|
|
|
|
tSpawnProtect[client] = INVALID_HANDLE;
|
|
|
|
}
|
|
|
|
|
2009-04-16 03:57:46 +02:00
|
|
|
/**
|
|
|
|
* 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.
|
2009-04-24 05:02:19 +02:00
|
|
|
if (!InfectIsClientHuman(client))
|
2009-04-16 03:57:46 +02:00
|
|
|
{
|
|
|
|
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.
|
2009-04-22 04:53:19 +02:00
|
|
|
bInfectImmune[client][INFECT_TYPE_NORMAL] = false;
|
2009-04-16 03:57:46 +02:00
|
|
|
|
|
|
|
// Tell client spawn protection is over.
|
|
|
|
ZR_HudHint(client, "Spawn protection end");
|
|
|
|
|
|
|
|
// Fix attributes.
|
2009-04-29 02:50:25 +02:00
|
|
|
ToolsSetClientAlpha(client, ClassGetAlphaInitial(client));
|
|
|
|
ToolsSetClientLMV(client, ClassGetSpeed(client));
|
2009-04-16 03:57:46 +02:00
|
|
|
|
|
|
|
// Clear timer handle.
|
|
|
|
tSpawnProtect[client] = INVALID_HANDLE;
|
|
|
|
|
|
|
|
// Stop timer.
|
|
|
|
return Plugin_Stop;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Allow timer to continue repeating.
|
|
|
|
return Plugin_Continue;
|
2009-05-01 11:22:45 +02:00
|
|
|
}
|