Client timers and waits
Client scripts use the scheduling functions from revo-client. Server scripts
use Node.js timers, and WebViews use browser timers.
Choose a scheduler
Section titled “Choose a scheduler”All delays are in milliseconds.
| Function | Runs | Cancellation |
|---|---|---|
revo.everyTick(handler) |
Every game frame | revo.clearEveryTick(handle) |
revo.setTimeout(handler, delay) |
Once, after the delay | revo.clearTimeout(handle) |
revo.setInterval(handler, interval) |
Repeatedly, after each interval | revo.clearInterval(handle) |
revo.wait(delay) |
Resolves a Promise after the delay | Ends when resolved or the script stops |
revo.waitFor(predicate, timeout) |
Checks a condition each frame until it returns true |
Ends when resolved, rejected or the script stops |
The callback-based functions return numeric handles. Keep the handle to cancel pending or recurring work when the feature using it ends.
Timers run with game frames. A delay sets the earliest time a callback can run, so a slow frame can delay it. A 1 ms interval still runs at most once per frame. After a late frame, an interval runs once and schedules its next call from that point.
setTimeout() and wait() default to 0, which schedules work for a later
frame. setInterval() defaults to 1 and clamps smaller values to 1.
Work that needs every frame
Section titled “Work that needs every frame”Some GTA natives apply only to the current frame. This example keeps the HUD
hidden for the requested duration, then removes its frame callback. Call
hideHudFor(5000) when the feature starts to hide it for five seconds:
// @ts-check/// <reference types="@revomp/types-client" />/// <reference types="@revomp/types-natives" />
import * as revo from 'revo-client';import * as natives from 'natives';
/** @param {number} duration Duration in milliseconds. */async function hideHudFor(duration) { const tick = revo.everyTick(() => { natives.hideHudAndRadarThisFrame(); });
try { await revo.wait(duration); } finally { revo.clearEveryTick(tick); }}Use everyTick() for work that needs to follow each frame. For changes already
reported by an event, subscribe to that event.
Wait for a condition
Section titled “Wait for a condition”waitFor() starts checking its predicate on a later frame. The predicate must
be synchronous and return a boolean. Keep it quick, since it runs every frame
while waiting.
The timeout defaults to 5000 ms. The Promise rejects if the condition times
out, the predicate throws or it returns a non-boolean value. Catch the rejection
where the feature can recover or report the failure.
When an API provides a readiness method, such as WebView.waitForReady(), use
that method directly.
Asynchronous callbacks and cleanup
Section titled “Asynchronous callbacks and cleanup”Interval scheduling continues while an async callback is awaiting. Schedule
the next run after completion when calls must stay sequential.
Leaving a server stops its client scripts and clears their timers and frame
callbacks. Pending waits are abandoned with the script. Code after those waits,
including finally blocks, is not resumed during teardown. Clear recurring
callbacks when their feature ends during the session, as in the example above.
For waits during startup, see Loading screen.