From 0db25c708e33b9f356e32dda6e6408147fce4c06 Mon Sep 17 00:00:00 2001 From: Wizzard Date: Sun, 30 Jul 2023 02:15:56 -0400 Subject: [PATCH] friendly fire randomizer --- friendly_fire_toggle.sp | 102 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 friendly_fire_toggle.sp diff --git a/friendly_fire_toggle.sp b/friendly_fire_toggle.sp new file mode 100644 index 0000000..7a86a09 --- /dev/null +++ b/friendly_fire_toggle.sp @@ -0,0 +1,102 @@ +#include +#include + +#define TOGGLE_TIME 250.0 +#define MIN_FF_DURATION 120 +#define MAX_FF_DURATION 270 + +public Plugin myinfo = +{ + name = "Toggle Friendly Fire", + author = "Retard", + description = "Toggles Friendly Fire On/Off at random moments.", + version = "1.0", + url = "https://deadzone.lol" +}; + +Handle timerToggle = null; +bool g_bFriendlyFire = false; +bool g_bPluginEnabled = true; + +public void OnPluginStart() +{ + RegConsoleCmd("sm_friendlyfire", CmdToggleFriendlyFire, "Toggle the Friendly Fire script. Admins with 'z' flag only."); + StartToggleTimer(); +} + +public Action CmdToggleFriendlyFire(int client, int args) +{ + if (CheckCommandAccess(client, "sm_friendlyfire", ADMFLAG_ROOT)) + { + g_bPluginEnabled = !g_bPluginEnabled + + if (g_bPluginEnabled) + { + PrintToChat(client, "Friendly Fire script has been enabled!"); + StartToggleTimer(); + } + else + { + if (g_bFriendlyFire) + { + Handle hCvar = FindConVar("mp_friendlyfire"); + if (hCvar != INVALID_HANDLE) + { + SetConVarInt(hCvar, 0); + } + g_bFriendlyFire = false; + PrintToChatAll("[DEBUG] Friendly Fire is now OFF"); + } + + PrintToChat(client, "Friendly Fire script has been disabled!"); + + if (timerToggle != null) + { + KillTimer(timerToggle); + timerToggle = null; + } + } + } + else + { + PrintToChat(client, "You do not have permission to use this command."); + } + return Plugin_Handled; +} + +void StartToggleTimer() +{ + if (!g_bPluginEnabled) + return; + + if (timerToggle != null) + KillTimer(timerToggle); + + timerToggle = CreateTimer(TOGGLE_TIME, ToggleFriendlyFire); +} + +public Action ToggleFriendlyFire(Handle timer, any data) +{ + g_bFriendlyFire = !g_bFriendlyFire; + + Handle hCvar = FindConVar("mp_friendlyfire"); + if(hCvar == INVALID_HANDLE) + { + SetFailState("Failed to find 'mp_friendlyfire' cvar!"); + } + SetConVarInt(hCvar, g_bFriendlyFire ? 1 : 0); + + PrintToChatAll("[DEBUG] Friendly Fire is now %s", g_bFriendlyFire ? "ON" : "OFF"); + + StartToggleTimer(); + + return Plugin_Continue; +} + +public void OnPluginEnd() +{ + if(timerToggle != null) + { + KillTimer(timerToggle); + } +}