Raised This Month: $ Target: $400
 0% 

CloseHandle is not stopping TIMER_REPEAT?


Post New Thread Reply   
 
Thread Tools Display Modes
TheFlyingApple
Member
Join Date: Aug 2016
Old 03-09-2020 , 14:37   Re: CloseHandle is not stopping TIMER_REPEAT?
Reply With Quote #11

Quote:
Originally Posted by Dragokas View Post
TheFlyingApple, you have the problem somewhere else, not in the part of my code.

Marttt, he wants to stop timer on round end, not only on map end.
When I copy your code 1to1, it is still giving me this error message:

Code:
[SM] Plugin "slap.smx" encountered error 23: Native detected error
[SM] Invalid timer handle 12ae07f8 (error 3) during timer end, displayed function is timer callback, not the stack trace
[SM] Unable to call function "CheckPlayerZone" due to above error(s).
TheFlyingApple is offline
Dragokas
Veteran Member
Join Date: Nov 2017
Location: Ukraine on fire
Old 03-09-2020 , 14:50   Re: CloseHandle is not stopping TIMER_REPEAT?
Reply With Quote #12

Makes no sense for me. This one can only happen when destory timer handle inside callback.
Can timer callback and round_end event be executed during same ticks (?) ...
__________________
Expert of CMD/VBS/VB6. Malware analyst. L4D fun (Bloody Witch & FreeZone)
[My plugins] [My tools] [GitHub] [Articles] [HiJackThis+] [Donate]
Dragokas is offline
Ilusion9
Veteran Member
Join Date: Jun 2018
Location: Romania
Old 03-09-2020 , 15:04   Re: CloseHandle is not stopping TIMER_REPEAT?
Reply With Quote #13

Set timer variable to null in timer callback. The old timer value is kept, that's why is invalid handle.

PHP Code:
#pragma newdecls required 
#include <sourcemod>
#include <sdktools>
#include <multicolors>

Handle g_timerAntiCamp1;
Handle g_timerAntiCamp2;

public 
void OnPluginStart()
{
    
HookEvent("round_start"Round_Start_Hook);
    
HookEvent("round_end"Round_End_Hook);
}

public 
void OnMapEnd()
{
    
delete g_timerAntiCamp1;
    
delete g_timerAntiCamp2;
}

public 
Action Round_Start_Hook(Handle event, const char[] namebool dontBroadcast)
{    
    
g_timerAntiCamp1 CreateTimer(30.0CheckRoundTimeTIMER_FLAG_NO_MAPCHANGE);
}

public 
Action Round_End_Hook(Handle event, const char[] namebool dontBroadcast)
{
    
delete g_timerAntiCamp1;
    
delete g_timerAntiCamp2;
    
PrintToConsoleAll("Round ended, timers deleted");
}

public 
Action CheckRoundTime(Handle timer)
{
    
g_timerAntiCamp2 CreateTimer(2.0CheckPlayerZoneTIMER_FLAG_NO_MAPCHANGE|TIMER_REPEAT);
    
g_timerAntiCamp1 null;
}

public 
Action CheckPlayerZone(Handle timer
{
    for (
int i 1<= MaxClientsi++)
    {
        if (
IsClientInGame(i) && IsPlayerAlive(i))
        {

            
SlapPlayer(i20true);
            
CPrintToChat(i"{green}You are getting slapped");
        }
    }
    
    
g_timerAntiCamp2 null;

__________________
Ilusion9 is offline
TheFlyingApple
Member
Join Date: Aug 2016
Old 03-09-2020 , 15:12   Re: CloseHandle is not stopping TIMER_REPEAT?
Reply With Quote #14

Quote:
Originally Posted by Ilusion9 View Post
Set timer variable to null in timer callback. The old timer value is kept, that's why is invalid handle.

PHP Code:
#pragma newdecls required 
#include <sourcemod>
#include <sdktools>
#include <multicolors>

Handle g_timerAntiCamp1;
Handle g_timerAntiCamp2;

public 
void OnPluginStart()
{
    
HookEvent("round_start"Round_Start_Hook);
    
HookEvent("round_end"Round_End_Hook);
}

public 
void OnMapEnd()
{
    
delete g_timerAntiCamp1;
    
delete g_timerAntiCamp2;
}

public 
Action Round_Start_Hook(Handle event, const char[] namebool dontBroadcast)
{    
    
g_timerAntiCamp1 CreateTimer(30.0CheckRoundTimeTIMER_FLAG_NO_MAPCHANGE);
}

public 
Action Round_End_Hook(Handle event, const char[] namebool dontBroadcast)
{
    
delete g_timerAntiCamp1;
    
delete g_timerAntiCamp2;
    
PrintToConsoleAll("Round ended, timers deleted");
}

public 
Action CheckRoundTime(Handle timer)
{
    
g_timerAntiCamp2 CreateTimer(2.0CheckPlayerZoneTIMER_FLAG_NO_MAPCHANGE|TIMER_REPEAT);
    
g_timerAntiCamp1 null;
}

public 
Action CheckPlayerZone(Handle timer
{
    for (
int i 1<= MaxClientsi++)
    {
        if (
IsClientInGame(i) && IsPlayerAlive(i))
        {

            
SlapPlayer(i20true);
            
CPrintToChat(i"{green}You are getting slapped");
        }
    }
    
    
g_timerAntiCamp2 null;

With that code it wont repeat every round.
TheFlyingApple is offline
Ilusion9
Veteran Member
Join Date: Jun 2018
Location: Romania
Old 03-09-2020 , 15:23   Re: CloseHandle is not stopping TIMER_REPEAT?
Reply With Quote #15

Quote:
Originally Posted by TheFlyingApple View Post
With that code it wont repeat every round.
You have createtimer(30.0, ...) in round_start event. What are you talking about?
__________________
Ilusion9 is offline
TheFlyingApple
Member
Join Date: Aug 2016
Old 03-09-2020 , 15:33   Re: CloseHandle is not stopping TIMER_REPEAT?
Reply With Quote #16

Quote:
Originally Posted by Ilusion9 View Post
You have createtimer(30.0, ...) in round_start event. What are you talking about?
Yea. The first timer will start the second timer 30 seconds into the round. The second timer will slap people every 2 seconds... If I do it your way, the second timer will never repeat as it should.
TheFlyingApple is offline
Ilusion9
Veteran Member
Join Date: Jun 2018
Location: Romania
Old 03-09-2020 , 15:40   Re: CloseHandle is not stopping TIMER_REPEAT?
Reply With Quote #17

Try this:
PHP Code:
#pragma newdecls required 
#include <sourcemod>
#include <sdktools>
#include <multicolors>

Handle g_TimerRoundDelay;
Handle g_TimerSlap;

public 
void OnPluginStart()
{
    
HookEvent("round_start"Event_RoundStart);
    
HookEvent("round_end"Event_RoundEnd);
}

public 
void OnMapEnd()
{
    
delete g_TimerRoundDelay;
    
delete g_TimerSlap;
}

public 
Action Event_RoundStart(Handle event, const char[] namebool dontBroadcast)
{    
    
g_TimerRoundDelay CreateTimer(30.0Timer_RoundDelay);
}

public 
Action Timer_RoundDelay(Handle timer)
{
    
g_TimerSlap CreateTimer(2.0Timer_SlapPlayerTIMER_REPEAT);
    
g_TimerRoundDelay null;
}

public 
Action Event_RoundEnd(Handle event, const char[] namebool dontBroadcast)
{
    
delete g_TimerRoundDelay;
    
delete g_TimerSlap;
    
PrintToConsoleAll("Round ended, timers deleted");
}

public 
Action Timer_SlapPlayer(Handle timer
{
    for (
int i 1<= MaxClientsi++)
    {
        if (
IsClientInGame(i) && IsPlayerAlive(i))
        {
            
SlapPlayer(i20true);
            
CPrintToChat(i"{green}You are getting slapped");
        }
    }

__________________
Ilusion9 is offline
Marttt
Veteran Member
Join Date: Jan 2019
Location: Brazil
Old 03-09-2020 , 16:30   Re: CloseHandle is not stopping TIMER_REPEAT?
Reply With Quote #18

Thanks about the feedback Dragokas, I didn't pay attention in the whole thread, my mistake.

Anyway, I still think that is not really necessary using Handles here...it is just increasing the complexity for a simple thing.

You can control that with a simple bool var.

Gonna try here again...

__________________

EDIT:
Here we go, worked for me in my L4D2 Versus Server

Spoiler
__________________

Last edited by Marttt; 03-09-2020 at 16:46.
Marttt is offline
Ilusion9
Veteran Member
Join Date: Jun 2018
Location: Romania
Old 03-09-2020 , 16:50   Re: CloseHandle is not stopping TIMER_REPEAT?
Reply With Quote #19

You still need handles if the round ends too soon.
Should create a single timer in OnPluginStart (repeated timer), check if had passed 30 seconds since round start, then slap players.
__________________

Last edited by Ilusion9; 03-09-2020 at 16:51.
Ilusion9 is offline
Marttt
Veteran Member
Join Date: Jan 2019
Location: Brazil
Old 03-09-2020 , 17:17   Re: CloseHandle is not stopping TIMER_REPEAT?
Reply With Quote #20

Ilusion, yeah you are correct.
Well I made another version that minimizes that error, but still can "be exploited" in rare (impossible?) cases (between 2 seconds).

Spoiler
__________________
Marttt 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:57.


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