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

Best way to kill a timer


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
TrullSin
Senior Member
Join Date: Jun 2018
Old 12-22-2018 , 07:55   Best way to kill a timer
Reply With Quote #1

What is the best way to kill the timer at round end? I dont even know if this is the best way to make like a timer. But with this code when the map is changing there is like a crash idk

PHP Code:
#include <sourcemod>

public void OnPluginStart()
{
    
HookEvent("round_start"OnRoundStart);
}

public 
OnRoundStart(Handle event, const char[]name bool dontBroadcast)
{
      
CreateTimer(905.0something);
}
public 
Action something(Handle Timer)
{
    
stuff

TrullSin is offline
Ilusion9
Veteran Member
Join Date: Jun 2018
Location: Romania
Old 12-22-2018 , 08:03   Re: Best way to kill a timer
Reply With Quote #2

PHP Code:
#include <sourcemod>

Handle timer;

public 
void OnPluginStart()
{
    
HookEvent("round_start"OnRoundStart);
}

public 
OnRoundStart(Handle event, const char[]name bool dontBroadcast)
{
      
timer CreateTimer(905.0something);
}
public 
Action something(Handle Timer)
{
    
stuff
}
on round end:
{
    
delete timer;

__________________

Last edited by Ilusion9; 12-22-2018 at 08:03.
Ilusion9 is offline
TrullSin
Senior Member
Join Date: Jun 2018
Old 12-22-2018 , 09:37   Re: Best way to kill a timer
Reply With Quote #3

Well I think it works, but I have another problem, sometimes the timer does the action before the specifc time, and do the action multiple times but it should do it only one time
TrullSin is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 12-22-2018 , 09:48   Re: Best way to kill a timer
Reply With Quote #4

...ok. It depends, how you would use timer.
What if take simple example, using commands for testing purpose.

And when you store created timer in global Handle, you should keep track on it, for check is timer still active to avoid errors.

example 1 - one timer at time




example 2 - reset timer



example 2 - repeated timer
__________________
Do not Private Message @me

Last edited by Bacardi; 12-22-2018 at 10:04.
Bacardi is offline
TrullSin
Senior Member
Join Date: Jun 2018
Old 12-22-2018 , 10:00   Re: Best way to kill a timer
Reply With Quote #5

Well I wanted to at that certain time in the round, it will make something, not activated by command but for round time
TrullSin is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 12-22-2018 , 10:07   Re: Best way to kill a timer
Reply With Quote #6

...those are examples. Scripting is like puzzle. Try and figure it out. Learn.
Bacardi is offline
ThatOneGuy
Veteran Member
Join Date: Jul 2012
Location: Oregon, USA
Old 12-22-2018 , 18:29   Re: Best way to kill a timer
Reply With Quote #7

I've certainly stored timer handles, similar to the examples above. However, my preference anymore is just to pass a validation ID to the timer and check it in the callback - avoids direct use of the handles altogether. The validation variable ensures it doesnt fire when it shouldnt.

Repeat Timer Example


Non-Repeat Timer Example
__________________

Last edited by ThatOneGuy; 12-22-2018 at 18:31.
ThatOneGuy is offline
XiLuo
Member
Join Date: Mar 2018
Old 12-25-2018 , 08:04   Re: Best way to kill a timer
Reply With Quote #8

The trick for these friends above is just to show you how to make sure that a timer doesn't repeat itself.But you have to know,from your code,a timer will be activated after 905s, so if 'round start' again
before this timer is activated,it will created a timer again and be activated 905s later.
These friends's timers solve this problem.
when round end or mapend if you want to kill this timer that is created on round start ,I suggest the following two methods
For round end:you can follow above friends's ways to kill timer on round end
For map end:you can also use the above method or use flag for a timer
for example:
CreateTime(905.0,CallBackTimer,_,TIMER_FLAG_N O_MAPCHANGE);
TIMER_FLAG_NO_MAPCHANGE specifies that the timer will not be passed to the next map
onMapEnd() this timer will be destroyed automatically
There are several official parameters you can use when you need
TIMER_REPEAT /**< Timer will repeat until it returns Plugin_Stop */
TIMER_FLAG_NO_MAPCHANGE /**< Timer will not carry over mapchanges */
TIMER_HNDL_CLOSE /**< Deprecated define, replaced by below */
TIMER_DATA_HNDL_CLOSE /**< Timer will automatically call CloseHandle() on its data when finished */

Multiple flags can also be used simultaneously like this
CreateTimer(1.0,CallBackTimer,_,TIMER_REPEAT | TIMER_FLAG_NO_MAPCHANGE)

I wish I could help you,excuse my poor English,thanks
XiLuo 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 06:42.


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