AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Extensions (https://forums.alliedmods.net/forumdisplay.php?f=134)
-   -   [ANY] More Timers (https://forums.alliedmods.net/showthread.php?t=340133)

Mikusch 10-27-2022 16:47

[ANY] More Timers
 
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.");
    }



luki1412 10-28-2022 17:38

Re: [ANY] More Timers
 
Is there no Stop function? Does Invalidate stop the timer?
Is there pause/unpause functionality?


All times are GMT -4. The time now is 06:40.

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