Raised This Month: $32 Target: $400
 8% 

Help with Timer Handles


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
ThatOneGuy
Veteran Member
Join Date: Jul 2012
Location: Oregon, USA
Old 02-17-2014 , 03:18   Help with Timer Handles
Reply With Quote #1

I have been reading threads on timer handles way too long tonight. I have a plugin I made that was working great til I started adding in new timers. However, I am newer to scripting, so I am a bit confused with how to handle them, and what different options are available.

Here is an example of the code I am using, but with some comments added, and a few things changed to be able to ask questions...

Code


I am currently getting errors every time the timer executes, and I have crashed the server at least once.

Errors


Additionally, can someone clarify some differences between these:


Any help is much appreciated. If I can't get it figured out, I might just have to take them out of my plugin, as well as the features they trigger : /

-ToG

Last edited by ThatOneGuy; 02-17-2014 at 11:54.
ThatOneGuy is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 02-17-2014 , 11:47   Re: Help with Timer Handles
Reply With Quote #2

You don't have to save the Handles to timers unless you need to end them early. Incidentally, for timers 2 and 3, you probably want to not save the handles and pass the TIMER_FLAG_NO_MAPCHANGE flag to make sure they don't execute if the map changes before they fire.

Incidentally, it may be better to have the 90 second timer start and stop every time the map changes. That's up to you, though.

PHP Code:
new Handle:g_hTimer1 INVALID_HANDLE;    //timer1 to repeat every 90 seconds throughout whole map

public OnPluginStart()
{
    
//start timer1
    
g_hTimer1 CreateTimer(90Timer1_MonitorINVALID_HANDLETIMER_REPEAT);
}

public 
OnMapStart()
{
    
CreateTimer(30Timer2_MonitorINVALID_HANDLETIMER_FLAG_NO_MAPCHANGE);
    
CreateTimer(20Timer3_MonitorINVALID_HANDLETIMER_FLAG_NO_MAPCHANGE);
}

public 
Action:Timer2_Monitor(Handle:timer)
{
    
//EXECUTE ACTIONS HERE
}

public 
Action:Timer3_Monitor(Handle:timer)
{
    
//ACTIONS TIMER EXECUTES
}

public 
OnMapEnd()
{
    
//SHOULD I CLOSE HANDLES HERE?
}

public 
Action:Timer1_Monitor(Handle:timer)
{
    
//ACTIONS TIMER EXECUTES HERE

    
return Plugin_Continue;  //do i need this here? and if so, do i need it on the other two timers?

__________________
Not currently working on SourceMod plugin development.

Last edited by Powerlord; 02-17-2014 at 11:51.
Powerlord is offline
ThatOneGuy
Veteran Member
Join Date: Jul 2012
Location: Oregon, USA
Old 02-17-2014 , 12:07   Re: Help with Timer Handles
Reply With Quote #3

Quote:
Originally Posted by Powerlord View Post
You don't have to save the Handles to timers unless you need to end them early. Incidentally, for timers 2 and 3, you probably want to not save the handles and pass the TIMER_FLAG_NO_MAPCHANGE flag to make sure they don't execute if the map changes before they fire.

Incidentally, it may be better to have the 90 second timer start and stop every time the map changes. That's up to you, though.

Spoiler
So, what if the map were to change before the two non-repeating timers finished? Wouldnt that leak memory? It were be preferable to close the repeating timer on map change as well, then restart on map start. I'm not sure what the ideal way to close the handle is....

Quote:
Originally Posted by ThatOneGuy View Post
Additionally, can someone clarify some differences between these:
So, would I move the CreateTimer for Timer1 to OnMapStart(), then close in OnMapEnd() like this?


Thanks for the reply
ThatOneGuy is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 02-17-2014 , 12:46   Re: Help with Timer Handles
Reply With Quote #4

Quote:
Originally Posted by ThatOneGuy View Post
So, what if the map were to change before the two non-repeating timers finished? Wouldnt that leak memory? It were be preferable to close the repeating timer on map change as well, then restart on map start. I'm not sure what the ideal way to close the handle is....
Timer handles automatically close when:
  1. The map changes and the timer has the TIMER_FLAG_NO_MAPCHANGE flag.
  2. Timers without the TIMER_REPEAT flag run.
  3. Repeating timers return Plugin_Stop.

If you have a variable for said timers, you need to make sure you set it to INVALID_HANDLE when any of these happen.

Quote:
Originally Posted by ThatOneGuy View Post
So, would I move the CreateTimer for Timer1 to OnMapStart(), then close in OnMapEnd() like this?


Thanks for the reply
Yes.
__________________
Not currently working on SourceMod plugin development.
Powerlord 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 10:08.


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