Added cvar to enable suicide intercept before the first zombie.

This commit is contained in:
Richard Helgeby 2010-05-19 15:34:26 +02:00
parent 852f380b48
commit d556da6a32
3 changed files with 36 additions and 46 deletions

View File

@ -382,6 +382,10 @@ zr_damage_suicide_human "0"
// Default: "kill, spectate, jointeam, joinclass" // Default: "kill, spectate, jointeam, joinclass"
zr_damage_suicide_cmds "kill, spectate, jointeam, joinclass" zr_damage_suicide_cmds "kill, spectate, jointeam, joinclass"
// Intercept suicide commands only after the first zombie has spawned.
// Default: "1"
zr_damage_suicide_after_infect "1"
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// Overlays (core) // Overlays (core)

View File

@ -85,6 +85,7 @@ enum CvarsList
Handle:CVAR_DAMAGE_SUICIDE_MZOMBIE, Handle:CVAR_DAMAGE_SUICIDE_MZOMBIE,
Handle:CVAR_DAMAGE_SUICIDE_HUMAN, Handle:CVAR_DAMAGE_SUICIDE_HUMAN,
Handle:CVAR_DAMAGE_SUICIDE_CMDS, Handle:CVAR_DAMAGE_SUICIDE_CMDS,
Handle:CVAR_SUICIDE_AFTER_INFECT,
Handle:CVAR_SAYHOOKS_QUIET, Handle:CVAR_SAYHOOKS_QUIET,
Handle:CVAR_SAYHOOKS_QUIET_FILTER, Handle:CVAR_SAYHOOKS_QUIET_FILTER,
Handle:CVAR_SAYHOOKS_QUIET_FLAGS, Handle:CVAR_SAYHOOKS_QUIET_FLAGS,
@ -347,6 +348,7 @@ CvarsCreate()
g_hCvarsList[CVAR_DAMAGE_SUICIDE_MZOMBIE] = CreateConVar("zr_damage_suicide_mzombie", "1", "Intercept suicide commands attempted by mother zombies."); g_hCvarsList[CVAR_DAMAGE_SUICIDE_MZOMBIE] = CreateConVar("zr_damage_suicide_mzombie", "1", "Intercept suicide commands attempted by mother zombies.");
g_hCvarsList[CVAR_DAMAGE_SUICIDE_HUMAN] = CreateConVar("zr_damage_suicide_human", "0", "Intercept suicide commands attempted by humans."); g_hCvarsList[CVAR_DAMAGE_SUICIDE_HUMAN] = CreateConVar("zr_damage_suicide_human", "0", "Intercept suicide commands attempted by humans.");
g_hCvarsList[CVAR_DAMAGE_SUICIDE_CMDS] = CreateConVar("zr_damage_suicide_cmds", "kill, spectate, jointeam, joinclass", "List of client commands to intercept as suicide attempts. [Delimiter: \", \"]"); g_hCvarsList[CVAR_DAMAGE_SUICIDE_CMDS] = CreateConVar("zr_damage_suicide_cmds", "kill, spectate, jointeam, joinclass", "List of client commands to intercept as suicide attempts. [Delimiter: \", \"]");
g_hCvarsList[CVAR_SUICIDE_AFTER_INFECT] = CreateConVar("zr_damage_suicide_after_infect", "1", "Intercept suicide commands only after the first zombie has spawned.");
// =========================== // ===========================

View File

@ -382,63 +382,47 @@ public ZRTools_Action:DamageOnTakeDamage(client, inflictor, attacker, Float:dama
*/ */
public Action:DamageSuicideIntercept(client, argc) public Action:DamageSuicideIntercept(client, argc)
{ {
// If zombie hasn't spawned, then stop. // Get suicide interception settings.
if (!g_bZombieSpawned) new bool:suicideAfterInfect = GetConVarBool(g_hCvarsList[CVAR_SUICIDE_AFTER_INFECT]);
new bool:suicideZombie = GetConVarBool(g_hCvarsList[CVAR_DAMAGE_SUICIDE_ZOMBIE]);
new bool:suicideZombieMother = GetConVarBool(g_hCvarsList[CVAR_DAMAGE_SUICIDE_MZOMBIE]);
new bool:suicideHuman = GetConVarBool(g_hCvarsList[CVAR_DAMAGE_SUICIDE_HUMAN]);
// Check various criterias that will _allow_ the command. If no criterias
// match, block it.
// Check general criterias.
if ((suicideAfterInfect && !g_bZombieSpawned) || // Check if it should block suicides before mother zombie.
!ZRIsClientValid(client) || // Validate client (to stop console).
!IsPlayerAlive(client)) // Check if dead.
{ {
return Plugin_Continue;
}
// If client is invalid, then stop. (Stop console.)
if (!ZRIsClientValid(client))
{
return Plugin_Continue;
}
// If client is dead, then stop.
if (!IsPlayerAlive(client))
{
return Plugin_Continue;
}
// Get cvar values for suicide interception.
new bool:suicidezombie = GetConVarBool(g_hCvarsList[CVAR_DAMAGE_SUICIDE_ZOMBIE]);
new bool:suicidezombiemother = GetConVarBool(g_hCvarsList[CVAR_DAMAGE_SUICIDE_MZOMBIE]);
new bool:suicidehuman = GetConVarBool(g_hCvarsList[CVAR_DAMAGE_SUICIDE_HUMAN]);
// Check if client is a zombie.
if (InfectIsClientInfected(client))
{
// If client is a mother zombie, and suicide intercept is enabled for mother zombies zombies, then block command.
if (g_bDamageMotherZombie[client] && suicidezombiemother)
{
// Tell client their command has been intercepted, and log.
TranslationPrintToChat(client, "Damage suicide intercept");
LogEvent(false, LogType_Normal, LOG_GAME_EVENTS, LogModule_Damage, "Suicide Intercept", "Player \"%L\" attempted suicide.", client);
return Plugin_Handled;
}
// If client is a zombie, and suicide intercept is enabled for zombies, then block command.
if (!g_bDamageMotherZombie[client] && suicidezombie)
{
// Tell client their command has been intercepted, and log.
TranslationPrintToChat(client, "Damage suicide intercept");
LogEvent(false, LogType_Normal, LOG_GAME_EVENTS, LogModule_Damage, "Suicide Intercept", "Player \"%L\" attempted suicide.", client);
return Plugin_Handled;
}
}
// If client is a human, and suicide intercept is enabled for humans, then block command.
if (InfectIsClientHuman(client) && suicidehuman)
{
// Tell client their command has been intercepted, and log.
TranslationPrintToChat(client, "Damage suicide intercept");
LogEvent(false, LogType_Normal, LOG_GAME_EVENTS, LogModule_Damage, "Suicide Intercept", "Player \"%L\" attempted suicide.", client);
return Plugin_Handled;
}
// Allow command. // Allow command.
return Plugin_Continue; return Plugin_Continue;
}
// Check zombie criterias.
if (InfectIsClientInfected(client))
{
if (g_bDamageMotherZombie[client] && !suicideZombieMother || // Check if suicide is allowed for mother zombies.
(!g_bDamageMotherZombie[client] && !suicideZombie)) // Check if suicide is allowed for regular zombies.
{
// Allow command.
return Plugin_Continue;
}
}
// Check human criterias.
// Allow suicide if player is a human and humans can suicide.
if (InfectIsClientHuman(client) && !suicideHuman)
{
// Allow command.
return Plugin_Continue;
}
// Tell client their command has been intercepted, and log.
TranslationPrintToChat(client, "Damage suicide intercept");
LogEvent(false, LogType_Normal, LOG_GAME_EVENTS, LogModule_Damage, "Suicide Intercept", "\"%L\" attempted suicide.", client);
// Block command.
return Plugin_Handled;
} }