added cvars for being enabled/disabled for specific maps

This commit is contained in:
jenz
2026-08-24 21:20:51 +02:00
parent 5a8c97e082
commit 48ff38522b
2 changed files with 125 additions and 8 deletions
@@ -2,13 +2,13 @@
#include <sdktools>
#include <multicolors>
#include <zombiereloaded>
#include <loghelper>
#pragma semicolon 1
#pragma newdecls required
/* CONVARS */
ConVar g_hCVar_Delay;
ConVar g_hCVar_KnifemadnessEnabled;
/* BOOLS */
bool g_bClientKnifed[MAXPLAYERS+1];
@@ -32,6 +32,9 @@ public Plugin myinfo =
public void OnPluginStart()
{
g_hCVar_Delay = CreateConVar("sm_knife_madness_kill_delay", "3", "Delay before ZMs die after being knifed by a human.", 0, true, 0.0);
g_hCVar_KnifemadnessEnabled = CreateConVar("sm_knifemadness_enabled", "0", "", FCVAR_NONE, true, 0.0, true, 1.0);
g_hCVar_KnifemadnessEnabled.AddChangeHook(OnConVarChanged);
AutoExecConfig(true);
HookEvent("player_spawn", OnClientSpawn, EventHookMode_Post);
HookEvent("player_death", OnClientDeath, EventHookMode_Pre);
@@ -39,11 +42,23 @@ public void OnPluginStart()
HookEvent("player_team", OnClientTeam, EventHookMode_Pre);
}
public void OnConVarChanged(ConVar convar, const char[] oldValue, const char[] newValue)
{
if(g_hCVar_KnifemadnessEnabled.BoolValue)
CPrintToChatAll("{cyan}[Knifemadness] {white}has been allowed.");
else
CPrintToChatAll("{cyan}[Knifemadness] {white}has been disabled.");
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public void OnClientSpawn(Event hEvent, const char[] sEvent, bool bDontBroadcast)
{
if(!g_hCVar_KnifemadnessEnabled.BoolValue)
{
return;
}
int client = GetClientOfUserId(hEvent.GetInt("userid"));
g_bClientKnifed[client] = false;
@@ -58,6 +73,10 @@ public void OnClientSpawn(Event hEvent, const char[] sEvent, bool bDontBroadcast
//----------------------------------------------------------------------------------------------------
public Action OnClientDeath(Event hEvent, const char[] sEvent, bool bDontBroadcast)
{
if(!g_hCVar_KnifemadnessEnabled.BoolValue)
{
return Plugin_Continue;
}
int client = GetClientOfUserId(hEvent.GetInt("userid"));
if (g_bSupressDeath[client])
@@ -74,6 +93,10 @@ public Action OnClientDeath(Event hEvent, const char[] sEvent, bool bDontBroadca
//----------------------------------------------------------------------------------------------------
public void OnClientHurt(Event hEvent, const char[] sEvent, bool bDontBroadcast)
{
if(!g_hCVar_KnifemadnessEnabled.BoolValue)
{
return;
}
int attacker = GetClientOfUserId(hEvent.GetInt("attacker"));
int victim = GetClientOfUserId(hEvent.GetInt("userid"));
@@ -107,12 +130,16 @@ public void OnClientHurt(Event hEvent, const char[] sEvent, bool bDontBroadcast)
//----------------------------------------------------------------------------------------------------
public void OnClientTeam(Event hEvent, const char[] sEvent, bool bDontBroadcast)
{
if(!g_hCVar_KnifemadnessEnabled.BoolValue)
{
return;
}
int client = GetClientOfUserId(hEvent.GetInt("userid"));
if (g_bClientKnifed[client])
{
g_bClientKnifed[client] = false;
LogPlayerEvent(client, "triggered", "switch_to_spec");
//LogPlayerEvent(client, "triggered", "switch_to_spec");
}
}
@@ -121,6 +148,10 @@ public void OnClientTeam(Event hEvent, const char[] sEvent, bool bDontBroadcast)
//----------------------------------------------------------------------------------------------------
public void ZR_OnClientInfected(int client, int attacker, bool motherInfect, bool respawnOverride, bool respawn)
{
if(!g_hCVar_KnifemadnessEnabled.BoolValue)
{
return;
}
if (!IsValidClient(attacker))
return;
@@ -137,6 +168,10 @@ public void ZR_OnClientInfected(int client, int attacker, bool motherInfect, boo
//----------------------------------------------------------------------------------------------------
public Action KillZM(Handle timer, DataPack pack)
{
if(!g_hCVar_KnifemadnessEnabled.BoolValue)
{
return Plugin_Continue;
}
int attacker = 0;
int client = 0;
@@ -145,21 +180,21 @@ public Action KillZM(Handle timer, DataPack pack)
client = GetClientOfUserId(pack.ReadCell());
if (client == 0)
return;
return Plugin_Continue;
if (!(IsValidClient(client, false) && IsPlayerAlive(client) && ZR_IsClientZombie(client) && g_bClientKnifed[client]))
return;
return Plugin_Continue;
g_bSupressDeath[client] = true;
ForcePlayerSuicide(client);
g_bClientKnifed[client] = false;
if (!(IsValidClient(attacker, false)))
return;
return Plugin_Continue;
Event hEvent = CreateEvent("player_death");
if (hEvent == null)
return;
return Plugin_Continue;
hEvent.SetInt("userid", GetClientUserId(client));
hEvent.SetInt("attacker", GetClientUserId(attacker));
@@ -168,6 +203,7 @@ public Action KillZM(Handle timer, DataPack pack)
hEvent.SetInt("dominated", 0);
hEvent.SetInt("revenge", 0);
hEvent.Fire();
return Plugin_Handled;
}
//----------------------------------------------------------------------------------------------------
@@ -190,6 +226,10 @@ public void QueryClient(int client)
//----------------------------------------------------------------------------------------------------
public void OnConVarQueryFinished(QueryCookie cookie, int client, ConVarQueryResult result, const char[] cvarName, const char[] cvarValue, int iSerial)
{
if(!g_hCVar_KnifemadnessEnabled.BoolValue)
{
return;
}
if (GetClientFromSerial(iSerial) != client)
return;
@@ -251,4 +291,4 @@ stock int IsValidClient(int client, bool nobots = true)
return false;
return IsClientInGame(client);
}
}