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

Solved cleaning up timers


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
finishlast
Senior Member
Join Date: Nov 2018
Location: In Reno with the vitamin
Old 12-30-2021 , 13:34   cleaning up timers
Reply With Quote #1

Everytime I try to play with timers, I encounter various errors in the error logs.

Like this one:

L 12/30/2021 - 19:168: [SM] Exception reported: Invalid timer handle 65740965 (error 1)
L 12/30/2021 - 19:168: [SM] Blaming: l4d_death_toll_tunnel_block.smx
L 12/30/2021 - 19:168: [SM] Call stack trace:
L 12/30/2021 - 19:168: [SM] [0] KillTimer
L 12/30/2021 - 19:168: [SM] [1] Line 89, l4d_death_toll_tunnel_block.sp::OnMapEnd


I read various posts about cleaning up timers etc. and I found some code here and there but I am still unsure how to stop running timers, when the round ends etc.

Is there a master plan of stopping timers somewhere?
Attached Files
File Type: sp Get Plugin or Get Source (l4d_death_toll_tunnel_block.sp - 96 views - 37.9 KB)
__________________

Last edited by finishlast; 01-02-2022 at 06:10.
finishlast is offline
Silvers
SourceMod Plugin Approver
Join Date: Aug 2010
Location: SpaceX
Old 12-30-2021 , 14:03   Re: cleaning up timers
Reply With Quote #2

https://forums.alliedmods.net/showpo...3&postcount=32

When the timer ends set "g_timer = null" in the callback. That's the issue.

Also you can just do "delete g_timer" instead of:
PHP Code:
    if (g_timer != INVALID_HANDLE) {
        
KillTimer(g_timer);
        
g_timer INVALID_HANDLE;
    } 
delete does this same thing.
__________________
Silvers is offline
finishlast
Senior Member
Join Date: Nov 2018
Location: In Reno with the vitamin
Old 12-31-2021 , 05:06   Re: cleaning up timers
Reply With Quote #3

Oh, that's very helpful, Silvers, thank you for that link!

Going to change and test that!

***

But I am still lost.

See this example 1st level sacrafice, when I press the button at the crane it will lift the container, when I !cm to load the map again, it will still lift the container.

So the timer is still active, it don't get stopped in this case. I tried to delete it on round freeze end just in case but still nothing.
It just keeps working.
Attached Files
File Type: sp Get Plugin or Get Source (l4d_river01_docks_pimp2.sp - 88 views - 14.0 KB)
__________________

Last edited by finishlast; 01-02-2022 at 05:55.
finishlast is offline
Earendil
Senior Member
Join Date: Jan 2020
Location: Spain
Old 12-31-2021 , 06:23   Re: cleaning up timers
Reply With Quote #4

If you want to delete timers when map ends, use TIMER_FLAG_NO_MAPCHANGE in timer flags.

There is no point of trying to create a timer with an interval of 0.01s:

Quote:
The smallest possible interval is 0.1 seconds. Timers have high precision (floating point) but low accuracy, as the current time is based on the in-game tick count, not the system clock.
Earendil is offline
finishlast
Senior Member
Join Date: Nov 2018
Location: In Reno with the vitamin
Old 12-31-2021 , 07:06   Re: cleaning up timers
Reply With Quote #5

Oh, I see, thank you. I always thought the cleaning up timers would accomplish that.

With TIMER_FLAG_NO_MAPCHANGE it is working now, thanks a lot!

Good to know about the 0.1 min too.

***
Just an aditional question, it is not timer related but another problem I have in this plugin.

I try to check if a bot touches an entity (the container) and then set a cvar.

it is working but throws errors:

PHP Code:
L 12/31/2021 13:05:35: [SMCall stack trace:
L 12/31/2021 13:05:35: [SM]   [0IsClientInGame
L 12
/31/2021 13:05:35: [SM]   [1Line 466l4d_river01_docks_pimp2.sp::OnTouch
L 12
/31/2021 13:05:35: [SMException reportedClient index 670 is invalid
L 12
/31/2021 13:05:35: [SMBlamingl4d_river01_docks_pimp2.smx
L 12
/31/2021 13:05:35: [SMCall stack trace:
L 12/31/2021 13:05:35: [SM]   [0IsClientInGame
L 12
/31/2021 13:05:35: [SM]   [1Line 466l4d_river01_docks_pimp2.sp::OnTouch
L 12
/31/2021 13:05:35: [SMException reportedClient index 670 is invalid
L 12
/31/2021 13:05:35: [SMBlamingl4d_river01_docks_pimp2.smx
L 12
/31/2021 13:05:35: [SMCall stack trace:
L 12/31/2021 13:05:35: [SM]   [0IsClientInGame
L 12
/31/2021 13:05:35: [SM]   [1Line 466l4d_river01_docks_pimp2.sp::OnTouch
L 12
/31/2021 13:05:35: [SMException reportedClient index 670 is invalid
L 12
/31/2021 13:05:35: [SMBlamingl4d_river01_docks_pimp2.smx
L 12
/31/2021 13:05:35: [SMCall stack trace:
L 12/31/2021 13:05:35: [SM]   [0IsClientInGame
L 12
/31/2021 13:05:35: [SM]   [1Line 466l4d_river01_docks_pimp2.sp::OnTouch 
It seem like the
PHP Code:
    SDKHook(ent_dynamic_block1SDKHook_TouchOnTouch); 
that is supposed to register it, also tried to check for common infected.
PHP Code:
public void OnTouch(int clientint other)
{
//PrintToChatAll("%i", other);

if(other>0){
if(
IsClientInGame(other) && IsFakeClient(other) && GetClientTeam(other) == 2)
{
SetConVarInt(FindConVar("sb_unstick"), 0);
//PrintToChatAll ("touched");
SDKUnhook(ent_dynamic_block1SDKHook_TouchOnTouch);
}

}

Is there a way to filter common infected in this check?
__________________

Last edited by finishlast; 12-31-2021 at 07:18.
finishlast is offline
Silvers
SourceMod Plugin Approver
Join Date: Aug 2010
Location: SpaceX
Old 12-31-2021 , 07:16   Re: cleaning up timers
Reply With Quote #6

If you use TIMER_FLAG_NO_MAPCHANGE you need to set the timer handle to null in OnMapEnd, dont delete otherwise you'll probably get errors about invalid handle again since the timer is killing itself on map end. Without the flag, deleting the timer in map end should work fine. I see no reason for it to continue running, unless you're creating multiple timers and overwriting the handle without killing it before.
__________________

Last edited by Silvers; 12-31-2021 at 07:17.
Silvers is offline
Marttt
Veteran Member
Join Date: Jan 2019
Location: Brazil
Old 12-31-2021 , 07:28   Re: cleaning up timers
Reply With Quote #7

OnTouch return for entities that aren't clients as well, like common infected and witch, you should check if is a valid client index before checking IsClientInGame
__________________
Marttt is offline
finishlast
Senior Member
Join Date: Nov 2018
Location: In Reno with the vitamin
Old 12-31-2021 , 07:55   Re: cleaning up timers
Reply With Quote #8

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
__________________
finishlast is offline
Marttt
Veteran Member
Join Date: Jan 2019
Location: Brazil
Old 12-31-2021 , 08:08   Re: cleaning up timers
Reply With Quote #9

PHP Code:
bool IsValidClientIndex(int client)
{
    return (
<= client <= MaxClients);
}

bool IsValidClient(int client)
{
    return (
IsValidClientIndex(client) && IsClientInGame(client));

__________________
Marttt is offline
finishlast
Senior Member
Join Date: Nov 2018
Location: In Reno with the vitamin
Old 12-31-2021 , 08:19   Re: cleaning up timers
Reply With Quote #10

Oh, thank you Marttt, silly me.

so

if(other > 0 && other <= MaxClients){

would work too
__________________
finishlast 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:21.


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