2009-04-16 07:35:18 +02:00
|
|
|
/*
|
|
|
|
* ============================================================================
|
|
|
|
*
|
2009-07-05 08:49:23 +02:00
|
|
|
* Zombie:Reloaded
|
2009-04-16 07:35:18 +02:00
|
|
|
*
|
2009-06-12 05:51:26 +02:00
|
|
|
* File: respawn.inc
|
|
|
|
* Type: Module
|
|
|
|
* Description: Players come back to life
|
|
|
|
*
|
|
|
|
* Copyright (C) 2009 Greyscale, Richard Helgeby
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2009-04-16 07:35:18 +02:00
|
|
|
*
|
|
|
|
* ============================================================================
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Array for storing respawn timer handles per client.
|
|
|
|
*/
|
|
|
|
new Handle:tRespawn[MAXPLAYERS + 1];
|
|
|
|
|
2009-04-16 22:21:32 +02:00
|
|
|
/**
|
|
|
|
* Array for flagging zombies who were killed by world.
|
|
|
|
*/
|
2009-04-27 04:00:38 +02:00
|
|
|
new bool:bKilledByWorld[MAXPLAYERS + 1];
|
2009-04-16 22:21:32 +02:00
|
|
|
|
2009-04-16 07:35:18 +02:00
|
|
|
/**
|
|
|
|
* Client is joining the server.
|
|
|
|
*/
|
|
|
|
RespawnClientInit(client)
|
|
|
|
{
|
|
|
|
// Reset timer handle.
|
|
|
|
tRespawn[client] = INVALID_HANDLE;
|
|
|
|
|
2009-04-27 04:00:38 +02:00
|
|
|
// Init bKilledByWorld for client.
|
|
|
|
bKilledByWorld[client] = false;
|
2009-04-16 07:35:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Client is spawning into the game.
|
|
|
|
*
|
|
|
|
* @param client The client index.
|
|
|
|
*/
|
|
|
|
RespawnOnClientSpawn(client)
|
|
|
|
{
|
|
|
|
// If timer is running, kill it.
|
|
|
|
if (tRespawn[client] != INVALID_HANDLE)
|
|
|
|
{
|
|
|
|
KillTimer(tRespawn[client]);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Reset timer handle.
|
|
|
|
tRespawn[client] = INVALID_HANDLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Client has been killed.
|
|
|
|
*
|
|
|
|
* @param client The client index.
|
|
|
|
*/
|
2009-04-16 22:21:32 +02:00
|
|
|
RespawnOnClientDeath(client, attacker, const String:weapon[])
|
2009-04-16 07:35:18 +02:00
|
|
|
{
|
2009-04-16 22:21:32 +02:00
|
|
|
// If client is a zombie, check if they were killed by world.
|
2009-04-24 05:02:19 +02:00
|
|
|
if (InfectIsClientInfected(client))
|
2009-04-16 22:21:32 +02:00
|
|
|
{
|
2009-04-27 04:00:38 +02:00
|
|
|
// Set bKilledByWorld to true if attacker is not a valid client.
|
|
|
|
bKilledByWorld[client] = !ZRIsClientValid(attacker);
|
2009-04-16 22:21:32 +02:00
|
|
|
}
|
|
|
|
|
2009-04-16 07:35:18 +02:00
|
|
|
// If timer is running, kill it.
|
|
|
|
if (tRespawn[client] != INVALID_HANDLE)
|
|
|
|
{
|
|
|
|
KillTimer(tRespawn[client]);
|
|
|
|
}
|
|
|
|
|
|
|
|
// If player was infected, then stop.
|
|
|
|
if (StrEqual(weapon, "zombie_claws_of_death", false))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If respawn is disabled, stop here.
|
2009-04-20 02:56:26 +02:00
|
|
|
new bool:respawn = GetConVarBool(g_hCvarsList[CVAR_RESPAWN]);
|
2009-04-16 07:35:18 +02:00
|
|
|
if (!respawn)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Start respawn timer.
|
2009-04-20 02:56:26 +02:00
|
|
|
new Float:delay = GetConVarFloat(g_hCvarsList[CVAR_RESPAWN_DELAY]);
|
2009-04-16 07:35:18 +02:00
|
|
|
tRespawn[client] = CreateTimer(delay, RespawnTimer, client, TIMER_FLAG_NO_MAPCHANGE);
|
|
|
|
}
|
2009-04-16 22:21:32 +02:00
|
|
|
|
2009-04-27 04:00:38 +02:00
|
|
|
/**
|
|
|
|
* The round is ending.
|
|
|
|
*/
|
|
|
|
RespawnOnRoundEnd()
|
|
|
|
{
|
|
|
|
// x = client index.
|
|
|
|
for (new x = 1; x <= MaxClients; x++)
|
|
|
|
{
|
|
|
|
// If client isn't in-game, then stop.
|
|
|
|
if (!IsClientInGame(x))
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If timer isn't currently running, then stop.
|
|
|
|
if (tRespawn[x] == INVALID_HANDLE)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Stop timer.
|
|
|
|
KillTimer(tRespawn[x]);
|
|
|
|
|
|
|
|
// Reset timer handle.
|
|
|
|
tRespawn[x] = INVALID_HANDLE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-16 07:35:18 +02:00
|
|
|
/**
|
|
|
|
* Spawns a player into the round.
|
|
|
|
*
|
|
|
|
* @param client The client index.
|
|
|
|
*/
|
2009-05-12 04:30:16 +02:00
|
|
|
RespawnSpawnClient(client, bool:zombie = false)
|
2009-04-16 07:35:18 +02:00
|
|
|
{
|
|
|
|
// If client isn't in-game, then stop.
|
|
|
|
if (!IsClientInGame(client))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Spawn player.
|
|
|
|
CS_RespawnPlayer(client);
|
|
|
|
|
|
|
|
// Stop here if the first zombie hasn't spawned yet.
|
2009-04-17 12:16:44 +02:00
|
|
|
if (!g_bZombieSpawned)
|
2009-04-16 07:35:18 +02:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-05-12 04:30:16 +02:00
|
|
|
// Infect if zombie is true.
|
|
|
|
if (zombie)
|
2009-04-16 07:35:18 +02:00
|
|
|
{
|
2009-06-15 21:43:06 +02:00
|
|
|
InfectHumanToZombie(client);
|
2009-04-16 07:35:18 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-05-12 04:30:16 +02:00
|
|
|
if (GetConVarBool(g_hCvarsList[CVAR_RESPAWN_TEAM_ZOMBIE_WORLD]) && bKilledByWorld[client])
|
2009-04-16 07:35:18 +02:00
|
|
|
{
|
2009-06-15 21:43:06 +02:00
|
|
|
InfectHumanToZombie(client);
|
2009-04-27 04:00:38 +02:00
|
|
|
bKilledByWorld[client] = false;
|
2009-04-16 07:35:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Timer callback, respawns a player.
|
|
|
|
*
|
|
|
|
* @param timer The timer handle.
|
|
|
|
* @param client The client index.
|
|
|
|
*/
|
|
|
|
public Action:RespawnTimer(Handle:timer, any:client)
|
|
|
|
{
|
|
|
|
// Reset timer handle.
|
|
|
|
tRespawn[client] = INVALID_HANDLE;
|
|
|
|
|
|
|
|
// If client isn't in-game, then stop.
|
|
|
|
if (!IsClientInGame(client))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If player isn't alive, then stop.
|
|
|
|
if (IsPlayerAlive(client))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get client team.
|
|
|
|
new team = GetClientTeam(client);
|
|
|
|
|
|
|
|
// If player isn't on a team, then stop.
|
|
|
|
if (team != CS_TEAM_T && team != CS_TEAM_CT)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-05-12 04:30:16 +02:00
|
|
|
// Get respawn team.
|
|
|
|
new bool:respawn_zombie = GetConVarBool(g_hCvarsList[CVAR_RESPAWN_TEAM_ZOMBIE]);
|
|
|
|
|
2009-04-16 07:35:18 +02:00
|
|
|
// Spawn player.
|
2009-05-12 04:30:16 +02:00
|
|
|
RespawnSpawnClient(client, respawn_zombie);
|
2009-05-01 11:22:45 +02:00
|
|
|
}
|