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

Stopping a non-repeatable timer


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
condolent
AlliedModders Donor
Join Date: Jan 2016
Location: gc_sLocation;
Old 10-11-2017 , 03:18   Stopping a non-repeatable timer
Reply With Quote #1

Hi,
How do I correctly stop a non-repeatable timer?

I made it a separate handle and named it gH_WeapRespawn and tried this on each event I want it to stop:
PHP Code:
public void OnRoundStart(Event event, const char[] namebool dontBroadcast) {
    if(
gH_WeapRespawn != null)
        
KillTimer(gH_WeapRespawn);

This is the timer:
PHP Code:
public Action WeaponRespawner(Handle timer) {
    
int client GetRandomValidClient();
    
    
RemoveEdict(g_iPistol);
    
RequestFrame(GiveGunFrameclient);
    
    
gH_WeapRespawn null;

The first code block gave me a Invalid Timer Handle error in server console.
Is that due to it being the wrong way or is it most likely something else in my code, perhaps?
I know this is the way to stop repeatable timers, but does it work the same for non-repeatable?
__________________
condolent is offline
Peace-Maker
SourceMod Plugin Approver
Join Date: Aug 2008
Location: Germany
Old 10-11-2017 , 03:52   Re: Stopping a non-repeatable timer
Reply With Quote #2

Just do delete gH_WeapRespawn; instead of KillTimer. Or set gH_WeapRespawn to null after KillTimer.
__________________
Peace-Maker is offline
condolent
AlliedModders Donor
Join Date: Jan 2016
Location: gc_sLocation;
Old 10-11-2017 , 03:55   Re: Stopping a non-repeatable timer
Reply With Quote #3

Quote:
Originally Posted by Peace-Maker View Post
Just do delete gH_WeapRespawn; instead of KillTimer. Or set gH_WeapRespawn to null after KillTimer.
Which is better? Or do they do both do the same basically?

If it's the same I guess I'll use delete instead, just for the fact that I won't have to add more lines
__________________
condolent is offline
sdz
Senior Member
Join Date: Feb 2012
Old 10-11-2017 , 04:07   Re: Stopping a non-repeatable timer
Reply With Quote #4

Quote:
Originally Posted by condolent View Post
Which is better? Or do they do both do the same basically?

If it's the same I guess I'll use delete instead, just for the fact that I won't have to add more lines
I believe I read somewhere that CloseHandle/Delete var frees it entirely from memory
sdz is offline
hmmmmm
Great Tester of Whatever
Join Date: Mar 2017
Location: ...
Old 10-11-2017 , 08:48   Re: Stopping a non-repeatable timer
Reply With Quote #5

delete should set to null after freeing memory anyway, so I would go with that.
hmmmmm is offline
WildCard65
Veteran Member
Join Date: Aug 2013
Location: Canada
Old 10-11-2017 , 15:29   Re: Stopping a non-repeatable timer
Reply With Quote #6

Quote:
Originally Posted by EasSidezz View Post
I believe I read somewhere that CloseHandle/Delete var frees it entirely from memory
KillTimer and delete do the exact same thing for timer handles.
__________________
WildCard65 is offline
Reply


Thread Tools
Display Modes

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 12:58.


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