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

View File

@ -38,6 +38,7 @@ Handle g_hCookie_HitmarkerSoundVolume;
Handle g_hCookie_HitmarkerSkin; Handle g_hCookie_HitmarkerSkin;
ConVar g_hCVar_Debug; ConVar g_hCVar_Debug;
ConVar g_hCVar_HitmarkerEnabled;
bool g_bLate; bool g_bLate;
@ -87,7 +88,9 @@ public void OnPluginStart()
g_hCookie_HitmarkerSkin = RegClientCookie("hitmarker_skin", "", CookieAccess_Private); g_hCookie_HitmarkerSkin = RegClientCookie("hitmarker_skin", "", CookieAccess_Private);
g_hCVar_Debug = CreateConVar("sm_hitmarker_debug", "0", "", FCVAR_NONE, true, 0.0, true, 1.0); g_hCVar_Debug = CreateConVar("sm_hitmarker_debug", "0", "", FCVAR_NONE, true, 0.0, true, 1.0);
AutoExecConfig(); g_hCVar_HitmarkerEnabled = CreateConVar("sm_hitmarker_enabled", "1", "", FCVAR_NONE, true, 0.0, true, 1.0);
g_hCVar_HitmarkerEnabled.AddChangeHook(OnConVarChanged);
AutoExecConfig(true);
RegConsoleCmd("sm_hm", OnHitmarkerSettings); RegConsoleCmd("sm_hm", OnHitmarkerSettings);
RegConsoleCmd("sm_hitmarker", OnHitmarkerSettings); RegConsoleCmd("sm_hitmarker", OnHitmarkerSettings);
@ -109,6 +112,14 @@ public void OnPluginStart()
} }
} }
public void OnConVarChanged(ConVar convar, const char[] oldValue, const char[] newValue)
{
if(g_hCVar_HitmarkerEnabled.BoolValue)
CPrintToChatAll("{cyan}[Hitmarker] {white}has been allowed.");
else
CPrintToChatAll("{cyan}[Hitmarker] {white}has been disabled.");
}
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
// Purpose: // Purpose:
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
@ -120,6 +131,11 @@ public void OnMapStart()
g_sHitmarkerSkinsNames[i] = ""; g_sHitmarkerSkinsNames[i] = "";
} }
if(!g_hCVar_HitmarkerEnabled.BoolValue)
{
return;
}
char sConfigFile[PLATFORM_MAX_PATH]; char sConfigFile[PLATFORM_MAX_PATH];
BuildPath(Path_SM, sConfigFile, sizeof(sConfigFile), "configs/Hitmarkers.cfg"); BuildPath(Path_SM, sConfigFile, sizeof(sConfigFile), "configs/Hitmarkers.cfg");
@ -184,6 +200,11 @@ public void OnMapStart()
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
public void OnClientCookiesCached(int client) public void OnClientCookiesCached(int client)
{ {
if(!g_hCVar_HitmarkerEnabled.BoolValue)
{
return;
}
char sBuffer[PLATFORM_MAX_PATH]; char sBuffer[PLATFORM_MAX_PATH];
GetClientCookie(client, g_hCookie_ShowBossHitmarker, sBuffer, sizeof(sBuffer)); GetClientCookie(client, g_hCookie_ShowBossHitmarker, sBuffer, sizeof(sBuffer));
@ -243,6 +264,10 @@ public void OnClientDisconnect(int client)
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
public Action OnHitmarkerSettings(int client, int args) public Action OnHitmarkerSettings(int client, int args)
{ {
if(!g_hCVar_HitmarkerEnabled.BoolValue)
{
return Plugin_Handled;
}
ShowSettingsMenu(client); ShowSettingsMenu(client);
return Plugin_Handled; return Plugin_Handled;
} }
@ -252,6 +277,10 @@ public Action OnHitmarkerSettings(int client, int args)
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
public Action OnToggleBossHitmarker(int client, int args) public Action OnToggleBossHitmarker(int client, int args)
{ {
if(!g_hCVar_HitmarkerEnabled.BoolValue)
{
return Plugin_Handled;
}
ToggleBossHitmarker(client); ToggleBossHitmarker(client);
return Plugin_Handled; return Plugin_Handled;
} }
@ -275,6 +304,10 @@ public void ToggleBossHitmarker(int client)
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
public Action OnToggleZombieHitmarker(int client, int args) public Action OnToggleZombieHitmarker(int client, int args)
{ {
if(!g_hCVar_HitmarkerEnabled.BoolValue)
{
return Plugin_Handled;
}
ToggleZombieHitmarker(client); ToggleZombieHitmarker(client);
return Plugin_Handled; return Plugin_Handled;
} }
@ -284,6 +317,10 @@ public Action OnToggleZombieHitmarker(int client, int args)
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
public void ToggleZombieHitmarker(int client) public void ToggleZombieHitmarker(int client)
{ {
if(!g_hCVar_HitmarkerEnabled.BoolValue)
{
return;
}
g_bShowZombieHitmarker[client] = !g_bShowZombieHitmarker[client]; g_bShowZombieHitmarker[client] = !g_bShowZombieHitmarker[client];
SetClientCookie(client, g_hCookie_ShowZombieHitmarker, g_bShowZombieHitmarker[client] ? "1" : ""); SetClientCookie(client, g_hCookie_ShowZombieHitmarker, g_bShowZombieHitmarker[client] ? "1" : "");
@ -298,6 +335,10 @@ public void ToggleZombieHitmarker(int client)
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
public Action OnToggleHitmarkerSound(int client, int args) public Action OnToggleHitmarkerSound(int client, int args)
{ {
if(!g_hCVar_HitmarkerEnabled.BoolValue)
{
return Plugin_Handled;
}
ToggleHitmarkerSound(client); ToggleHitmarkerSound(client);
return Plugin_Handled; return Plugin_Handled;
} }
@ -307,6 +348,10 @@ public Action OnToggleHitmarkerSound(int client, int args)
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
public void ToggleHitmarkerSound(int client) public void ToggleHitmarkerSound(int client)
{ {
if(!g_hCVar_HitmarkerEnabled.BoolValue)
{
return;
}
g_bHitmarkerSound[client] = !g_bHitmarkerSound[client]; g_bHitmarkerSound[client] = !g_bHitmarkerSound[client];
SetClientCookie(client, g_hCookie_HitmarkerSound, g_bHitmarkerSound[client] ? "1" : ""); SetClientCookie(client, g_hCookie_HitmarkerSound, g_bHitmarkerSound[client] ? "1" : "");
@ -321,6 +366,10 @@ public void ToggleHitmarkerSound(int client)
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
public void ToggleHitmarkerSoundVolume(int client) public void ToggleHitmarkerSoundVolume(int client)
{ {
if(!g_hCVar_HitmarkerEnabled.BoolValue)
{
return;
}
g_iHitmarkerSoundVolume[client] += 25; g_iHitmarkerSoundVolume[client] += 25;
if(g_iHitmarkerSoundVolume[client] > 100) if(g_iHitmarkerSoundVolume[client] > 100)
@ -339,6 +388,10 @@ public void ToggleHitmarkerSoundVolume(int client)
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
public void ToggleHitmarkerSkin(int client) public void ToggleHitmarkerSkin(int client)
{ {
if(!g_hCVar_HitmarkerEnabled.BoolValue)
{
return;
}
g_iHitmarkerSkin[client]++; g_iHitmarkerSkin[client]++;
if (StrEqual(g_sHitmarkerSkins[g_iHitmarkerSkin[client]], "")) if (StrEqual(g_sHitmarkerSkins[g_iHitmarkerSkin[client]], ""))
@ -354,6 +407,10 @@ public void ToggleHitmarkerSkin(int client)
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
public void ShowSettingsMenu(int client) public void ShowSettingsMenu(int client)
{ {
if(!g_hCVar_HitmarkerEnabled.BoolValue)
{
return;
}
Menu menu = new Menu(MenuHandler_MainMenu); Menu menu = new Menu(MenuHandler_MainMenu);
menu.SetTitle("Hitmarker Settings", client); menu.SetTitle("Hitmarker Settings", client);
@ -434,6 +491,10 @@ public int MenuHandler_MainMenu(Menu menu, MenuAction action, int client, int se
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
public void OnEntitySpawned(int Entity, const char[] sClassname) public void OnEntitySpawned(int Entity, const char[] sClassname)
{ {
if(!g_hCVar_HitmarkerEnabled.BoolValue)
{
return;
}
int ent = EntRefToEntIndex(Entity); int ent = EntRefToEntIndex(Entity);
if (0 < ent < MAX_EDICTS) if (0 < ent < MAX_EDICTS)
@ -451,6 +512,10 @@ public void OnEntitySpawned(int Entity, const char[] sClassname)
/* /*
public void OnBossDamaged(CBoss Boss, CConfig Config, int client, float damage) public void OnBossDamaged(CBoss Boss, CConfig Config, int client, float damage)
{ {
if(!g_hCVar_HitmarkerEnabled.BoolValue)
{
return;
}
if (!IsValidClient(client)) if (!IsValidClient(client))
return; return;
@ -475,6 +540,10 @@ public void OnBossDamaged(CBoss Boss, CConfig Config, int client, float damage)
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
public MRESReturn Detour_OnTakeDamage(int entity, Handle hReturn, Handle hParams) public MRESReturn Detour_OnTakeDamage(int entity, Handle hReturn, Handle hParams)
{ {
if(!g_hCVar_HitmarkerEnabled.BoolValue)
{
return MRES_Ignored;
}
//https://github.com/alliedmodders/hl2sdk/blob/css/game/shared/takedamageinfo.h#L115 //https://github.com/alliedmodders/hl2sdk/blob/css/game/shared/takedamageinfo.h#L115
int iHealth = GetEntProp(entity, Prop_Data, "m_iHealth"); int iHealth = GetEntProp(entity, Prop_Data, "m_iHealth");
int client = DHookGetParamObjectPtrVar(hParams, 1, 3*(3*4) + 0, ObjectValueType_Ehandle); int client = DHookGetParamObjectPtrVar(hParams, 1, 3*(3*4) + 0, ObjectValueType_Ehandle);
@ -514,6 +583,10 @@ public MRESReturn Detour_OnTakeDamage(int entity, Handle hReturn, Handle hParams
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
public void OnClientHurt(Event hEvent, const char[] sEvent, bool bDontBroadcast) public void OnClientHurt(Event hEvent, const char[] sEvent, bool bDontBroadcast)
{ {
if(!g_hCVar_HitmarkerEnabled.BoolValue)
{
return;
}
int client = GetClientOfUserId(hEvent.GetInt("attacker")); int client = GetClientOfUserId(hEvent.GetInt("attacker"));
int victim = GetClientOfUserId(hEvent.GetInt("userid")); int victim = GetClientOfUserId(hEvent.GetInt("userid"));
@ -544,6 +617,10 @@ public void OnClientHurt(Event hEvent, const char[] sEvent, bool bDontBroadcast)
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
void ShowOverlay(int client, float fTime = 0.3) void ShowOverlay(int client, float fTime = 0.3)
{ {
if(!g_hCVar_HitmarkerEnabled.BoolValue)
{
return;
}
if (g_bHitmarkerSound[client]) if (g_bHitmarkerSound[client])
{ {
float fVolume = g_iHitmarkerSoundVolume[client] / 100.0; float fVolume = g_iHitmarkerSoundVolume[client] / 100.0;

View File

@ -2,13 +2,13 @@
#include <sdktools> #include <sdktools>
#include <multicolors> #include <multicolors>
#include <zombiereloaded> #include <zombiereloaded>
#include <loghelper>
#pragma semicolon 1 #pragma semicolon 1
#pragma newdecls required #pragma newdecls required
/* CONVARS */ /* CONVARS */
ConVar g_hCVar_Delay; ConVar g_hCVar_Delay;
ConVar g_hCVar_KnifemadnessEnabled;
/* BOOLS */ /* BOOLS */
bool g_bClientKnifed[MAXPLAYERS+1]; bool g_bClientKnifed[MAXPLAYERS+1];
@ -32,6 +32,9 @@ public Plugin myinfo =
public void OnPluginStart() 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_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_spawn", OnClientSpawn, EventHookMode_Post);
HookEvent("player_death", OnClientDeath, EventHookMode_Pre); HookEvent("player_death", OnClientDeath, EventHookMode_Pre);
@ -39,11 +42,23 @@ public void OnPluginStart()
HookEvent("player_team", OnClientTeam, EventHookMode_Pre); 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: // Purpose:
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
public void OnClientSpawn(Event hEvent, const char[] sEvent, bool bDontBroadcast) public void OnClientSpawn(Event hEvent, const char[] sEvent, bool bDontBroadcast)
{ {
if(!g_hCVar_KnifemadnessEnabled.BoolValue)
{
return;
}
int client = GetClientOfUserId(hEvent.GetInt("userid")); int client = GetClientOfUserId(hEvent.GetInt("userid"));
g_bClientKnifed[client] = false; 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) public Action OnClientDeath(Event hEvent, const char[] sEvent, bool bDontBroadcast)
{ {
if(!g_hCVar_KnifemadnessEnabled.BoolValue)
{
return Plugin_Continue;
}
int client = GetClientOfUserId(hEvent.GetInt("userid")); int client = GetClientOfUserId(hEvent.GetInt("userid"));
if (g_bSupressDeath[client]) 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) public void OnClientHurt(Event hEvent, const char[] sEvent, bool bDontBroadcast)
{ {
if(!g_hCVar_KnifemadnessEnabled.BoolValue)
{
return;
}
int attacker = GetClientOfUserId(hEvent.GetInt("attacker")); int attacker = GetClientOfUserId(hEvent.GetInt("attacker"));
int victim = GetClientOfUserId(hEvent.GetInt("userid")); 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) public void OnClientTeam(Event hEvent, const char[] sEvent, bool bDontBroadcast)
{ {
if(!g_hCVar_KnifemadnessEnabled.BoolValue)
{
return;
}
int client = GetClientOfUserId(hEvent.GetInt("userid")); int client = GetClientOfUserId(hEvent.GetInt("userid"));
if (g_bClientKnifed[client]) if (g_bClientKnifed[client])
{ {
g_bClientKnifed[client] = false; 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) public void ZR_OnClientInfected(int client, int attacker, bool motherInfect, bool respawnOverride, bool respawn)
{ {
if(!g_hCVar_KnifemadnessEnabled.BoolValue)
{
return;
}
if (!IsValidClient(attacker)) if (!IsValidClient(attacker))
return; return;
@ -137,6 +168,10 @@ public void ZR_OnClientInfected(int client, int attacker, bool motherInfect, boo
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
public Action KillZM(Handle timer, DataPack pack) public Action KillZM(Handle timer, DataPack pack)
{ {
if(!g_hCVar_KnifemadnessEnabled.BoolValue)
{
return Plugin_Continue;
}
int attacker = 0; int attacker = 0;
int client = 0; int client = 0;
@ -145,21 +180,21 @@ public Action KillZM(Handle timer, DataPack pack)
client = GetClientOfUserId(pack.ReadCell()); client = GetClientOfUserId(pack.ReadCell());
if (client == 0) if (client == 0)
return; return Plugin_Continue;
if (!(IsValidClient(client, false) && IsPlayerAlive(client) && ZR_IsClientZombie(client) && g_bClientKnifed[client])) if (!(IsValidClient(client, false) && IsPlayerAlive(client) && ZR_IsClientZombie(client) && g_bClientKnifed[client]))
return; return Plugin_Continue;
g_bSupressDeath[client] = true; g_bSupressDeath[client] = true;
ForcePlayerSuicide(client); ForcePlayerSuicide(client);
g_bClientKnifed[client] = false; g_bClientKnifed[client] = false;
if (!(IsValidClient(attacker, false))) if (!(IsValidClient(attacker, false)))
return; return Plugin_Continue;
Event hEvent = CreateEvent("player_death"); Event hEvent = CreateEvent("player_death");
if (hEvent == null) if (hEvent == null)
return; return Plugin_Continue;
hEvent.SetInt("userid", GetClientUserId(client)); hEvent.SetInt("userid", GetClientUserId(client));
hEvent.SetInt("attacker", GetClientUserId(attacker)); hEvent.SetInt("attacker", GetClientUserId(attacker));
@ -168,6 +203,7 @@ public Action KillZM(Handle timer, DataPack pack)
hEvent.SetInt("dominated", 0); hEvent.SetInt("dominated", 0);
hEvent.SetInt("revenge", 0); hEvent.SetInt("revenge", 0);
hEvent.Fire(); 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) 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) if (GetClientFromSerial(iSerial) != client)
return; return;
@ -251,4 +291,4 @@ stock int IsValidClient(int client, bool nobots = true)
return false; return false;
return IsClientInGame(client); return IsClientInGame(client);
} }