This commit is contained in:
Wizzard 2023-07-30 02:44:28 -04:00
parent a8791a6477
commit bbd047a493
1 changed files with 56 additions and 18 deletions

View File

@ -10,14 +10,15 @@ public Plugin myinfo =
url = "https://deadzone.lol"
};
Handle timerToggle = null;
Handle timerToggleFFOn = null;
Handle timerToggleFFOff = 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();
StartFFOnTimer();
}
public Action CmdToggleFriendlyFire(int client, int args)
@ -29,7 +30,7 @@ public Action CmdToggleFriendlyFire(int client, int args)
if (g_bPluginEnabled)
{
PrintToChat(client, "Friendly Fire script has been enabled!");
StartToggleTimer();
StartFFOnTimer();
}
else
{
@ -46,10 +47,16 @@ public Action CmdToggleFriendlyFire(int client, int args)
PrintToChat(client, "Friendly Fire script has been disabled!");
if (timerToggle != null)
if (timerToggleFFOn != null)
{
KillTimer(timerToggle);
timerToggle = null;
KillTimer(timerToggleFFOn);
timerToggleFFOn = null;
}
if (timerToggleFFOff != null)
{
KillTimer(timerToggleFFOff);
timerToggleFFOff = null;
}
}
}
@ -60,40 +67,71 @@ public Action CmdToggleFriendlyFire(int client, int args)
return Plugin_Handled;
}
void StartToggleTimer()
void StartFFOnTimer()
{
if (!g_bPluginEnabled)
return;
if (timerToggle != null)
KillTimer(timerToggle);
if (timerToggleFFOn != null)
KillTimer(timerToggleFFOn);
float randomToggleTime = GetRandomFloat(30.0, 600.0);
timerToggle = CreateTimer(randomToggleTime, ToggleFriendlyFire);
float randomTimeToTurnOn = GetRandomFloat(60.0, 600.0); // Between 1 and 10 minutes
timerToggleFFOn = CreateTimer(randomTimeToTurnOn, TurnOnFriendlyFire);
}
public Action ToggleFriendlyFire(Handle timer, any data)
public Action TurnOnFriendlyFire(Handle timer, any data)
{
g_bFriendlyFire = !g_bFriendlyFire;
g_bFriendlyFire = true;
Handle hCvar = FindConVar("mp_friendlyfire");
if(hCvar == INVALID_HANDLE)
{
SetFailState("Failed to find 'mp_friendlyfire' cvar!");
}
SetConVarInt(hCvar, g_bFriendlyFire ? 1 : 0);
SetConVarInt(hCvar, 1);
PrintToChatAll("[DEBUG] Friendly Fire is now %s", g_bFriendlyFire ? "ON" : "OFF");
PrintToChatAll("[DEBUG] Friendly Fire is now ON");
StartToggleTimer();
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();
return Plugin_Continue;
}
public void OnPluginEnd()
{
if(timerToggle != null)
if(timerToggleFFOn != null)
{
KillTimer(timerToggle);
KillTimer(timerToggleFFOn);
}
if(timerToggleFFOff != null)
{
KillTimer(timerToggleFFOff);
}
}