Garry's Mod Wiki

timer

The timer library is a very useful set of functions which allow you to run a function periodically or after a given delay.

Methods

boolean timer.Adjust( any identifier, number delay, number repetitions = nil, function func = nil )
Adjusts the timer if the timer with the given identifier exists.
timer.Check()
We advise against using this. It may be changed or removed in a future update. If you want to check if whether or not a timer exists, use timer. Exists. This function does nothing.
timer.Create( string identifier, number delay, number repetitions, function func )
Creates a new timer that will repeat its function given amount of times. This function also requires the timer to be named, which allows you to control it after it was created via the timer. For a simple one-time timer with no identifiers, see timer. Simple. Timers use CurTime internally. Due to this, they won't advance while the client is timing out from the server or on an empty dedicated server due to hibernation. (unless sv_hibernate_think is set to 1).
timer.Destroy( string identifier )
We advise against using this. It may be changed or removed in a future update. You should be using timer. Remove instead. Stops and destroys the given timer. Alias of timer. Remove.
boolean timer.Exists( string identifier )
Returns whenever the given timer exists or not. For debugging purposes you can use the following commands: lua_dumptimers_cl lua_dumptimers_sv lua_dumptimers_menu These will list all active timers in each realm.
boolean timer.Pause( any identifier )
Pauses the given timer.
timer.Remove( string identifier )
Stops and removes a timer created by timer. Create. The timers are removed in the next frame! Keep this in mind when storing identifiers in variables.
number timer.RepsLeft( any identifier )
Returns amount of repetitions/executions left before the timer destroys itself.
timer.Simple( number delay, function func )
Creates a simple timer that runs the given function after a specified delay. For a more advanced version that you can control after creation, see timer. Create. Timers use CurTime internally. Due to this, they won't advance while the client is timing out from the server or on an empty dedicated server due to hibernation. (unless sv_hibernate_think is set to 1).
boolean timer.Start( any identifier )
Restarts the given timer. Timers use CurTime for timing. Timers won't advance while the client is timing out from the server.
boolean timer.Stop( any identifier )
Stops the given timer and rewinds it.
number timer.TimeLeft( any identifier )
Returns amount of time left (in seconds) before the timer executes its function. If the timer is paused, the amount will be negative.
boolean timer.Toggle( any identifier )
Runs either timer. Pause or timer. UnPause based on the timer's current status.
boolean timer.UnPause( any identifier )
Unpauses the timer.