From edcf5777cd5be2c4c615b678e3d65d265dd6811b Mon Sep 17 00:00:00 2001 From: Wizzard Date: Tue, 8 Aug 2023 00:06:20 -0400 Subject: [PATCH] Updated function --- friendly_fire_toggle.sp | 79 ++++++++++++----------------------------- 1 file changed, 22 insertions(+), 57 deletions(-) diff --git a/friendly_fire_toggle.sp b/friendly_fire_toggle.sp index 5afe304..49e0865 100644 --- a/friendly_fire_toggle.sp +++ b/friendly_fire_toggle.sp @@ -1,6 +1,10 @@ #include #include +#define TOGGLE_TIME 612.0 +#define MIN_FF_DURATION 30 +#define MAX_FF_DURATION 270 + public Plugin myinfo = { name = "Toggle Friendly Fire", @@ -10,27 +14,26 @@ public Plugin myinfo = url = "https://deadzone.lol" }; -Handle timerToggleFFOn = null; -Handle timerToggleFFOff = null; +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."); - StartFFOnTimer(); + StartToggleTimer(); } public Action CmdToggleFriendlyFire(int client, int args) { if (CheckCommandAccess(client, "sm_friendlyfire", ADMFLAG_ROOT)) { - g_bPluginEnabled = !g_bPluginEnabled; + g_bPluginEnabled = !g_bPluginEnabled if (g_bPluginEnabled) { PrintToChat(client, "Friendly Fire script has been enabled!"); - StartFFOnTimer(); + StartToggleTimer(); } else { @@ -47,16 +50,10 @@ public Action CmdToggleFriendlyFire(int client, int args) PrintToChat(client, "Friendly Fire script has been disabled!"); - if (timerToggleFFOn != null) + if (timerToggle != null) { - KillTimer(timerToggleFFOn); - timerToggleFFOn = null; - } - - if (timerToggleFFOff != null) - { - KillTimer(timerToggleFFOff); - timerToggleFFOff = null; + KillTimer(timerToggle); + timerToggle = null; } } } @@ -67,71 +64,39 @@ public Action CmdToggleFriendlyFire(int client, int args) return Plugin_Handled; } -void StartFFOnTimer() +void StartToggleTimer() { if (!g_bPluginEnabled) return; - if (timerToggleFFOn != null) - KillTimer(timerToggleFFOn); + if (timerToggle != null) + KillTimer(timerToggle); - float randomTimeToTurnOn = GetRandomFloat(60.0, 600.0); // Between 1 and 10 minutes - timerToggleFFOn = CreateTimer(randomTimeToTurnOn, TurnOnFriendlyFire); + timerToggle = CreateTimer(TOGGLE_TIME, ToggleFriendlyFire); } -public Action TurnOnFriendlyFire(Handle timer, any data) +public Action ToggleFriendlyFire(Handle timer, any data) { - g_bFriendlyFire = true; + g_bFriendlyFire = !g_bFriendlyFire; Handle hCvar = FindConVar("mp_friendlyfire"); if(hCvar == INVALID_HANDLE) { SetFailState("Failed to find 'mp_friendlyfire' cvar!"); } - SetConVarInt(hCvar, 1); + SetConVarInt(hCvar, g_bFriendlyFire ? 1 : 0); - PrintToChatAll("[DEBUG] Friendly Fire is now ON"); + PrintToChatAll("[DEBUG] Friendly Fire is now %s", g_bFriendlyFire ? "ON" : "OFF"); - StartFFOffTimer(); - - return Plugin_Continue; -} - -void StartFFOffTimer() -{ - if (timerToggleFFOff != null) - KillTimer(timerToggleFFOff); - - float randomTimeToTurnOff = GetRandomFloat(30.0, 150.0); // Between 30 seconds and 2.5 minutes - timerToggleFFOff = CreateTimer(randomTimeToTurnOff, TurnOffFriendlyFire); -} - -public Action TurnOffFriendlyFire(Handle timer, any data) -{ - g_bFriendlyFire = false; - - Handle hCvar = FindConVar("mp_friendlyfire"); - if(hCvar == INVALID_HANDLE) - { - SetFailState("Failed to find 'mp_friendlyfire' cvar!"); - } - SetConVarInt(hCvar, 0); - - PrintToChatAll("[DEBUG] Friendly Fire is now OFF"); - - StartFFOnTimer(); + StartToggleTimer(); return Plugin_Continue; } public void OnPluginEnd() { - if(timerToggleFFOn != null) + if(timerToggle != null) { - KillTimer(timerToggleFFOn); - } - if(timerToggleFFOff != null) - { - KillTimer(timerToggleFFOff); + KillTimer(timerToggle); } }