General: Apply ZSpawn logic on late spawners.

Improvement on `a45be16399`
This commit is contained in:
zaCade 2018-08-28 14:54:42 +02:00
parent 9f157e14e9
commit c32cda3fc9
2 changed files with 121 additions and 36 deletions

View File

@ -278,14 +278,10 @@ InfectOnClientSpawn(client)
// Disable zombie flag on client.
g_bZombie[client] = false;
// Check if client is spawning on the terrorist team.
if (ZRIsClientOnTeam(client, CS_TEAM_T) && InfectHasZombieSpawned())
{
CS_SwitchTeam(client, CS_TEAM_CT);
CS_RespawnPlayer(client);
}
InfectUnglitchKevlar(client);
// Forward event to modules.
ZSpawnOnClientSpawn(client);
}
/**

View File

@ -25,6 +25,16 @@
* ============================================================================
*/
/**
* Conditions for respawning players.
*/
enum ZSpawnCondition
{
ZSpawn_Block = -1, /** Let ZR decide according to its settings. */
ZSpawn_Human = 0, /** Respawn as a human. */
ZSpawn_Zombie /** Respawn as a zombie. */
}
/**
* Global variable to store infect timer handle.
*/
@ -106,6 +116,48 @@ ZSpawnOnClientDeath(client)
SteamidCacheAddClient(g_hZSpawnSteamIDCache, client);
}
/**
* Client is spawning into the game.
*
* @param client The client index.
*/
ZSpawnOnClientSpawn(client)
{
if (InfectHasZombieSpawned())
{
// Get our zspawn condition.
new ZSpawnCondition:condition = GetZSpawnCondition();
switch(condition)
{
case ZSpawn_Human:
{
// Disable zombie flag on client.
g_bZombie[client] = false;
// Check if client is spawning on the terrorists team.
if (ZRIsClientOnTeam(client, CS_TEAM_T))
{
CS_SwitchTeam(client, CS_TEAM_CT);
CS_RespawnPlayer(client);
}
}
case ZSpawn_Zombie:
{
// Enable zombie flag on client.
g_bZombie[client] = true;
// Check if client is spawning on the counter-terrorists team.
if (ZRIsClientOnTeam(client, CS_TEAM_CT))
{
CS_SwitchTeam(client, CS_TEAM_T);
CS_RespawnPlayer(client);
}
}
}
}
}
/**
* Client has been infected.
*
@ -253,48 +305,38 @@ bool:ZSpawnClient(client, bool:force = false, bool:zombie = false)
if (!force)
{
// Check if zspawn override is enabled, and if so get overidden value.
new bool:teamoverride = GetConVarBool(g_hCvarsList[CVAR_ZSPAWN_TEAM_OVERRIDE]);
teamzombie = teamoverride ? GetConVarBool(g_hCvarsList[CVAR_ZSPAWN_TEAM_ZOMBIE]) : GetConVarBool(g_hCvarsList[CVAR_RESPAWN_TEAM_ZOMBIE]);
// Get our zspawn condition.
new ZSpawnCondition:condition = GetZSpawnCondition();
// Block is the time limit is up.
new bool:zspawntimelimit = GetConVarBool(g_hCvarsList[CVAR_ZSPAWN_TIMELIMIT]);
if (zspawntimelimit)
switch(condition)
{
if (tZSpawn == INVALID_HANDLE)
case ZSpawn_Block:
{
new zspawntimelimitzombie = GetConVarInt(g_hCvarsList[CVAR_ZSPAWN_TIMELIMIT_ZOMBIE]);
switch(zspawntimelimitzombie)
{
case -1:
{
// Get timelimit
new Float:zspawntime = GetConVarFloat(g_hCvarsList[CVAR_ZSPAWN_TIMELIMIT_TIME]);
// Get timelimit.
new Float:zspawntime = GetConVarFloat(g_hCvarsList[CVAR_ZSPAWN_TIMELIMIT_TIME]);
// Tell client the timelimit for this command has expired.
TranslationPrintToChat(client, "ZSpawn timelimit", RoundToNearest(zspawntime));
return false;
}
case 0:
{
teamzombie = false;
}
case 1:
{
teamzombie = true;
}
}
// Tell client the timelimit for this command has expired.
TranslationPrintToChat(client, "ZSpawn timelimit", RoundToNearest(zspawntime));
return false;
}
case ZSpawn_Human:
{
teamzombie = false;
}
case ZSpawn_Zombie:
{
teamzombie = true;
}
}
// Client has been infected this round, respawning as a zombie
// Client has been infected this round, respawning as a zombie.
if(g_bZSpawnClientInfected[client])
teamzombie = true;
}
else
{
// Use the override team in the function if were forcing the spawn.
teamzombie = zombie;
teamzombie = zombie;
}
// Tell respawn module to respawn client.
@ -488,3 +530,50 @@ public Action:ZSpawnTimer(Handle:timer)
// Reset timer handle.
tZSpawn = INVALID_HANDLE;
}
/**
* Get ZSpawn condition.
*/
ZSpawnCondition:GetZSpawnCondition()
{
new ZSpawnCondition:condition;
// Check if zspawn override is enabled, and if so use overriden value.
if (GetConVarBool(g_hCvarsList[CVAR_ZSPAWN_TEAM_OVERRIDE]))
{
// Convert boolean to zspawn condition.
condition = GetConVarBool(g_hCvarsList[CVAR_ZSPAWN_TEAM_ZOMBIE]) ? ZSpawn_Zombie : ZSpawn_Human;
}
else
{
// Convert boolean to zspawn condition.
condition = GetConVarBool(g_hCvarsList[CVAR_RESPAWN_TEAM_ZOMBIE]) ? ZSpawn_Zombie : ZSpawn_Human;
}
// Check if zspawn timelimit is enabled.
if (GetConVarBool(g_hCvarsList[CVAR_ZSPAWN_TIMELIMIT]))
{
// Check if zspawn timelimit is expired.
if (!ZRIsTimerRunning(tZSpawn))
{
new zspawntimelimitzombie = GetConVarInt(g_hCvarsList[CVAR_ZSPAWN_TIMELIMIT_ZOMBIE]);
switch(zspawntimelimitzombie)
{
case -1:
{
condition = ZSpawn_Block;
}
case 0:
{
condition = ZSpawn_Human;
}
case 1:
{
condition = ZSpawn_Zombie;
}
}
}
}
return condition;
}