API overview
Author-time types ship in two npm packages; the engine injects the runtime at load:
@s2script/sdk— every engine-generic capability. Prefer the root barrel (import { command, hook } from "@s2script/sdk"); subpaths (@s2script/sdk/entity,/events,/chat, …) stay valid. Also carries thes2sbuild CLI.@s2script/sdk/unsafestays a deliberate subpath.@s2script/cs2— CS2 game types (Player,Pawn, schema accessors, the typed event overlay,ChatColors).Playeris not on the SDK barrel.
How imports work#
import { command, hook, HookResult } from '@s2script/sdk';
import { Player } from '@s2script/cs2';Add @s2script/sdk (and @s2script/cs2) to your package’s dependencies. The CLI externalizes both by wildcard; the host maps @s2script/sdk/<name> → the injected runtime module. Subpath imports stay valid.
Two flavors of API#
- Load-window APIs — call from
OnPluginStart; they throw after settle.command,hook.on/hook.onPre,translations,publish/use/tryUse/watchOptional/bindForwards,previous(),pluginId(),createScope(),onOutput,topmenu. On CS2,CustomHudLayout(uiis a deprecated alias),gameRules,players,items(ItemsApi—import { items } from "@s2script/cs2"). These are ledgered and torn down on unload.hudkitis used fromOnPluginStartor a later callback — methods andlayout/hudthrow before plugin context exists; claimed handles stay usable after settle. CJS module evaluation is before this window — do not register at module top level. - Named publics —
OnPluginStart/OnPluginEnd/OnPluginState,OnMapStart/OnGameFrame/OnClientConnected/OnEntityCreated/OnTakeDamage/ … Missing export = not subscribed. Game events arehook.on/hook.onPre, nothooksubjects. - Stateless helpers are plain named imports —
Chat,Player,Admin,config,Translations,Events.fire,delay,fetch.config.onChangeis typed on the freeconfigimport and is not load-window-gated.
SDKHook is the exception to load-window registration: per-entity, books-gated, callable whenever you hold a live EntityRef. See SDKHooks (OnTakeDamage / OnTakeDamagePost, SetTransmit, lifecycle virtuals, Weapon* / Reload).
import { hook, Chat } from '@s2script/sdk';
export function OnPluginStart(): void {
hook.on('round_start', () => Chat.toAll('go!')); // game-event catalog → hook
}
export function OnGameFrame(): void {
// before simulation — SourceMod's public. There is no OnGameFramePre / OnGameFramePost.
}Post-simulation work is createScope().server.onGameFrame(fn, { phase: 'post' }), not a named public. See lifecycle.
Engine-generic highlights#
| Subpath | Role |
|---|---|
@s2script/sdk | Authoring barrel: command, hook, previous, named-public types |
@s2script/sdk/plugin | hook (game-event catalog), onOutput, createScope, previous, publish / use / watchOptional / bindForwards, Scope |
@s2script/sdk/entity | EntityRef, create/spawn, I/O |
@s2script/sdk/events | Fire events + HookResult |
@s2script/sdk/sdkhooks | SDKHook / SDKUnhook (OnTakeDamage / OnTakeDamagePost, SetTransmit, lifecycle virtuals, Weapon* / Reload) |
@s2script/sdk/timers | delay / nextTick / nextFrame / threadSleep |
@s2script/sdk/clients | Connection-lifetime Client handle |
@s2script/sdk/commands | command / command.admin / command.server |
@s2script/sdk/chat | Chat send |
@s2script/sdk/admin | Admin flags + cache |
@s2script/sdk/server | Server.command, cvars |
@s2script/sdk/db | SQLite / SQL database (named result-size errors) |
@s2script/sdk/cookies | Client preference cookies (set / setAuthId admission boolean) |
@s2script/sdk/http · /ws · /net | Async network (boolean socket sends; named capacity errors) |
@s2script/sdk/menu · /topmenu · /votes | Menus, TopMenu dashboard, votes |
@s2script/sdk/translations | Phrase files + cmd.replyT |
@s2script/sdk/unsafe | Engine.function — plugin-declared engine calls and PRE/POST hooks |
CS2#
@s2script/cs2 — Player, Pawn, schema accessors, the typed event overlay, ChatColors, pickPlayer, Fade/Shake/HintText, CustomPlayerCamera, and CustomHudLayout / hudkit (custom Panorama HUD — prefer hudkit). Load-window CS2 exports: CustomHudLayout, gameRules, players, items (ItemsApi pickup gates). Use hudkit from OnPluginStart or later (throws before plugin context; usable after settle).
Next#
- Full package reference
- Modules catalog — generated from the shipped type definitions
- Concepts: lifecycle, entities, events, SDKHooks, commands, translations, async, cookies, interfaces, HUD, custom camera