Raised This Month: $44 Target: $400
 11% 

[ANY] More Timers


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Mikusch
AlliedModders Donor
Join Date: Oct 2019
Location: Germany
Old 10-27-2022 , 17:47   [ANY] More Timers
Reply With Quote #1

More Timers is an extension that adds the IntervalTimer and CountdownTimer classes from the Source SDK as Handle methodmaps.

This is useful if you want Valve-style timers without having to keep track of timestamps and durations by yourself.

Yes, you can technically do something similar in SourcePawn with enum structs already, but it is a bit of a pain if you want to store the timer state (which is precisely why I made this).

https://github.com/Mikusch/moretimers/releases

Example:
PHP Code:
#include <moretimers>

CountdownTimer g_PrintCountdownTimer;
IntervalTimer g_PrintIntervalTimer;

public 
void OnPluginStart()
{
    
// Initialize our timer variables.
    // Remember to close Handles using the 'delete' operator to avoid memory leaks.
    
g_PrintCountdownTimer = new CountdownTimer();
    
g_PrintIntervalTimer = new IntervalTimer();
}

public 
void OnClientPutInServer(int client)
{
    
// Start the countdown timer. If restarted while already running, the elapsed time resets.
    
g_PrintCountdownTimer.Start(3.0);
}

public 
void OnGameFrame()
{
    
// Use the countdown timer.
    
if (g_PrintCountdownTimer.HasStarted() && g_PrintCountdownTimer.IsElapsed())
    {
        
g_PrintCountdownTimer.Invalidate();
        
LogMessage("New player(s) have joined the server.");
    }
    
    
// Start and use the interval timer.
    
if (!g_PrintIntervalTimer.HasStarted())
    {
        
g_PrintIntervalTimer.Start();
    }
    else if (
g_PrintIntervalTimer.IsGreaterThan(10.0))
    {
        
g_PrintIntervalTimer.Invalidate();
        
LogMessage("This log message sends every 10 seconds.");
    }

__________________

Last edited by Mikusch; 10-28-2022 at 05:12.
Mikusch is offline
luki1412
Veteran Member
Join Date: Oct 2008
Location: OnPluginStart()
Old 10-28-2022 , 18:38   Re: [ANY] More Timers
Reply With Quote #2

Is there no Stop function? Does Invalidate stop the timer?
Is there pause/unpause functionality?
__________________
luki1412 is offline
Reply


Thread Tools
Display Modes

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 19:42.


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