Modules

Docs / API / Modules / events

Events

Players & world

@s2script/sdk/events

Typed game-event bus: fire / fireToClient, HookResult, and the block-scoped GameEvent accessor.

Import

import { GameEvent } from "@s2script/sdk/events";

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.

class
GameEvent

A live game-event accessor. Valid ONLY during the synchronous handler — read fields before any await; a stashed GameEvent used later reads defaults. The raw engine event never crosses to JS.

readonly name: string
The event's name (e.g. "player_death").
getInt(key: string): number
Read an integer field. 0 if absent or non-integer.
getFloat(key: string): number
Read a float field. 0 if absent or non-float.
getBool(key: string): boolean
Read a boolean field. false if absent.
getString(key: string): string
Read a string field. "" if absent.
getUint64(key: string): string
A 64-bit field as a decimal string (SM-parity, wire-safe).
getPlayerSlot(key: string): number
A player field (e.g. "userid"/"attacker") as a 0-based slot, or -1 if absent. Resolve with Player.fromSlot.
setInt(key: string, value: number): void
Overwrite an integer field on the live event (valid only in the synchronous handler).
setFloat(key: string, value: number): void
Overwrite a float field on the live event (valid only in the synchronous handler).
setBool(key: string, value: boolean): void
Overwrite a boolean field on the live event (valid only in the synchronous handler).
setString(key: string, value: string): void
Overwrite a string field on the live event (valid only in the synchronous handler).
setUint64(key: string, value: string): void
Set a 64-bit field from a decimal string (SM-parity, wire-safe).
const
HookResult

Collapsed pre-hook result. Return from an onPre handler; Handled/Stop suppress the client broadcast (server still processes). Returning nothing = Continue.

readonly Continue: 0
No change — proceed normally. Equivalent to returning nothing.
readonly Changed: 1
Fields were modified in place; proceed with the changes (the client broadcast still happens).
readonly Handled: 2
Suppress the client broadcast (the server still processes the event).
readonly Stop: 3
Suppress the client broadcast AND stop running lower-priority handlers. The collapse takes the MAX.
type
HookResultValue

The numeric union an onPre handler may return — one of the HookResult values.

const
Events

Fire and target game events from JS.

import { Events } from "@s2script/sdk/events";
// plugins/playercommands/src/plugin.ts:78 — announce a name change
Events.fire("player_changename", { userid: p.userId, oldname, newname });
fire(name: string, fields?: Record<string, number | string | boolean | bigint>, dontBroadcast?: boolean): boolean
Fire a game event. Returns the engine FireEvent result.
fireToClient(slot: number, name: string, fields?: Record<string, string | number | boolean | bigint>): boolean
Fire a game event to ONE client (SourceMod FireToClient). Same field type-inference as fire. Returns false on miss.
Back to modules All packages

s2script — Source 2 plugin framework

GitHub