Modules

Docs / API / Modules / commands

Commands

Admin & chat

@s2script/sdk/commands

Console + chat command registration: register / registerServer / registerAdmin.

Import

import { CommandInvocation } from "@s2script/sdk/commands";

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.

interface
CommandInvocation

The parsed invocation handed to a command callback: who called it, its arguments (multiple typed accessors), and a caller-appropriate reply channel. Valid only for the duration of the callback.

readonly callerSlot: number
0-based caller slot, or -1 for the server console.
readonly args: string[]
argString split on whitespace (0-based; the command name is NOT included). Kept for compat.
readonly argString: string
everything after the command name (raw) — SM GetCmdArgString.
readonly argCount: number
number of whitespace-split arguments — SM GetCmdArgs.
arg(n: number): string
the nth argument (0-based), or "" if absent — SM GetCmdArg.
argInt(n: number, fallback?: number): number
the nth argument parsed as an integer, or fallback (default 0) if absent/non-numeric.
argFloat(n: number, fallback?: number): number
the nth argument parsed as a float, or fallback (default 0) if absent/non-numeric.
argsFrom(n: number): string
every argument from index n onward, re-joined with a single space (a reason/message/value that spans spaces).
reply(message: string): void
reply to the caller: server console → server print; a player → their chat.
replyT(key: string, ...args: (string | number)[]): void
reply to the caller, translated for THEIR language (SM's %t on the reply path). Soft-deps @s2script/translations — degrades to the raw key if it isn't loaded.
interface
ChatTrigger

A parsed chat trigger: which command + args, and whether it was the silent (/) trigger.

readonly silent: boolean
true = the silent trigger (/, hidden); false = the public trigger (!).
readonly name: string
the command name (the first token after the trigger char; NOT sm_-prefixed).
readonly argString: string
everything after the command name.
const
Commands

Command-registry utilities: dispatch by name, parse/route chat triggers, and enumerate the global registry. Commands themselves are registered through the plugin context (ctx.commands.register*).

import { Commands } from "@s2script/sdk/commands";
// sm_help backend: every registered command + its required admin flag mask.
const cmds = Commands.list().slice().sort((a, b) => (a.name < b.name ? -1 : 1));
dispatch(name: string, slot: number, argString: string): boolean
Invoke a registered command by name in THIS plugin (applying its gating). Returns true if it exists.
parseChatTrigger(message: string): ChatTrigger | null
Parse a chat message for a trigger (!//). Returns the parsed trigger, or null if it's ordinary chat.
handleChatTrigger(slot: number, message: string): { silent: boolean; ran: boolean } | null
If message is a trigger, dispatch the command (tries name then sm_<name>) as slot; returns { silent, ran } (the caller should suppress the chat message), or null if it was ordinary chat.
readonly triggers: { public: string; silent: string }
The trigger characters — SM PublicChatTrigger ("!") / SilentChatTrigger ("/"). Mutate to reconfigure.
list(): { name: string; flags: number }[]
Every globally-registered command with its required admin flags: 0 = anyone, -1 = console/server-only, else the ADMFLAG bit mask (map bits→names in your plugin). The sm_help backend.
Back to modules All packages

s2script — Source 2 plugin framework

GitHub