Events
Subscribe to the game-event catalog with hook.on (post) and hook.onPre (pre). Both are load-window only — they throw after settle, the same window as command.
import { hook, HookResult } from '@s2script/sdk';
export function OnPluginStart(): void {
hook.on('player_spawn', (ev) => {
const slot = ev.getPlayerSlot('userid');
});
hook.onPre('round_start', (ev) => {
ev.setInt('timelimit', 4242);
return HookResult.Handled; // suppress the client broadcast
});
} The GameEvent is valid only synchronously — do not stash ev across await; a stashed event reads defaults.
hook is the game-event catalog only. There is no hook.client, hook.entity, hook.server, or nested hook.events. Callers that used hook.events.on become hook.on. Engine callbacks (map, frame, client, entity lifecycle, damage) are named publics, not hook subjects.
CS2 ships a typed catalog overlay (272 events) on Events from @s2script/cs2, so Events.on('player_death', …) constrains the field keys. Fire custom events with the free Events.fire / Events.fireToClient from @s2script/sdk. From an onPre handler, Events.setRecipients(slots) plus HookResult.Handled delivers the event to exactly those viewers.
Per-entity virtuals and damage are not game events — subscribe with SDKHook (OnTakeDamage, SetTransmit, Spawn/Think/Use). See SDKHooks.
See the events module, the plugin module (hook), and the game events reference.