Garry's Mod Wiki
About
A cooldown will make an event only trigger if a certain amount of time has passed since its last occurrence.
An event cooldown can be created in several ways, and it is made by setting a condition based on time
CurTime
CurTime is a useful tool for setting a delay for an event. The function returns the uptime of the server in seconds, which means we can use it to keep track of time elapsed by saving the returned value, then calling it again.
Here's an example of a cooldown made using CurTime
In the above example, we use CurTime to tell when the last event had occured. Instead, we could use it to determine when the next event should occur
Timers
Another method of setting a delay is using the timer.
Real World Time
If you're dealing with long cooldowns, that should persist between map changes and even server restarts, you'll need to use real world time to set the cooldown. We can use real world time with os.time and os.date
There are different ways to save information between map changes and server restarts. In the following example I'll be using the cookie to set a 24-hour cooldown on my function
This site is a community mirror of the official Garry's Mod wiki.. This site is not maintained by Facepunch Studios.
Page content is automatically updated four times a day. Edits and history are not available.
Last Parsed: Loading...