View Single Post
Author Message
Mikusch
AlliedModders Donor
Join Date: Oct 2019
Location: Germany
Old 10-27-2022 , 16: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 04:12.
Mikusch is offline