Author-time types ship in the npm package; the engine injects the runtime at plugin load.
Add @s2script/sdk to your plugin's dependencies.
API reference
Generated from the shipped type definitions.
fn
delay(ms: number): Promise<void>
Await a delay of ms milliseconds before continuing. Tick-integrated (resumes on a game frame).
Rejects with AsyncQueueFull at the global or owning plugin timer limit.
import { delay } from "@s2script/sdk/timers";// plugins/funcommands/src/plugin.ts:77 — sm_freeze auto-unfreeze after `secs`delay(secs * 1000).then(() => { const q = Player.fromSlot(slot); if (q && q.pawn) q.pawn.moveType = WALK; });
fn
nextTick(): Promise<void>
Yield to the next microtick. Rejects with AsyncQueueFull at the timer admission limit.
fn
nextFrame(): Promise<void>
Yield until the next game frame. Rejects with AsyncQueueFull at the timer admission limit.
fn
threadSleep(ms: number): Promise<void>
Sleep on a worker thread; the returned promise settles on a later game frame.
Rejects with AsyncQueueFull when outstanding jobs or the worker queue are full.
interface
Timer
A live callback timer, returned by after and every. Ledgered against the creating
plugin: unload kills it whether or not kill() was called, so a repeating timer can never outlive
its plugin and fire into a dead context.
readonly alive: boolean
— False once the timer has fired (one-shot), been killed, or had its plugin unloaded.
kill(): boolean
— Cancel it. Idempotent — returns false if it was already dead. Safe to call from inside the callback.
fn
after(ms: number, fn: () => void): Timer
Run fn once after ms milliseconds (SourceMod CreateTimer without TIMER_REPEAT).
Throws an error named AsyncQueueFull if no timer slot is available.
Prefer delay when you can await; use this when you need something cancellable.
A throwing callback is reported and contained — it never kills the frame or the timer system.
import { after } from "@s2script/sdk/timers";const t = after(5000, () => console.log("5s later"));t.kill(); // ...unless cancelled first
fn
every(ms: number, fn: () => void): Timer
Run fn every ms milliseconds until killed (SourceMod CreateTimer with TIMER_REPEAT).
Throws an error named AsyncQueueFull if no timer slot is available.
The next firing is scheduled *after* the callback returns, so a slow callback cannot pile up.
ms must be greater than 0 — a zero-interval repeat would re-arm every drain and starve the
frame, so it throws rather than degrading.
import { every } from "@s2script/sdk/timers";const tick = every(1000, () => console.log("tick"));// later: tick.kill();