ServerServer console + globals: run commands, register/read/set cvars, and query map/time state.
import { Server } from "@s2script/sdk/server";
// plugins/basecommands/src/plugin.ts:46 — sm_map
Server.command("changelevel " + map);command(cmd: string): voidcmd at the server console (queued; executes next frame).isMapValid(map: string): booleanmap is an installed, valid map file.getCvar(name: string): string"" if the cvar doesn't exist (or an unsupported type → "<type>").setCvar(name: string, value: string): void<name> <value>), which the console splits on ; — treat value like command() input and
sanitize/quote any untrusted value to avoid command injection. Queued: applies next frame.registerCvar(name: string, opts: {
type: "bool" | "int" | "float" | "string";
default: boolean | number | string;
help?: string;
flags?: number;
min?: number;
max?: number;
}): booleanflags
are additive raw FCVAR bits. Read the value with getCvar; set it with setCvar/the console.
min/max apply to numeric types only.onCvarChange(name: string, handler: (name: string, newValue: string, oldValue: string) => void): { dispose(): void }Watch a cvar for changes (SourceMod HookConVarChange, ModSharp's cvar change hook).
name is a cvar name, or "*" for every cvar. The handler receives the cvar's name and its
new and old values as strings — for "*" the name tells you which one moved.
NOTIFY-only: the engine's global change callback runs **after** the value has been applied, so
a handler cannot veto a change; returning anything is ignored. A handler that throws is logged
and contained, and the remaining handlers still run.
Subscriptions are ledgered — unload removes them whether or not dispose() is called.
import { Server } from "@s2script/sdk/server";
Server.onCvarChange("mp_friendlyfire", (name, next, prev) => {
console.log(`${name}: ${prev} -> ${next}`);
});readonly maxPlayers: numberGetMaxClients()). 0 if unavailable.readonly mapName: stringGetMapName(), the BSP). "" if unavailable.readonly gameTime: numberGetGlobals()->curtime). 0 if unavailable.