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
|
2016-02-06 00:47:47 +01:00
|
|
|
* Type: Module
|
2009-06-12 05:51:26 +02:00
|
|
|
* Description: Players come back to life
|
|
|
|
*
|
2013-01-12 08:47:36 +01:00
|
|
|
* Copyright (C) 2009-2013 Greyscale, Richard Helgeby
|
2009-06-12 05:51:26 +02:00
|
|
|
*
|
|
|
|
* 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
|
|
|
*
|
|
|
|
* ============================================================================
|
|
|
|
*/
|
|
|
|
|
2010-11-14 15:17:19 +01:00
|
|
|
/**
|
|
|
|
* Conditions for respawning players.
|
|
|
|
*/
|
|
|
|
enum RespawnCondition
|
|
|
|
{
|
|
|
|
Repsawn_Default = -1, /** Let ZR decide according to its settings. */
|
|
|
|
Respawn_Human = 0, /** Respawn as a human. */
|
|
|
|
Respawn_Zombie, /** Respawn as a zombie. */
|
|
|
|
Respawn_ZombieIfSuicide /** Respawn as a zombie if killed by world damage. */
|
|
|
|
}
|
|
|
|
|
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.
|
2016-02-06 00:47:47 +01:00
|
|
|
*/
|
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.
|
2016-02-06 00:47:47 +01:00
|
|
|
*/
|
2009-04-16 07:35:18 +02:00
|
|
|
RespawnClientInit(client)
|
|
|
|
{
|
|
|
|
// Reset timer handle.
|
|
|
|
tRespawn[client] = INVALID_HANDLE;
|
2016-02-06 00:47:47 +01:00
|
|
|
|
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.
|
2016-02-06 00:47:47 +01:00
|
|
|
*
|
2009-04-16 07:35:18 +02:00
|
|
|
* @param client The client index.
|
|
|
|
*/
|
|
|
|
RespawnOnClientSpawn(client)
|
|
|
|
{
|
|
|
|
// If timer is running, kill it.
|
|
|
|
if (tRespawn[client] != INVALID_HANDLE)
|
|
|
|
{
|
|
|
|
KillTimer(tRespawn[client]);
|
|
|
|
}
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2009-04-16 07:35:18 +02:00
|
|
|
// Reset timer handle.
|
|
|
|
tRespawn[client] = INVALID_HANDLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Client has been killed.
|
2016-02-06 00:47:47 +01:00
|
|
|
*
|
2009-04-16 07:35:18 +02:00
|
|
|
* @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
|
|
|
}
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2009-04-16 07:35:18 +02:00
|
|
|
// If timer is running, kill it.
|
|
|
|
if (tRespawn[client] != INVALID_HANDLE)
|
|
|
|
{
|
|
|
|
KillTimer(tRespawn[client]);
|
|
|
|
}
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2009-04-16 07:35:18 +02:00
|
|
|
// If player was infected, then stop.
|
|
|
|
if (StrEqual(weapon, "zombie_claws_of_death", false))
|
|
|
|
{
|
2016-06-12 00:31:08 +02:00
|
|
|
tRespawn[client] = INVALID_HANDLE;
|
2009-04-16 07:35:18 +02:00
|
|
|
return;
|
|
|
|
}
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2009-04-16 07:35:18 +02:00
|
|
|
// 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)
|
|
|
|
{
|
2016-06-12 00:31:08 +02:00
|
|
|
tRespawn[client] = INVALID_HANDLE;
|
2009-04-16 07:35:18 +02:00
|
|
|
return;
|
|
|
|
}
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2009-04-16 07:35:18 +02:00
|
|
|
// 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;
|
|
|
|
}
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2009-04-27 04:00:38 +02:00
|
|
|
// If timer isn't currently running, then stop.
|
|
|
|
if (tRespawn[x] == INVALID_HANDLE)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2009-04-27 04:00:38 +02:00
|
|
|
// Stop timer.
|
|
|
|
KillTimer(tRespawn[x]);
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2009-04-27 04:00:38 +02:00
|
|
|
// Reset timer handle.
|
|
|
|
tRespawn[x] = INVALID_HANDLE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-16 07:35:18 +02:00
|
|
|
/**
|
|
|
|
* Spawns a player into the round.
|
2016-02-06 00:47:47 +01:00
|
|
|
*
|
2010-11-14 15:17:19 +01:00
|
|
|
* @param client The client index.
|
|
|
|
* @param zombie Respawn as zombie.
|
|
|
|
* @param zombieIfSuicide Respawn as zombie if killed by world damage.
|
|
|
|
*
|
|
|
|
* @return True if the player was spawned, false otherwise.
|
2009-04-16 07:35:18 +02:00
|
|
|
*/
|
2010-11-14 15:17:19 +01:00
|
|
|
bool:RespawnSpawnClient(client, bool:zombie = false, bool:zombieIfSuicide = false)
|
2009-04-16 07:35:18 +02:00
|
|
|
{
|
|
|
|
// If client isn't in-game, then stop.
|
|
|
|
if (!IsClientInGame(client))
|
|
|
|
{
|
2010-11-14 15:17:19 +01:00
|
|
|
return false;
|
2009-04-16 07:35:18 +02:00
|
|
|
}
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2010-11-14 15:17:19 +01:00
|
|
|
// Get respawn condition.
|
|
|
|
new RespawnCondition:condition = RespawnToContition(zombie, zombieIfSuicide);
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2010-11-14 15:17:19 +01:00
|
|
|
// Trigger API forward.
|
|
|
|
new Action:result = APIOnClientRespawn(client, condition);
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2010-11-14 15:17:19 +01:00
|
|
|
// Check if respawn should be stopped.
|
|
|
|
if (result == Plugin_Handled)
|
2009-04-16 07:35:18 +02:00
|
|
|
{
|
2010-11-14 15:17:19 +01:00
|
|
|
return false;
|
2009-04-16 07:35:18 +02:00
|
|
|
}
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2010-11-14 15:17:19 +01:00
|
|
|
// Restore respawn condition.
|
|
|
|
RespawnRestoreCondition(condition, zombie, zombieIfSuicide);
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2012-02-26 15:39:12 +01:00
|
|
|
new bool:ragdollremove = GetConVarBool(g_hCvarsList[CVAR_VEFFECTS_RAGDOLL_REMOVE]);
|
|
|
|
if (!ragdollremove)
|
|
|
|
{
|
|
|
|
// Detatch ragdoll so it's not removed on respawn.
|
|
|
|
RagdollResetClientRagdoll(client);
|
|
|
|
}
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2010-11-14 15:17:19 +01:00
|
|
|
// Spawn player.
|
|
|
|
CS_RespawnPlayer(client);
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2016-05-08 03:10:25 +02:00
|
|
|
// Reset player velocity
|
|
|
|
float fResetVelocity[3] = {0.0, 0.0, 0.0};
|
|
|
|
TeleportEntity(client, NULL_VECTOR, NULL_VECTOR, fResetVelocity);
|
|
|
|
|
2010-11-14 15:17:19 +01:00
|
|
|
// Check if first zombie has spawned.
|
2015-03-22 18:06:40 +01:00
|
|
|
if (InfectHasZombieSpawned())
|
2009-04-16 07:35:18 +02:00
|
|
|
{
|
2010-11-14 15:17:19 +01:00
|
|
|
// Infect if player should spawn as zombie.
|
|
|
|
if (zombie)
|
|
|
|
{
|
|
|
|
InfectHumanToZombie(client);
|
|
|
|
}
|
|
|
|
// Infect if player committed suicide by world damage.
|
|
|
|
else if (zombieIfSuicide && bKilledByWorld[client])
|
|
|
|
{
|
|
|
|
InfectHumanToZombie(client);
|
|
|
|
bKilledByWorld[client] = false;
|
|
|
|
}
|
2009-04-16 07:35:18 +02:00
|
|
|
}
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2010-11-14 15:17:19 +01:00
|
|
|
// Forward event to modules.
|
|
|
|
APIOnClientRespawned(client, condition);
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2010-11-14 15:17:19 +01:00
|
|
|
return true;
|
2009-04-16 07:35:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Timer callback, respawns a player.
|
2016-02-06 00:47:47 +01:00
|
|
|
*
|
2009-04-16 07:35:18 +02:00
|
|
|
* @param timer The timer handle.
|
|
|
|
* @param client The client index.
|
2016-02-06 00:47:47 +01:00
|
|
|
*/
|
2009-04-16 07:35:18 +02:00
|
|
|
public Action:RespawnTimer(Handle:timer, any:client)
|
|
|
|
{
|
|
|
|
// Reset timer handle.
|
|
|
|
tRespawn[client] = INVALID_HANDLE;
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2009-04-16 07:35:18 +02:00
|
|
|
// If client isn't in-game, then stop.
|
|
|
|
if (!IsClientInGame(client))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2010-11-14 15:17:19 +01:00
|
|
|
// If player already is alive, then stop.
|
2009-04-16 07:35:18 +02:00
|
|
|
if (IsPlayerAlive(client))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2009-04-16 07:35:18 +02:00
|
|
|
// Get client team.
|
|
|
|
new team = GetClientTeam(client);
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2009-04-16 07:35:18 +02:00
|
|
|
// If player isn't on a team, then stop.
|
|
|
|
if (team != CS_TEAM_T && team != CS_TEAM_CT)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2013-07-14 12:35:09 +02:00
|
|
|
// Get whether player should respawn as zombie.
|
|
|
|
new bool:zombie = GetConVarBool(g_hCvarsList[CVAR_RESPAWN_TEAM_ZOMBIE]);
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2013-07-14 12:35:09 +02:00
|
|
|
// Get whether zombies died by suicide should respawn as zombies.
|
|
|
|
new bool:zombieIfSuicide = GetConVarBool(g_hCvarsList[CVAR_RESPAWN_TEAM_ZOMBIE_WORLD]);
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2009-04-16 07:35:18 +02:00
|
|
|
// Spawn player.
|
2013-07-14 12:35:09 +02:00
|
|
|
RespawnSpawnClient(client, zombie, zombieIfSuicide);
|
2010-11-14 15:17:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Converts separate conditions into a single condition value.
|
|
|
|
*/
|
|
|
|
RespawnCondition:RespawnToContition(bool:zombie, bool:zombieIfSuicide)
|
|
|
|
{
|
2010-11-17 15:48:57 +01:00
|
|
|
if (zombie)
|
2010-11-14 15:17:19 +01:00
|
|
|
{
|
2010-11-17 15:48:57 +01:00
|
|
|
return Respawn_Zombie;
|
2010-11-14 15:17:19 +01:00
|
|
|
}
|
2010-11-17 15:48:57 +01:00
|
|
|
else if (zombieIfSuicide)
|
2010-11-14 15:17:19 +01:00
|
|
|
{
|
2010-11-17 15:48:57 +01:00
|
|
|
return Respawn_ZombieIfSuicide;
|
2010-11-14 15:17:19 +01:00
|
|
|
}
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2010-11-14 15:17:19 +01:00
|
|
|
return Respawn_Human;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Restores respawn condition to individual variables. If the condition invalid,
|
|
|
|
* nothing will be changed.
|
|
|
|
*
|
|
|
|
* @param condition Condition to restore.
|
|
|
|
* @param zombie Output.
|
|
|
|
* @param zombieIfSucidie Output.
|
|
|
|
*/
|
|
|
|
RespawnRestoreCondition(RespawnCondition:condition, &bool:zombie, &bool:zombieIfSuicide)
|
|
|
|
{
|
|
|
|
switch (condition)
|
|
|
|
{
|
|
|
|
case Respawn_Human:
|
|
|
|
{
|
|
|
|
zombie = false;
|
|
|
|
zombieIfSuicide = false;
|
|
|
|
}
|
|
|
|
case Respawn_Zombie:
|
|
|
|
{
|
|
|
|
zombie = true;
|
|
|
|
zombieIfSuicide = false;
|
|
|
|
}
|
|
|
|
case Respawn_ZombieIfSuicide:
|
|
|
|
{
|
|
|
|
zombie = false;
|
|
|
|
zombieIfSuicide = true;
|
|
|
|
}
|
|
|
|
}
|
2009-05-01 11:22:45 +02:00
|
|
|
}
|