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

CloseHandle is not stopping TIMER_REPEAT?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
TheFlyingApple
Member
Join Date: Aug 2016
Old 03-08-2020 , 17:04   CloseHandle is not stopping TIMER_REPEAT?
Reply With Quote #1

Hi,

I'm trying to create a script that slaps someone every 2 seconds, 30 seconds into the round. However, the slap timer never stops, which means that on the next round start, everyone will be slapped instantly.. What am I doing wrong?

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

new Handle:g_timerAntiCamp1 INVALID_HANDLE;
new 
Handle:g_timerAntiCamp2 INVALID_HANDLE;

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

public 
OnMapEnd()
{
    
g_timerAntiCamp1 INVALID_HANDLE;
    
g_timerAntiCamp2 INVALID_HANDLE;
}

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)
{
    
/* Clean up timers */
    
if (g_timerAntiCamp1 != INVALID_HANDLE) {
        
CloseHandle(g_timerAntiCamp1);
        
g_timerAntiCamp1 INVALID_HANDLE;
    }

    if (
g_timerAntiCamp2 != INVALID_HANDLE) {
        
CloseHandle(g_timerAntiCamp2);
        
g_timerAntiCamp2 INVALID_HANDLE;
    }
    
}

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

public 
Action CheckPlayerZone(Handle:timer
{
    for (new 
1<= MaxClientsi++)
    {
        if (
>= && <= MaxClients && IsClientConnected(i) && IsClientInGame(i) && IsPlayerAlive(i))
        {

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


Last edited by TheFlyingApple; 03-08-2020 at 17:04.
TheFlyingApple is offline
ddhoward
Veteran Member
Join Date: May 2012
Location: California
Old 03-08-2020 , 17:12   Re: CloseHandle is not stopping TIMER_REPEAT?
Reply With Quote #2

Why the old syntax? You've even got #newdecls required but you're not using the newdecls?

Also, why the extra i >= 1 && i <= MaxClients check? You're already looping i through 1 and MaxClients; it's guaranteed to be within that range. Also, IsClientInGame() has a IsClientConnected() check built in.

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);
}

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

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

My suggestion would be to add some debug text in the round end hook, to see if that's even actually firing. I've added such text above.
__________________

Last edited by ddhoward; 03-08-2020 at 17:14.
ddhoward is offline
8guawong
AlliedModders Donor
Join Date: Dec 2013
Location: BlackMarke7
Old 03-09-2020 , 03:50   Re: CloseHandle is not stopping TIMER_REPEAT?
Reply With Quote #3

Quote:
Originally Posted by TheFlyingApple View Post
Hi,

I'm trying to create a script that slaps someone every 2 seconds, 30 seconds into the round. However, the slap timer never stops, which means that on the next round start, everyone will be slapped instantly.. What am I doing wrong?

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

new Handle:g_timerAntiCamp1 INVALID_HANDLE;
new 
Handle:g_timerAntiCamp2 INVALID_HANDLE;

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

public 
OnMapEnd()
{
    
g_timerAntiCamp1 INVALID_HANDLE;
    
g_timerAntiCamp2 INVALID_HANDLE;
}

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)
{
    
/* Clean up timers */
    
if (g_timerAntiCamp1 != INVALID_HANDLE) {
        
CloseHandle(g_timerAntiCamp1);
        
g_timerAntiCamp1 INVALID_HANDLE;
    }

    if (
g_timerAntiCamp2 != INVALID_HANDLE) {
        
CloseHandle(g_timerAntiCamp2);
        
g_timerAntiCamp2 INVALID_HANDLE;
    }
    
}

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

public 
Action CheckPlayerZone(Handle:timer
{
    for (new 
1<= MaxClientsi++)
    {
        if (
>= && <= MaxClients && IsClientConnected(i) && IsClientInGame(i) && IsPlayerAlive(i))
        {

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

did you check to see if there are any errors in your log?
__________________
8guawong is offline
Dragokas
Veteran Member
Join Date: Nov 2017
Location: Ukraine on fire
Old 03-09-2020 , 10:45   Re: CloseHandle is not stopping TIMER_REPEAT?
Reply With Quote #4

TheFlyingApple,

Minimal sample "How to stop (delete) global repeatable timer on round end"
__________________
Expert of CMD/VBS/VB6. Malware analyst. L4D fun (Bloody Witch & FreeZone)
[My plugins] [My tools] [GitHub] [Articles] [HiJackThis+] [Donate]
Dragokas is offline
TheFlyingApple
Member
Join Date: Aug 2016
Old 03-09-2020 , 13:20   Re: CloseHandle is not stopping TIMER_REPEAT?
Reply With Quote #5

I have updated the code a bit... It looks like this now:

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

Handle g_timerAntiCamp1;
Handle g_timerAntiCamp2;

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

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

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

public 
Action CheckRoundTime(Handle timer)
{
    
delete g_timerAntiCamp2;
    
g_timerAntiCamp2 CreateTimer(2.0CheckPlayerZone_TIMER_REPEAT);
}

public 
Action CheckPlayerZone(Handle:timer
{
    for (new 
1<= MaxClientsi++)
    {
        if (
IsClientConnected(i) && IsClientInGame(i) && IsPlayerAlive(i))
        {
            
SlapPlayer(i20true);
            
CPrintToChat(i"{green}You are being slapped!");
        }
    }


Quote:
Originally Posted by 8guawong View Post
did you check to see if there are any errors in your log?
I get the following message in console:

PHP Code:
[SMException reportedHandle a9a07e3 is invalid (error 1)
[
SMBlamingslap.smx
[SMCall stack trace:
[
SM]   [0CloseHandle
[SM]   [1Line 34slap.sp::Round_Start_Hook 
Which is pointing to the line
PHP Code:
delete g_timerAntiCamp1
Quote:
Originally Posted by Dragokas View Post
I tried that with my code. It did not solve the problem. The timer is still running after round end.
TheFlyingApple is offline
Dragokas
Veteran Member
Join Date: Nov 2017
Location: Ukraine on fire
Old 03-09-2020 , 13:40   Re: CloseHandle is not stopping TIMER_REPEAT?
Reply With Quote #6

Because you didn't zeroed single timer's handle when it is no more valid (in callback).

PHP Code:
#pragma semicolon 1 
#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_End_Hook(Handle event, const char[] namebool dontBroadcast
{
    
delete g_timerAntiCamp1
    
delete g_timerAntiCamp2
}

public 
Action Round_Start_Hook(Handle event, const char[] namebool dontBroadcast

    
delete g_timerAntiCamp1
    
g_timerAntiCamp1 CreateTimer(30.0CheckRoundTime); 


public 
Action CheckRoundTime(Handle timer

    
delete g_timerAntiCamp2;
    
g_timerAntiCamp2 CreateTimer(2.0CheckPlayerZone_TIMER_REPEAT); 
    
g_timerAntiCamp1 INVALID_HANDLE;
}

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

__________________
Expert of CMD/VBS/VB6. Malware analyst. L4D fun (Bloody Witch & FreeZone)
[My plugins] [My tools] [GitHub] [Articles] [HiJackThis+] [Donate]
Dragokas is offline
Marttt
Veteran Member
Join Date: Jan 2019
Location: Brazil
Old 03-09-2020 , 14:05   Re: CloseHandle is not stopping TIMER_REPEAT?
Reply With Quote #7

I don't think you need control the handles for this.
Also, usually is good to use TIMER_FLAG_NO_MAPCHANGE flag with TIMER_REPEAT

Try this modifications:

Spoiler
__________________

Last edited by Marttt; 03-09-2020 at 14:08.
Marttt is offline
TheFlyingApple
Member
Join Date: Aug 2016
Old 03-09-2020 , 14:12   Re: CloseHandle is not stopping TIMER_REPEAT?
Reply With Quote #8

Quote:
Originally Posted by Dragokas View Post
Because you didn't zeroed single timer's handle when it is no more valid (in callback).

PHP Code:
#pragma semicolon 1 
#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_End_Hook(Handle event, const char[] namebool dontBroadcast
{
    
delete g_timerAntiCamp1
    
delete g_timerAntiCamp2
}

public 
Action Round_Start_Hook(Handle event, const char[] namebool dontBroadcast

    
delete g_timerAntiCamp1
    
g_timerAntiCamp1 CreateTimer(30.0CheckRoundTime); 


public 
Action CheckRoundTime(Handle timer

    
delete g_timerAntiCamp2;
    
g_timerAntiCamp2 CreateTimer(2.0CheckPlayerZone_TIMER_REPEAT); 
    
g_timerAntiCamp1 INVALID_HANDLE;
}

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

I tried that code... Just gave me a new warning:

Code:
[SM] Plugin "devzones_anticampslap.smx" encountered error 23: Native detected error
[SM] Invalid timer handle 117b07ed (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
TheFlyingApple
Member
Join Date: Aug 2016
Old 03-09-2020 , 14:16   Re: CloseHandle is not stopping TIMER_REPEAT?
Reply With Quote #9

Quote:
Originally Posted by Marttt View Post
I don't think you need control the handles for this.
Also, usually is good to use TIMER_FLAG_NO_MAPCHANGE flag with TIMER_REPEAT

Try this modifications:

Spoiler
I now tried this. The problem is still the same.. When a new round starts slapping begins immediately.. No errors in console, though!
TheFlyingApple is offline
Dragokas
Veteran Member
Join Date: Nov 2017
Location: Ukraine on fire
Old 03-09-2020 , 14:27   Re: CloseHandle is not stopping TIMER_REPEAT?
Reply With Quote #10

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.
__________________
Expert of CMD/VBS/VB6. Malware analyst. L4D fun (Bloody Witch & FreeZone)
[My plugins] [My tools] [GitHub] [Articles] [HiJackThis+] [Donate]

Last edited by Dragokas; 03-09-2020 at 14:28.
Dragokas 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 18:44.


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