Modules

Docs / API / Modules / server

Server

Admin & chat

@s2script/sdk/server

Server.command, cvars, map validity, and onMapStart.

Import

import { Server } from "@s2script/sdk/server";

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.

const
Server

Server 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): void
Run cmd at the server console (queued; executes next frame).
isMapValid(map: string): boolean
Whether map is an installed, valid map file.
getCvar(name: string): string
A cvar's current value as a string. "" if the cvar doesn't exist (or an unsupported type → "<type>").
setCvar(name: string, value: string): void
Set a cvar via the server console (so any type is accepted). SECURITY: this builds and runs a console command (<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;
  }): boolean
Register a plugin-owned ConVar (CSSharp FakeConVar / SM CreateConVar parity). Idempotent — re-registering an existing name is a no-op success, and the cvar + its value persist across plugin reloads (SourceMod parity). The shim adds FCVAR_RELEASE (customer-visible); flags are additive raw FCVAR bits. Read the value with getCvar; set it with setCvar/the console. min/max apply to numeric types only.
readonly maxPlayers: number
The server's configured max client count (GetMaxClients()). 0 if unavailable.
readonly mapName: string
The current map name (GetMapName(), the BSP). "" if unavailable.
readonly gameTime: number
The current map time in seconds (GetGlobals()->curtime). 0 if unavailable.
Back to modules All packages

s2script — Source 2 plugin framework

GitHub