Search docs
Search guides, modules and symbols
Modules

Docs / API / Modules / clients

Clients

Players & world

@s2script/sdk/clients

A Client is a handle to one connection lifetime. Reusing a slot never revives a saved handle. Disconnect callbacks expose a synchronous identity snapshot; stale getters and actions return safe defaults.

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 handle to one connection lifetime. Reusing a slot, even for the same SteamID, never revives it. Stale handles return "0" for steamId, "" for name/ip, -1 for userId/signonState, false for booleans; void actions do nothing and command actions return false. OnClientDisconnect receives a read-only identity snapshot during its synchronous callback; isValid() is already false. Capture identity before awaiting; afterward stale defaults apply.

readonly slot: number
— The client's 0-based engine slot (CPlayerSlot) — not sufficient by itself to identify a connection.
isValid(): boolean
— True while this exact connection occupies the 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 for a stale handle.
readonly isBot: boolean
— True for a fake client (bot) — false for stale handles.
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). Engine commands (say, kill, …) execute. A command registered by an s2script plugin runs that plugin's JS handler before this returns.

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