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

Solved cleaning up timers


Post New Thread Reply   
 
Thread Tools Display Modes
Silvers
SourceMod Plugin Approver
Join Date: Aug 2010
Location: SpaceX
Old 12-31-2021 , 09:31   Re: cleaning up timers
Reply With Quote #11

Quote:
Originally Posted by finishlast View Post
Strange, when I change
g_timer = CreateTimer(0.1, gate, _, TIMER_REPEAT | TIMER_FLAG_NO_MAPCHANGE);
to
g_timer = CreateTimer(0.1, gate, _, TIMER_REPEAT);

it would still run after changing map to same map.

*****
Just to not get confused, when I have another plugin that uses a g_timer, that wouldn't interfear bc of the same name or?
*****


Is there a function for checking valid client indexes?!

My wife would yell now RTFM, I guess she is right
Wouldn't interfere. Do "delete g_timer" in OnMapEnd to stop it. Or if you use the TIMER_FLAG_NO_MAPCHANGE flag set "g_timer = null" in OnMapEnd.
__________________
Silvers is offline
finishlast
Senior Member
Join Date: Nov 2018
Location: In Reno with the vitamin
Old 12-31-2021 , 10:41   Re: cleaning up timers
Reply With Quote #12

That's what I was trying with:

PHP Code:
public void OnPluginStart()
{
    
HookEvent("round_freeze_end"event_round_freeze_endEventHookMode_PostNoCopy);
    
HookEvent("round_end"event_round_endEventHookMode_PostNoCopy);
}

public 
void OnMapEnd()
{
delete g_timer;
}

public 
void event_round_end(Event event, const char[] namebool dontBroadcast)
{
delete g_timer;

wonder what is wrong

I updated the script in second post

When I remove TIMER_FLAG_NO_MAPCHANGE it just keeps running.
__________________
finishlast is offline
Silvers
SourceMod Plugin Approver
Join Date: Aug 2010
Location: SpaceX
Old 12-31-2021 , 10:44   Re: cleaning up timers
Reply With Quote #13

Duplicate plugin running?
__________________
Silvers is offline
finishlast
Senior Member
Join Date: Nov 2018
Location: In Reno with the vitamin
Old 12-31-2021 , 11:18   Re: cleaning up timers
Reply With Quote #14

I put it on a server without those plugins but it still shows the behavior.

I put a

PrintToChatAll ("DELETE");

to see if it reaches the delete part

PHP Code:
public void OnMapEnd()
{
PrintToChatAll ("DELETE1");
delete g_timer;
}

public 
void event_round_end(Event event, const char[] namebool dontBroadcast)
{
PrintToChatAll ("DELETE2");
delete g_timer;

When I start the event and !slay @all

It reads DELETE2

When the game resets the lift is still going up.
__________________
finishlast is offline
azalty
AlliedModders Donor
Join Date: Feb 2020
Location: France
Old 01-01-2022 , 18:55   Re: cleaning up timers
Reply With Quote #15

Quote:
Originally Posted by finishlast View Post
I put it on a server without those plugins but it still shows the behavior.

I put a

PrintToChatAll ("DELETE");

to see if it reaches the delete part

PHP Code:
public void OnMapEnd()
{
PrintToChatAll ("DELETE1");
delete g_timer;
}

public 
void event_round_end(Event event, const char[] namebool dontBroadcast)
{
PrintToChatAll ("DELETE2");
delete g_timer;

When I start the event and !slay @all

It reads DELETE2

When the game resets the lift is still going up.
You're setting the timer's handle to null while asking it to continue inside the timer's function.

In that case, deleting g_timer won't do anything since g_timer is null. The timer is still going though.

Code:
g_timer = null;
return Plugin_Continue;
change to
Code:
return Plugin_Continue;
Only set the timer handle to null when you're killing the timer.

- In short: -
Inside the timer's function:
Code:
g_timer = null;
return Plugin_Stop;
Outside of the timer's function:
Code:
delete g_timer;
__________________
GitHub | Discord: @azalty | Steam

Last edited by azalty; 01-01-2022 at 19:02.
azalty is offline
finishlast
Senior Member
Join Date: Nov 2018
Location: In Reno with the vitamin
Old 01-02-2022 , 06:10   Re: cleaning up timers
Reply With Quote #16

Oh, now I see, I understood it wrong.

Now it is working as intended without TIMER_FLAG_NO_MAPCHANGE.

Thanks a lot guys, you are great.
__________________
finishlast is offline
HarryPotter
Veteran Member
Join Date: Sep 2017
Location: Taiwan, Asia
Old 01-02-2022 , 21:38   Re: cleaning up timers
Reply With Quote #17

I usually delete timer when
1. OnMapEnd()
2. round end
PHP Code:
    HookEvent("round_end"evtRoundEnd); //round end, trigger when versus mode first round & second round end
    
HookEvent("map_transition"evtRoundEnd); //mission complete in coop/realism, won't trigger "round_end"
    
HookEvent("mission_lost"evtRoundEnd); //mission failed in coop/realism, will trigger "round_end"
    
HookEvent("finale_vehicle_leaving"evtRoundEnd); //final rescue vehicle leaving, won't trigger "round_end" 
__________________

Last edited by HarryPotter; 01-03-2022 at 04:17.
HarryPotter is offline
azalty
AlliedModders Donor
Join Date: Feb 2020
Location: France
Old 01-03-2022 , 03:16   Re: cleaning up timers
Reply With Quote #18

Quote:
Originally Posted by HarryPotter View Post
I usually delete timer when
1. OnMapEnd() or you can use TIMER_FLAG_NO_MAPCHANGE
2. OnPluginEnd()
3. round end
PHP Code:
    HookEvent("round_end"evtRoundEnd); //round end, trigger when versus mode first round & second round end
    
HookEvent("map_transition"evtRoundEnd); //mission complete in coop/realism, won't trigger "round_end"
    
HookEvent("mission_lost"evtRoundEnd); //mission failed in coop/realism, will trigger "round_end"
    
HookEvent("finale_vehicle_leaving"evtRoundEnd); //final rescue vehicle leaving, won't trigger "round_end" 
Do not use TIMER_FLAG_NO_MAPCHANGE if you save the timer handle in a variable, because that will cause you to store a handle pointing to nothing, which could cause errors

When the plugin is unloaded, any variable that it registered, any handle (and the object they are pointing to) created by the plugin is deleted, and the memory the plugin uses is freed automatically. This means timers will be automatically killed too, there is no need to do anything inside OnPluginEnd() in 99,9% cases
__________________
GitHub | Discord: @azalty | Steam

Last edited by azalty; 01-03-2022 at 06:11.
azalty is offline
HarryPotter
Veteran Member
Join Date: Sep 2017
Location: Taiwan, Asia
Old 01-03-2022 , 04:17   Re: cleaning up timers
Reply With Quote #19

Quote:
Originally Posted by azalty View Post
When the plugin is unloaded, any variable that it registered, any handle (and the object they are pointing to) created by the plugin is deleted, and the memory the plugin use is freed automatically. This means timers will be automatically killed too, there is no need to do anything inside OnPluginEnd() in 99,9% cases
Oh, I see, thank you
__________________
HarryPotter 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 00:42.


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