Modules

Docs / API / Modules / cookies

Cookies

Persistence

@s2script/sdk/cookies

SM-parity client preference cookies.

4 exports

Import

import { CookieAccess } from "@s2script/sdk/cookies";

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.

enum
CookieAccess

SM-parity access level carried as metadata on a Cookie definition (client cookie-menu visibility/editability).

Public
Visible and editable by the client in the cookie menu.
Protected
Visible to the client but not editable.
Private
Hidden from the client; plugin-only.
interface
Cookie

A registered cookie definition — the handle passed to Cookies.get/Cookies.set.

readonly name: string
Unique cookie name (the DB key).
readonly access: CookieAccess
Client visibility/editability, per CookieAccess.
readonly default: string
Value returned by Cookies.get when the client has no stored value.
interface
CookieOptions

Options for Cookies.register.

description?: string
Human-readable description (shown in a cookie menu).
access?: CookieAccess
Client visibility/editability.
default?: string
Fallback value when the client has no stored value.
const
Cookies

Entry point for registering and reading/writing client preference cookies.

register(name: string, opts?: CookieOptions): Cookie

Register (or return an existing) cookie definition. Idempotent per plugin context — the same name returns the already-registered Cookie.

import { Cookies } from "@s2script/sdk/cookies";
const boots = Cookies.register("demo_boots", { default: "0" });
const n = parseInt(Cookies.get(client, boots), 10);
get(client: Client, cookie: Cookie): string
Cache value for this client (a stored "" is a real value), else the cookie's default. Default for bots.
set(client: Client, cookie: Cookie, value: string): void
Write the cache + mark dirty (flushed to the DB on disconnect). No-op for bots.
areCached(client: Client): boolean
Has this client's cookies finished loading from the DB?
getTime(client: Client, cookie: Cookie): number
Unix timestamp of the cookie's last write (set or DB load), or 0 if never set. 0 for bots.
setAuthId(steamId: string, cookie: Cookie, value: string): void
Write a cookie for a SteamID64 that may not be connected right now (SetAuthIdCookie parity): updates the cache immediately (an online client sees it right away) and queues the write for the clientprefs plugin to persist directly next frame — an offline SteamID never fires the disconnect flush. No-op for "0" (bot/unset).
Back to modules All packages

s2script — Source 2 plugin framework

GitHub