View Single Post
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 11-21-2022 , 18:24   Re: Stop Timer before Callback
Reply With Quote #4

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_Stop// If repeating timer flag in use
    
}

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



    
PrintToChatAll("My timer got executed");

    
//return Plugin_Continue;
    
return Plugin_Stop// If repeating timer flag in use

__________________
Do not Private Message @me

Last edited by Bacardi; 11-29-2022 at 15:27. Reason: change return type. Doesn't really matter when not using repeating timer flag..
Bacardi is offline