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
Adjusts a previously created (timer.Create) timer with the given identifier.
timer.Check()
Deprecated: 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.
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.
Warning: 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 or delay is set to 0 ).
Deprecated: 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.
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.
Stops and removes a timer created by timer.Create.
Warning: The timers are removed in the next frame! Keep this in mind when storing identifiers in variables.
Returns amount of repetitions/executions left before the timer destroys itself.
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.
Warning: 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).Warning: A previous message on this page stated that a delay of 0 would run the function on the next tick. This was partially an invalid assumption, and the true behavior is dependent on where timer.Simple(0, func) is called relative to GarrysMod::Lua::Libraries::Timer::DoSimpleTimers.
If called before DoSimpleTimers, the callback will be executed on the same frame.
If called during DoSimpleTimers, the callback will be executed on the same frame. Note that calling timer.Simple(0, func) recursively (ie. a function that calls timer.simple(0, itself)) can lead to a hang!
If called after DoSimpleTimers, the callback will be executed on the next frame.
For more information on hook execution order, see Lua Hooks Order.
Restarts the given timer.
Note: Timers use CurTime for timing.Warning: Timers won't advance while the client is timing out from the server.
Returns amount of time left (in seconds) before the timer executes its function.
Note: If the timer is paused, the amount will be negative.
Runs either timer.Pause or timer.UnPause based on the timer's current status.
Garry's Mod
Rust
Steamworks
Wiki Help