PDA

View Full Version : [REQ-TF2] RTD Timer Plugin


FluffPuro
12-15-2020, 21:39
Hi,

I'd like a timer plugin that forces the command "sm_forcertd" every x seconds. The reason I ask for something like this is because on my server I occasionally host an event that's similar to VSH, except MvM themed - a single giant robot on BLU versus the entire RED team. What I normally do is disable RTD from manual use and instead force effects both good and bad at random at intervals but I would rather have a timer that does the work for me so I can watch over the event.

I need the plugin to have these features:
-Defining the interval the command is executed (in seconds)
-Defining the team sm_forcertd uses (@red/@blue/@all)
-Being able to disable/enable the timer


Thanks! :)

PC Gamer
12-16-2020, 00:26
This works, but isn't written well. Perhaps someone can chime in with better code. Until then, here you go:

#include <sourcemod>

#pragma semicolon 1
#pragma newdecls required

#define PLUGIN_VERSION "1.0"

Handle g_hForceTimer;

public Plugin myinfo =
{
name = "Repeat Forcertd Commands",
author = "PC Gamer",
description = "Allow Admin to force a repeatable Roll The Dice on players",
version = PLUGIN_VERSION,
url = "www.sourcemod.com"
}

public void OnPluginStart()
{
RegAdminCmd("sm_forcestart", Command_ForceStart, ADMFLAG_SLAY, "Start Repeatable Forcertd command");
RegAdminCmd("sm_forcestop", Command_ForceStop, ADMFLAG_SLAY, "Stop Repeatable Forcertd command");
}

public void OnMapEnd()
{
if (g_hForceTimer)
{
KillTimer(g_hForceTimer);
}
}

public Action Command_ForceStart(int client, int args)
{
char arg1[32];
if (args < 2)
{
ReplyToCommand(client, "Usage: sm_forcestart [red/blue/all] [interval in seconds]");
ReplyToCommand(client, "Example: sm_forcestart all 90");

return Plugin_Handled;
}
else GetCmdArg(1, arg1, sizeof(arg1));

char arg2[32];
GetCmdArg(2, arg2, sizeof(arg2));
int forceinterval = StringToInt(arg2);
if (forceinterval < 1 || forceinterval >10000)
{
ReplyToCommand(client, "Usage: sm_forcestart [red/blue/all] [interval in seconds]");
ReplyToCommand(client, "Example: sm_forcestart all 90");

return Plugin_Handled;
}

if (StrEqual(arg1, "red", false))
{
if (g_hForceTimer)
{
KillTimer(g_hForceTimer);
}

ServerCommand("sm_forcertd @red");
g_hForceTimer = CreateTimer(forceinterval * 1.0, Timer_ForceRTDRed, _, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);

}

if (StrEqual(arg1, "blue", false))
{
if (g_hForceTimer)
{
KillTimer(g_hForceTimer);
}

ServerCommand("sm_forcertd @blue");
g_hForceTimer = CreateTimer(forceinterval * 1.0, Timer_ForceRTDBlue, _, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
}

if (StrEqual(arg1, "all", false))
{
if (g_hForceTimer)
{
KillTimer(g_hForceTimer);
}

ServerCommand("sm_forcertd @all");
g_hForceTimer = CreateTimer(forceinterval * 1.0, Timer_ForceRTDRed, _, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
}

ReplyToCommand(client, "ForceRTD started on %s every %i seconds", arg1, forceinterval);
ReplyToCommand(client, "To stop it use: sm_forcestop");

return Plugin_Handled;
}


public Action Command_ForceStop(int client, int args)
{
if (g_hForceTimer)
{
KillTimer(g_hForceTimer);
}

ReplyToCommand(client, "Stopped repeating ForceRTD");
}

public Action Timer_ForceRTDRed(Handle timer)
{
ServerCommand("sm_forcertd @red");
}

public Action Timer_ForceRTDBlue(Handle timer)
{
ServerCommand("sm_forcertd @blue");
}

public Action Timer_ForceRTDAll(Handle timer)
{
ServerCommand("sm_forcertd @all");
}

FluffPuro
12-16-2020, 01:18
This works, but isn't written well. Perhaps someone can chime in with better code. Until then, here you go:

#include <sourcemod>

#pragma semicolon 1
#pragma newdecls required

#define PLUGIN_VERSION "1.0"

Handle g_hForceTimer;

public Plugin myinfo =
{
name = "Repeat Forcertd Commands",
author = "PC Gamer",
description = "Allow Admin to force a repeatable Roll The Dice on players",
version = PLUGIN_VERSION,
url = "www.sourcemod.com"
}

public void OnPluginStart()
{
RegAdminCmd("sm_forcestart", Command_ForceStart, ADMFLAG_SLAY, "Start Repeatable Forcertd command");
RegAdminCmd("sm_forcestop", Command_ForceStop, ADMFLAG_SLAY, "Stop Repeatable Forcertd command");
}

public void OnMapEnd()
{
if (g_hForceTimer)
{
KillTimer(g_hForceTimer);
}
}

public Action Command_ForceStart(int client, int args)
{
char arg1[32];
if (args < 2)
{
ReplyToCommand(client, "Usage: sm_forcestart [red/blue/all] [interval in seconds]");
ReplyToCommand(client, "Example: sm_forcestart all 90");

return Plugin_Handled;
}
else GetCmdArg(1, arg1, sizeof(arg1));

char arg2[32];
GetCmdArg(2, arg2, sizeof(arg2));
int forceinterval = StringToInt(arg2);
if (forceinterval < 1 || forceinterval >10000)
{
ReplyToCommand(client, "Usage: sm_forcestart [red/blue/all] [interval in seconds]");
ReplyToCommand(client, "Example: sm_forcestart all 90");

return Plugin_Handled;
}

if (StrEqual(arg1, "red", false))
{
if (g_hForceTimer)
{
KillTimer(g_hForceTimer);
}

ServerCommand("sm_forcertd @red");
g_hForceTimer = CreateTimer(forceinterval * 1.0, Timer_ForceRTDRed, _, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);

}

if (StrEqual(arg1, "blue", false))
{
if (g_hForceTimer)
{
KillTimer(g_hForceTimer);
}

ServerCommand("sm_forcertd @blue");
g_hForceTimer = CreateTimer(forceinterval * 1.0, Timer_ForceRTDBlue, _, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
}

if (StrEqual(arg1, "all", false))
{
if (g_hForceTimer)
{
KillTimer(g_hForceTimer);
}

ServerCommand("sm_forcertd @all");
g_hForceTimer = CreateTimer(forceinterval * 1.0, Timer_ForceRTDRed, _, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
}

ReplyToCommand(client, "ForceRTD started on %s every %i seconds", arg1, forceinterval);
ReplyToCommand(client, "To stop it use: sm_forcestop");

return Plugin_Handled;
}


public Action Command_ForceStop(int client, int args)
{
if (g_hForceTimer)
{
KillTimer(g_hForceTimer);
}

ReplyToCommand(client, "Stopped repeating ForceRTD");
}

public Action Timer_ForceRTDRed(Handle timer)
{
ServerCommand("sm_forcertd @red");
}

public Action Timer_ForceRTDBlue(Handle timer)
{
ServerCommand("sm_forcertd @blue");
}

public Action Timer_ForceRTDAll(Handle timer)
{
ServerCommand("sm_forcertd @all");
}

Great work, this is just what I needed. :3