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,previous(),pluginId(),createScope(),onOutput,topmenu. On CS2,ui,gameRules,players,items. These are ledgered and torn down on unload. - 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, SetTransmit, lifecycle virtuals).
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, Scope |
@s2script/sdk/entity | EntityRef, create/spawn, I/O |
@s2script/sdk/events | Fire events + HookResult |
@s2script/sdk/sdkhooks | SDKHook / SDKUnhook (OnTakeDamage, SetTransmit, lifecycle virtuals) |
@s2script/sdk/timers | delay / nextTick / nextFrame |
@s2script/sdk/clients | 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 |
@s2script/sdk/http · /ws · /net | Async network |
@s2script/sdk/menu · /votes | Menus + votes |
@s2script/sdk/translations | Phrase files + cmd.replyT |
@s2script/sdk/unsafe | Plugin-declared engine calls and inbound hooks |
CS2
@s2script/cs2 — Player, Pawn, schema accessors, the typed event overlay, ChatColors, pickPlayer, Fade/Shake/HintText, and ui (custom Panorama HUD — prefer components()). Load-window CS2 exports: ui, gameRules, players, items.
Next
- Full package reference
- Modules catalog — generated from the shipped type definitions
- Concepts: lifecycle, entities, events, SDKHooks, commands, translations, async, HUD