2009-04-29 01:58:41 +02:00
|
|
|
/*
|
|
|
|
* ============================================================================
|
|
|
|
*
|
|
|
|
* Zombie:Reloaded
|
|
|
|
*
|
2009-06-12 05:51:26 +02:00
|
|
|
* File: zspawn.inc
|
|
|
|
* Type: Module
|
|
|
|
* Description: Handles zspawn command, spawns late-joining clients into the game.
|
|
|
|
*
|
|
|
|
* 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-29 01:58:41 +02:00
|
|
|
*
|
|
|
|
* ============================================================================
|
|
|
|
*/
|
|
|
|
|
2009-05-06 03:04:55 +02:00
|
|
|
/**
|
|
|
|
* Global variable to store infect timer handle.
|
|
|
|
*/
|
|
|
|
new Handle:tZSpawn = INVALID_HANDLE;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Map is starting.
|
|
|
|
*/
|
|
|
|
ZSpawnOnMapStart()
|
|
|
|
{
|
|
|
|
// Reset timer handle.
|
|
|
|
tZSpawn = INVALID_HANDLE;
|
|
|
|
}
|
|
|
|
|
2009-04-29 01:58:41 +02:00
|
|
|
/**
|
|
|
|
* Client is leaving the server.
|
|
|
|
*
|
|
|
|
* @param client The client index.
|
|
|
|
*/
|
|
|
|
ZSpawnOnClientDisconnect(client)
|
|
|
|
{
|
2009-05-09 17:45:19 +02:00
|
|
|
// Check if client is a bot.
|
2009-05-10 01:32:53 +02:00
|
|
|
if (IsFakeClient(client))
|
2009-05-09 17:45:19 +02:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-05-12 04:12:13 +02:00
|
|
|
// Add client serial to global array.
|
|
|
|
SerialAddClient(client);
|
2009-04-29 01:58:41 +02:00
|
|
|
}
|
|
|
|
|
2009-05-06 03:04:55 +02:00
|
|
|
/**
|
|
|
|
* Client has been killed.
|
|
|
|
*
|
|
|
|
* @param client The client index.
|
|
|
|
*/
|
|
|
|
ZSpawnOnClientDeath(client)
|
|
|
|
{
|
2009-05-12 04:12:13 +02:00
|
|
|
// Add client serial to global array.
|
|
|
|
SerialAddClient(client);
|
2009-05-06 03:04:55 +02:00
|
|
|
}
|
|
|
|
|
2009-04-29 01:58:41 +02:00
|
|
|
/**
|
|
|
|
* The round is starting.
|
|
|
|
*/
|
|
|
|
ZSpawnOnRoundStart()
|
|
|
|
{
|
2009-05-12 04:12:13 +02:00
|
|
|
// Reset serial number array.
|
|
|
|
SerialReset();
|
2009-05-06 03:04:55 +02:00
|
|
|
|
|
|
|
// If zspawn timer is running, then kill it.
|
|
|
|
if (tZSpawn != INVALID_HANDLE)
|
|
|
|
{
|
|
|
|
// Kill timer.
|
|
|
|
KillTimer(tZSpawn);
|
|
|
|
|
|
|
|
// Reset timer handle.
|
|
|
|
tZSpawn = INVALID_HANDLE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The freeze time is ending.
|
|
|
|
*/
|
|
|
|
ZSpawnOnRoundFreezeEnd()
|
|
|
|
{
|
|
|
|
// If infect timer is running, then kill it.
|
|
|
|
if (tZSpawn != INVALID_HANDLE)
|
|
|
|
{
|
|
|
|
// Kill timer.
|
|
|
|
KillTimer(tZSpawn);
|
|
|
|
}
|
|
|
|
|
|
|
|
// If zspawn is disabled, then stop.
|
|
|
|
new bool:zspawn = GetConVarBool(g_hCvarsList[CVAR_ZSPAWN]);
|
|
|
|
if (!zspawn)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If timelimit is disabled, then stop.
|
|
|
|
new bool:zspawntimelimit = GetConVarBool(g_hCvarsList[CVAR_ZSPAWN_TIMELIMIT]);
|
|
|
|
if (!zspawntimelimit)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get timelimit
|
|
|
|
new Float:zspawntime = GetConVarFloat(g_hCvarsList[CVAR_ZSPAWN_TIMELIMIT_TIME]);
|
|
|
|
|
|
|
|
// Start timer.
|
|
|
|
tZSpawn = CreateTimer(zspawntime, ZSpawnTimer, _, TIMER_FLAG_NO_MAPCHANGE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The round is ending.
|
|
|
|
*/
|
|
|
|
ZSpawnOnRoundEnd()
|
|
|
|
{
|
|
|
|
// If zspawn timer is running, then kill it.
|
|
|
|
if (tZSpawn != INVALID_HANDLE)
|
|
|
|
{
|
|
|
|
// Kill timer.
|
|
|
|
KillTimer(tZSpawn);
|
|
|
|
|
|
|
|
// Reset timer handle.
|
|
|
|
tZSpawn = INVALID_HANDLE;
|
|
|
|
}
|
2009-04-29 01:58:41 +02:00
|
|
|
}
|
|
|
|
|
2009-05-06 02:28:09 +02:00
|
|
|
/**
|
|
|
|
* Spawns a late-joining client into the game.
|
|
|
|
*
|
|
|
|
* @param client The client index.
|
|
|
|
* @return True if successful, false otherwise.
|
|
|
|
*/
|
|
|
|
bool:ZSpawnClient(client)
|
2009-04-29 01:58:41 +02:00
|
|
|
{
|
|
|
|
// If zspawn is disabled, then stop.
|
|
|
|
new bool:zspawn = GetConVarBool(g_hCvarsList[CVAR_ZSPAWN]);
|
|
|
|
if (!zspawn)
|
|
|
|
{
|
2009-05-14 09:32:01 +02:00
|
|
|
TranslationPrintToChat(client, "Feature is disabled");
|
2009-05-06 02:28:09 +02:00
|
|
|
return false;
|
2009-04-29 01:58:41 +02:00
|
|
|
}
|
|
|
|
|
2009-05-06 03:04:55 +02:00
|
|
|
// If client isn't on a team, then stop.
|
|
|
|
if (!ZRIsClientOnTeam(client))
|
|
|
|
{
|
|
|
|
// Tell client the command may only be used when on a team.
|
2009-05-14 09:32:01 +02:00
|
|
|
TranslationPrintToChat(client, "Must be on team");
|
2009-05-06 03:04:55 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-04-29 01:58:41 +02:00
|
|
|
// If client is alive, then stop.
|
|
|
|
if (IsPlayerAlive(client))
|
|
|
|
{
|
2009-05-06 03:04:55 +02:00
|
|
|
// Tell client the command may only be used when dead.
|
2009-05-14 09:32:01 +02:00
|
|
|
TranslationPrintToChat(client, "Must be dead");
|
2009-05-06 02:28:09 +02:00
|
|
|
return false;
|
2009-04-29 01:58:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Block if client has already played during this round.
|
2009-05-12 04:12:13 +02:00
|
|
|
if (SerialClientExists(client))
|
2009-04-29 01:58:41 +02:00
|
|
|
{
|
2009-05-06 02:28:09 +02:00
|
|
|
// Tell client the command may only be used when joining late.
|
2009-05-14 09:32:01 +02:00
|
|
|
TranslationPrintToChat(client, "ZSpawn double spawn");
|
2009-05-06 02:28:09 +02:00
|
|
|
return false;
|
2009-04-29 01:58:41 +02:00
|
|
|
}
|
|
|
|
|
2009-05-06 03:04:55 +02:00
|
|
|
// Block is the time limit is up.
|
|
|
|
new bool:zspawntimelimit = GetConVarBool(g_hCvarsList[CVAR_ZSPAWN_TIMELIMIT]);
|
|
|
|
if (zspawntimelimit)
|
|
|
|
{
|
|
|
|
if (tZSpawn == INVALID_HANDLE)
|
|
|
|
{
|
|
|
|
// Get timelimit
|
|
|
|
new Float:zspawntime = GetConVarFloat(g_hCvarsList[CVAR_ZSPAWN_TIMELIMIT_TIME]);
|
|
|
|
|
|
|
|
// Tell client the timelimit for this command has expired.
|
2009-05-14 09:32:01 +02:00
|
|
|
TranslationPrintToChat(client, "ZSpawn timelimit", RoundToNearest(zspawntime));
|
2009-05-06 03:04:55 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-12 04:30:16 +02:00
|
|
|
// Check if zspawn override is enabled, and if so get overidden value.
|
|
|
|
new bool:teamoverride = GetConVarBool(g_hCvarsList[CVAR_ZSPAWN_TEAM_OVERRIDE]);
|
|
|
|
new bool:teamzombie = teamoverride ? GetConVarBool(g_hCvarsList[CVAR_ZSPAWN_TEAM_ZOMBIE]) : GetConVarBool(g_hCvarsList[CVAR_RESPAWN_TEAM_ZOMBIE]);
|
|
|
|
|
2009-04-29 01:58:41 +02:00
|
|
|
// Tell respawn module to respawn client.
|
2009-05-12 04:30:16 +02:00
|
|
|
RespawnSpawnClient(client, teamzombie);
|
2009-05-06 02:28:09 +02:00
|
|
|
|
|
|
|
return true;
|
2009-05-01 11:22:45 +02:00
|
|
|
}
|
2009-05-06 03:04:55 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Timer callback, resets handle.
|
|
|
|
*
|
|
|
|
* @param timer The timer handle.
|
|
|
|
*/
|
|
|
|
public Action:ZSpawnTimer(Handle:timer)
|
|
|
|
{
|
|
|
|
// Reset timer handle.
|
|
|
|
tZSpawn = INVALID_HANDLE;
|
2009-06-12 15:52:51 +02:00
|
|
|
}
|