View Single Post
alasfourom
Senior Member
Join Date: Feb 2022
Location: Saudi Arabia
Old 11-21-2022 , 18:38   Re: Stop Timer before Callback
Reply With Quote #5

Quote:
Originally Posted by Bacardi View Post
Should work, unless... you have something wierd.
PHP Code:

Handle mytimer
;

public 
void OnPluginStart()
{
    
PrintToChatAll("Plugin loaded and timer creted");
    
mytimer CreateTimer(60.0timer_callback);

    
RegConsoleCmd("sm_test"test);
}

public 
Action test(int clientint args)
{
    if(
mytimer != null)
    {
        
delete mytimer;
        
PrintToChat(client"You stop timer.");
    }

    
PrintToChat(client"Piip!");

    return 
Plugin_Handled;
}


public 
Action timer_callback(Handle timer)
{
    
// For example, when multiple timers have accidentally created to same handle, ignore previous timers.
    // Or if Handle is null.
    
if(timer != mytimer)
    {
        return 
Plugin_Continue;
    }

    
// When you know timer callback will finish, not repeating.
    // First step is clear handle.
    
mytimer null;



    
PrintToChatAll("My timer got executed");

    return 
Plugin_Continue;

I liked that
__________________
alasfourom is offline