Raised This Month: $ Target: $400
 0% 

Solved Is there a native to pause timer


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Earendil
Senior Member
Join Date: Jan 2020
Location: Spain
Old 08-02-2022 , 13:24   Re: What IS The Simplest Way To Pause Timer
Reply With Quote #7

PHP Code:
Handle g_hTimer// Store Timer Handle
float g_fTimerTime// Value to parse to timer, build through ConVars or harcode inside your functions.
float g_fTimerStore = -1.0// Store here timer durations for pause/resume (IMPORTANT, NEG VALUES MEAN TIMER NOT CREATED)

void SomethingThatEnablesTimer()
{
    
/*
     * Whatever you want to do before starting Timer here
     * You don't need to add a new function only for this, just copy the 3 lines below in the function that enables this timer
     * Unless timer is being called from multiple functions, then don't make redundant code
     */
     
    
delete g_hTimer;    // Safe way to get rid of old timer if exists and prevent double timer execution
    
g_hTimer CreateTimer(g_fTimerTimePausable_Timer); // Create the timer
    
g_fTimerStore GetGameTime() + g_fTimerTime// Store when the timer will end
}

/*
 * Is not possible to pause a timer, you only can stop and store remaining time and create
 * a new one and then assing the reaining time.
 * You can call PauseTheTimer() and ContinueTimer() multiple times if you want
 */
 
void PauseTheTimer()
{
    
// Trying to pause the timer when it doesn't exist? Nope!
    
if( g_fTimerStore 0.0 )
        return;
        
    
g_fTimerStore -= GetGameTime(); // Substract time to get the remaining time of the timer when stopped
    
delete g_hTimer;    // No method to pause, delete it
}

void ResumeTheTimer()
{
    
// Ehhh.... NO!
    
if( g_fTimerStore 0.0 )
        return;
        
    
delete g_hTimer// Not needed if you have write the code well, but prevents possible errors
    
g_hTimer CreateTimer(g_fTimerStorePausable_Timer);
    
g_fTimerStore += GetGameTime(); // Again convert timer store to the time when the timer will end
}

Action Pausable_Timer(Handle timerany data)
{
    
g_hTimer null// Allways when you store timer Handles
    
g_fTimerStore = -1.0// To prevent to pause/continue timers when there is no timer
    
    /*
     * Your Timer code here
     */
    
return Plugin_Continue// Allways on Actions

__________________
>>My plugins<<
>>GitHub<<
Earendil is offline
 



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:58.


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