Search docs
Search modules and symbols
Modules

Docs / API / Modules / clients

Clients

Players & world

@s2script/sdk/clients

engine-generic client handle + lifecycle events. Resolved at runtime via globalThis.__s2pkg_clients. Import: import { Client, Clients } from "./clients";

Import

import { Client } from "@s2script/sdk/clients";

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.

class
Client

A connected client, identified by its 0-based slot (CPlayerSlot). Slot-backed; getters read live.

readonly slot: number
The client's 0-based engine slot (CPlayerSlot) — the handle's stable identity for its connection.
isValid(): boolean
True while a client occupies this slot.
readonly steamId: string
Decimal SteamID64; "0" for a bot or an unauthenticated client.
readonly name: string
Display name; "" if unavailable.
readonly userId: number
Engine user-id; -1 if none.
readonly signonState: number
Tracked signon state: 0 = none/disconnected, 2 = connected, 5 = spawned, 6 = full (in-game); -1 if the slot is out of range.
readonly isBot: boolean
True for a fake client (bot) — derived from steamId === "0".
kick(reason?: string): void
Disconnect this client.
chat(message: string): void
Send a chat (SayText2) line to this client.
print(message: string): void
Print one line to this client's developer console (skipped for bots).
readonly ip: string
This client's IP address (":port" stripped); "" for a bot.
kickWithReason(reason: string, delaySeconds?: number): void
Show reason (chat + console) once the client is in-game, then kick after delaySeconds (default 5). Intended to be called from a Clients.onConnect handler.
voiceMuted: boolean
Server-side voice mute: while true, this client's OUTGOING voice is silenced for every receiver. Framework state (not an engine field): cleared automatically on disconnect, persists across map changes while connected. If the voice descriptor is degraded (hook/validation failure — named reason in the server log), setting is an inert no-op and reads stay false.
command(cmd: string): boolean

Tell this client to run cmd in their own console, as if they had typed it (SourceMod ClientCommand). Requires a real client: a bot has no console, so this is a no-op on bots — use Client.fakeCommand for server-side execution. Returns false when the command was not dispatched (empty text, bad slot, or the engine interface is unavailable on this build), never a silent no-op.

client.command("play sounds/ui/beep.vsnd");
fakeCommand(cmd: string): boolean

Have the SERVER process cmd as if this client had sent it (SourceMod FakeClientCommand). Unlike Client.command this works on bots, because nothing is sent to a client — the engine dispatches the command itself, attributed to this player's slot. Live-verified: fakeCommand("say hi") on slot 0 prints as that player, not as Console. Returns false — never a silent no-op — for a bad slot, empty text, an unavailable interface, or a name that is not a registered console **command** (a ConVar such as mp_friendlyfire is refused: use Server.command for those). KNOWN LIMITATION: engine commands (say, kill, …) execute. A command registered by an s2script plugin is dispatched by the engine, but its JS handler will NOT run — the core holds the isolate borrow across all JS, so re-entering the dispatcher hits the documented re-entrancy skip. (This is not a permissions issue: every s2script command is registered client-executable, which is why a player can type it in their own console.) To invoke another plugin's behaviour, use a cross-plugin interface rather than faking its command. See docs/superpowers/specs/2026-07-25-client-command-design.md §12.

client.fakeCommand("say hello");   // as though the player typed it
const
Clients

Look up connected clients by slot or enumerate them all.

import { Clients } from "@s2script/sdk/clients";
console.log(`onLoad — all()=${Clients.all().length} clients`);
fromSlot(slot: number): Client | null
The client in slot, or null if the slot is empty.
all(): Client[]
Every currently-connected client (bots included).
Back to modules All packages

s2script — Source 2 plugin framework

GitHub