diff --git a/Hitmarker/scripting/Hitmarker.sp b/Hitmarker/scripting/Hitmarker.sp index 809ba19..fa66bf7 100644 --- a/Hitmarker/scripting/Hitmarker.sp +++ b/Hitmarker/scripting/Hitmarker.sp @@ -38,6 +38,7 @@ Handle g_hCookie_HitmarkerSoundVolume; Handle g_hCookie_HitmarkerSkin; ConVar g_hCVar_Debug; +ConVar g_hCVar_HitmarkerEnabled; bool g_bLate; @@ -87,7 +88,9 @@ public void OnPluginStart() g_hCookie_HitmarkerSkin = RegClientCookie("hitmarker_skin", "", CookieAccess_Private); 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_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: //---------------------------------------------------------------------------------------------------- @@ -120,6 +131,11 @@ public void OnMapStart() g_sHitmarkerSkinsNames[i] = ""; } + if(!g_hCVar_HitmarkerEnabled.BoolValue) + { + return; + } + char sConfigFile[PLATFORM_MAX_PATH]; BuildPath(Path_SM, sConfigFile, sizeof(sConfigFile), "configs/Hitmarkers.cfg"); @@ -184,6 +200,11 @@ public void OnMapStart() //---------------------------------------------------------------------------------------------------- public void OnClientCookiesCached(int client) { + if(!g_hCVar_HitmarkerEnabled.BoolValue) + { + return; + } + char sBuffer[PLATFORM_MAX_PATH]; GetClientCookie(client, g_hCookie_ShowBossHitmarker, sBuffer, sizeof(sBuffer)); @@ -243,6 +264,10 @@ public void OnClientDisconnect(int client) //---------------------------------------------------------------------------------------------------- public Action OnHitmarkerSettings(int client, int args) { + if(!g_hCVar_HitmarkerEnabled.BoolValue) + { + return Plugin_Handled; + } ShowSettingsMenu(client); return Plugin_Handled; } @@ -252,6 +277,10 @@ public Action OnHitmarkerSettings(int client, int args) //---------------------------------------------------------------------------------------------------- public Action OnToggleBossHitmarker(int client, int args) { + if(!g_hCVar_HitmarkerEnabled.BoolValue) + { + return Plugin_Handled; + } ToggleBossHitmarker(client); return Plugin_Handled; } @@ -275,6 +304,10 @@ public void ToggleBossHitmarker(int client) //---------------------------------------------------------------------------------------------------- public Action OnToggleZombieHitmarker(int client, int args) { + if(!g_hCVar_HitmarkerEnabled.BoolValue) + { + return Plugin_Handled; + } ToggleZombieHitmarker(client); return Plugin_Handled; } @@ -284,6 +317,10 @@ public Action OnToggleZombieHitmarker(int client, int args) //---------------------------------------------------------------------------------------------------- public void ToggleZombieHitmarker(int client) { + if(!g_hCVar_HitmarkerEnabled.BoolValue) + { + return; + } g_bShowZombieHitmarker[client] = !g_bShowZombieHitmarker[client]; 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) { + if(!g_hCVar_HitmarkerEnabled.BoolValue) + { + return Plugin_Handled; + } ToggleHitmarkerSound(client); return Plugin_Handled; } @@ -307,6 +348,10 @@ public Action OnToggleHitmarkerSound(int client, int args) //---------------------------------------------------------------------------------------------------- public void ToggleHitmarkerSound(int client) { + if(!g_hCVar_HitmarkerEnabled.BoolValue) + { + return; + } g_bHitmarkerSound[client] = !g_bHitmarkerSound[client]; SetClientCookie(client, g_hCookie_HitmarkerSound, g_bHitmarkerSound[client] ? "1" : ""); @@ -321,6 +366,10 @@ public void ToggleHitmarkerSound(int client) //---------------------------------------------------------------------------------------------------- public void ToggleHitmarkerSoundVolume(int client) { + if(!g_hCVar_HitmarkerEnabled.BoolValue) + { + return; + } g_iHitmarkerSoundVolume[client] += 25; if(g_iHitmarkerSoundVolume[client] > 100) @@ -339,6 +388,10 @@ public void ToggleHitmarkerSoundVolume(int client) //---------------------------------------------------------------------------------------------------- public void ToggleHitmarkerSkin(int client) { + if(!g_hCVar_HitmarkerEnabled.BoolValue) + { + return; + } g_iHitmarkerSkin[client]++; if (StrEqual(g_sHitmarkerSkins[g_iHitmarkerSkin[client]], "")) @@ -354,6 +407,10 @@ public void ToggleHitmarkerSkin(int client) //---------------------------------------------------------------------------------------------------- public void ShowSettingsMenu(int client) { + if(!g_hCVar_HitmarkerEnabled.BoolValue) + { + return; + } Menu menu = new Menu(MenuHandler_MainMenu); 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) { + if(!g_hCVar_HitmarkerEnabled.BoolValue) + { + return; + } int ent = EntRefToEntIndex(Entity); 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) { + if(!g_hCVar_HitmarkerEnabled.BoolValue) + { + return; + } if (!IsValidClient(client)) 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) { + if(!g_hCVar_HitmarkerEnabled.BoolValue) + { + return MRES_Ignored; + } //https://github.com/alliedmodders/hl2sdk/blob/css/game/shared/takedamageinfo.h#L115 int iHealth = GetEntProp(entity, Prop_Data, "m_iHealth"); 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) { + if(!g_hCVar_HitmarkerEnabled.BoolValue) + { + return; + } int client = GetClientOfUserId(hEvent.GetInt("attacker")); 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) { + if(!g_hCVar_HitmarkerEnabled.BoolValue) + { + return; + } if (g_bHitmarkerSound[client]) { float fVolume = g_iHitmarkerSoundVolume[client] / 100.0; diff --git a/UNLOZE_KnifeMadness/scripting/UNLOZE_KnifeMadness.sp b/UNLOZE_KnifeMadness/scripting/UNLOZE_KnifeMadness.sp index 147216b..5fc570a 100644 --- a/UNLOZE_KnifeMadness/scripting/UNLOZE_KnifeMadness.sp +++ b/UNLOZE_KnifeMadness/scripting/UNLOZE_KnifeMadness.sp @@ -2,13 +2,13 @@ #include #include #include -#include #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); -} \ No newline at end of file +}