Skip to content

tm.players ​

Per player cooldowns and active player iteration. Server only.

These cooldowns are keyed by player server id and live in memory for the calling resource, so each resource has its own set. For cooldowns keyed to a character or any other id, use tm.cooldowns.

Durations are in seconds (fractions allowed), for example 0.5 or 30.

lua
if not tm.players.checkCooldown(source, 5.0, true, 'rob_store') then
    return          -- on cooldown
end
-- allowed, and a 5 second cooldown just started
FunctionNotes
checkCooldown(source, duration, update?, id?)Returns true when the player is not on cooldown. With update, the cooldown starts or restarts in the same call whether or not it was running. id (default 1) names separate cooldowns per player.
updateCooldown(source, id?)Starts or restarts a cooldown without checking.
waitForCooldown(source, duration, update?, id?)Yields the calling thread until the cooldown runs out (it sleeps, it does not spin), then optionally restarts it. Returns false when someone else restarted the cooldown while this call waited, or when the player left.
getActivePlayers()Iterator over the server ids of connected players: for source in tm.players.getActivePlayers() do ... end.
getAllCooldowns()The live table (source, then id, then start time in seconds). Read only.

Entries are removed when the player drops.

Durations are in seconds. Time comes from GetGameTimer() (wall time), and waitForCooldown sleeps instead of spinning.