Raised This Month: $51 Target: $400
 12% 

[TF2] Command timer plugin


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Elpapuh
Member
Join Date: Aug 2017
Old 06-21-2018 , 07:26   [TF2] Command timer plugin
Reply With Quote #1

Hi, I need a plugin that executes a command for every "x" minutes or "x" seconds


For example, a plugin that every 5 minutes runs "sm_rainiman @all" from console
Elpapuh is offline
mug1wara
AlliedModders Donor
Join Date: Jun 2018
Old 06-21-2018 , 08:21   Re: [TF2] Command timer plugin
Reply With Quote #2

PHP Code:
#include <sourcemod>

public void OnMapStart()
{
    
CreateTimer(300.0Timer_Callback_TIMER_REPEAT);
}

public 
Action Timer_Callback(Handle timer)
{
    
ServerCommand("sm_rainiman @all");

    return 
Plugin_Continue;


Last edited by mug1wara; 06-21-2018 at 17:31.
mug1wara is offline
ThatKidWhoGames
Veteran Member
Join Date: Jun 2013
Location: IsValidClient()
Old 06-21-2018 , 15:30   Re: [TF2] Command timer plugin
Reply With Quote #3

Quote:
Originally Posted by mug1wara View Post
PHP Code:
#include <sourcemod>

public void OnMapStart()
{
    
CreateTimer(300.0Timer_Callback_TIMER_REPEAT); /* eg. 5 * 60 = 300 =
                                                                = 5 min = 300 sec */
}

public 
Action Timer_Callback(Handle hTimer)
{
    
ServerCommand("sm_rainiman @all");
    
    return 
Plugin_Handled;

You are not returning Plugin_Continue, which will prevent the timer from repeating. Also, you are creating a timer OnMapStart, yet you are not using the TIMER_FLAG_NO_MAPCHANGE flag with the timer.

Use this code instead:
PHP Code:
#include <sourcemod>

public void OnMapStart()
{
    
CreateTimer(300.0Timer_Callback_TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
}

public 
Action Timer_Callback(Handle timer)
{
    
ServerCommand("sm_rainiman @all");
    return 
Plugin_Continue;

If you want more than one command to be executed, simply add a semicolon after the first command and enter your next command.

Example:
PHP Code:
ServerCommand("sm_rainiman @all;sm_slay @all"); 

Last edited by ThatKidWhoGames; 06-21-2018 at 15:34.
ThatKidWhoGames is offline
mug1wara
AlliedModders Donor
Join Date: Jun 2018
Old 06-21-2018 , 17:29   Re: [TF2] Command timer plugin
Reply With Quote #4

@ThatKidWhoGames

I've never used TIMER_FLAG_NO_MAPCHANGE.

Also closing the handle which I did will prevent the timer from repeating, thank's for notifying!

- Sincerely
Mugiwara
mug1wara is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 05:07.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode