@s2script/sdk 0.5.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE-APACHE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 Gabriel Hirakawa
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/LICENSE-MIT ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Gabriel Hirakawa
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,10 +1,44 @@
1
1
  # @s2script/sdk
2
2
 
3
- The **s2script SDK** — types + CLI for building [Source 2](https://developer.valvesoftware.com/wiki/Source_2) / CS2 plugins in TypeScript.
3
+ The **s2script SDK** — the TypeScript types and the `s2s` CLI for building
4
+ [Source 2](https://developer.valvesoftware.com/wiki/Source_2) / Counter-Strike 2 server plugins.
4
5
 
5
- > **`0.0.1` is a placeholder.** This release exists only to claim the package name and bootstrap npm OIDC trusted publishing. The real content lands in **`0.1.0`**:
6
- >
7
- > - Per-capability type subpaths — `import { Entity } from "@s2script/sdk/entity"`, `@s2script/sdk/math`, `@s2script/sdk/timers`, `@s2script/sdk/events`, … (the framework's standard library, consolidated from the former `@s2script/*` packages).
8
- > - The build CLI, exposed as the **`s2s`** command (`s2s build`; cold-start `npx @s2script/sdk build`).
6
+ s2script is a plugin framework for Source 2 games, loaded via
7
+ [Metamod:Source](https://www.sourcemm.net/). This package is what you develop against; the runtime
8
+ ships with the server addon.
9
9
 
10
- Game-specific schema/types ship separately in `@s2script/cs2` (and future `@s2script/<game>` packages).
10
+ ## Quickstart
11
+
12
+ ```bash
13
+ npx @s2script/sdk create my-plugin
14
+ cd my-plugin
15
+ npm run build # → dist/<id>.s2sp
16
+ ```
17
+
18
+ Copy the `.s2sp` into `addons/s2script/plugins/` on a running server and it loads immediately —
19
+ re-drop to hot-reload, delete to unload. No restart.
20
+
21
+ ```ts
22
+ import { plugin } from "@s2script/sdk/plugin";
23
+
24
+ export default plugin((ctx) => {
25
+ ctx.commands.register("hello", (cmd) => {
26
+ cmd.reply("hello from s2script");
27
+ });
28
+ });
29
+ ```
30
+
31
+ This package is **types-only** — the engine injects the implementation at load time, and
32
+ `s2s build` marks `@s2script/*` external rather than bundling it. Capabilities are imported as
33
+ per-capability subpaths (`@s2script/sdk/entity`, `@s2script/sdk/timers`, `@s2script/sdk/clients`, …);
34
+ game-specific schema types ship separately in
35
+ [`@s2script/cs2`](https://www.npmjs.com/package/@s2script/cs2).
36
+
37
+ ## Docs
38
+
39
+ **[s2script.com/docs](https://s2script.com/docs)** — getting started, guides, and the full API
40
+ reference. Source and issues: [GitHub](https://github.com/s2script/s2script).
41
+
42
+ ## License
43
+
44
+ MIT OR Apache-2.0
package/admin.d.ts CHANGED
@@ -7,26 +7,43 @@
7
7
 
8
8
  /** SourceMod-parity admin flag bitmask constants (SM bit values). */
9
9
  export declare const ADMFLAG: {
10
+ /** Reserved-slot access (`1<<0` = 1). */
10
11
  readonly RESERVATION: number;
12
+ /** Generic admin — the baseline "is an admin" flag (`1<<1` = 2). */
11
13
  readonly GENERIC: number;
14
+ /** May kick players (`1<<2` = 4). */
12
15
  readonly KICK: number;
16
+ /** May ban players (`1<<3` = 8). */
13
17
  readonly BAN: number;
18
+ /** May remove bans (`1<<4` = 16). */
14
19
  readonly UNBAN: number;
20
+ /** May slay/slap players (`1<<5` = 32). */
15
21
  readonly SLAY: number;
22
+ /** May change the map (`1<<6` = 64). */
16
23
  readonly CHANGEMAP: number;
24
+ /** May change most convars (`1<<7` = 128). */
17
25
  readonly CONVARS: number;
26
+ /** May execute config files (`1<<8` = 256). */
18
27
  readonly CONFIG: number;
28
+ /** Admin-chat and other special chat privileges (`1<<9` = 512). */
19
29
  readonly CHAT: number;
30
+ /** May start votes (`1<<10` = 1024). */
20
31
  readonly VOTE: number;
32
+ /** May set the server password (`1<<11` = 2048). */
21
33
  readonly PASSWORD: number;
34
+ /** May use rcon commands (`1<<12` = 4096). */
22
35
  readonly RCON: number;
36
+ /** May change cheat convars and use cheat commands (`1<<13` = 8192). */
23
37
  readonly CHEATS: number;
38
+ /** Full access — implicitly satisfies every flag (`1<<14` = 16384). See {@link AdminInfo.hasFlags}. */
24
39
  readonly ROOT: number;
25
40
  };
26
41
 
27
42
  /** An admin entry: their SteamID64, their combined flag mask, and a helper to check flags. */
28
43
  export interface AdminInfo {
44
+ /** This admin's SteamID64 (decimal string). */
29
45
  readonly steamId: string;
46
+ /** Combined flag mask (union of file + runtime tiers and group flags) — test against {@link ADMFLAG} bits. */
30
47
  readonly flags: number;
31
48
  /** Immunity level (0 = none). A lower-immunity admin cannot target a higher one. */
32
49
  readonly immunity: number;
@@ -38,13 +55,23 @@ export interface AdminInfo {
38
55
 
39
56
  /** A resolved admin group (from admin_groups.json): its flags, immunity, and per-command overrides. */
40
57
  export interface AdminGroup {
58
+ /** The group's name (its key in admin_groups.json). */
41
59
  readonly name: string;
60
+ /** Flag mask granted to every member — {@link ADMFLAG} bits. */
42
61
  readonly flags: number;
62
+ /** Immunity level conferred by membership (0 = none). */
43
63
  readonly immunity: number;
64
+ /** Per-command access overrides, keyed by command name: `public` opens it to all, `mask` is the required flags. */
44
65
  readonly overrides: Readonly<Record<string, { public: boolean; mask: number }>>;
45
66
  }
46
67
 
47
- /** The admin API: add/remove runtime admins, look up by SteamID or slot, reload from file. */
68
+ /**
69
+ * The admin API: add/remove runtime admins, look up by SteamID or slot, reload from file.
70
+ * @example
71
+ * import { Admin, ADMFLAG } from "@s2script/sdk/admin";
72
+ * const a = Admin.forSlot(p.slot);
73
+ * const adminStr = a ? "yes(flags=0x" + a.flags.toString(16) + ")" : "no";
74
+ */
48
75
  export declare const Admin: {
49
76
  /** Add (or overwrite) a runtime admin. Not persisted to admins.json. */
50
77
  add(steamId: string, flags: number, immunity?: number): void;
package/bans.d.ts CHANGED
@@ -29,7 +29,14 @@ export interface BanEntry {
29
29
  reason: string;
30
30
  }
31
31
 
32
- /** The ban API: add/remove bans, look up by SteamID64, list, and reload from bans.json. */
32
+ /**
33
+ * The ban API: add/remove bans, look up by SteamID64, list, and reload from bans.json.
34
+ * @example
35
+ * import { Bans } from "@s2script/sdk/bans";
36
+ * // Connect-time enforcement inside a Clients.onConnect handler.
37
+ * const b = Bans.get(c.steamId);
38
+ * if (b && (b.until === 0 || b.until > Date.now() / 1000)) c.kickWithReason(b.reason);
39
+ */
33
40
  export declare const Bans: {
34
41
  /** Add (or overwrite) a ban and persist it to bans.json. `minutes <= 0` = permanent. */
35
42
  add(steamId: string, minutes: number, reason?: string): void;
package/chat.d.ts CHANGED
@@ -1,5 +1,12 @@
1
1
  /** @s2script/chat — print messages to player chat. NO runtime code (injected at load). */
2
2
 
3
+ /**
4
+ * Print messages to player chat (SayText2), with a caller-owned {@link Chat.color} prefix.
5
+ * @example
6
+ * import { Chat } from "@s2script/sdk/chat";
7
+ * Chat.toAll("[Vote] Result: " + winner);
8
+ * Chat.toSlot(slot, "Usage: @@<target> <message>");
9
+ */
3
10
  export declare const Chat: {
4
11
  /**
5
12
  * An opaque prefix prepended to every chat message (NOT rcon/console replies). Color is content the
package/clients.d.ts CHANGED
@@ -2,8 +2,10 @@
2
2
  * @s2script/clients — engine-generic client handle + lifecycle events.
3
3
  * Resolved at runtime via globalThis.__s2pkg_clients. Import: import { Client, Clients } from "./clients";
4
4
  */
5
+
5
6
  /** A connected client, identified by its 0-based slot (CPlayerSlot). Slot-backed; getters read live. */
6
7
  export declare class Client {
8
+ /** The client's 0-based engine slot (`CPlayerSlot`) — the handle's stable identity for its connection. */
7
9
  readonly slot: number;
8
10
  /** True while a client occupies this slot. */
9
11
  isValid(): boolean;
@@ -35,9 +37,15 @@ export declare class Client {
35
37
  */
36
38
  voiceMuted: boolean;
37
39
  }
40
+ /**
41
+ * Look up connected clients by slot or enumerate them all.
42
+ * @example
43
+ * import { Clients } from "@s2script/sdk/clients";
44
+ * console.log(`onLoad — all()=${Clients.all().length} clients`);
45
+ */
38
46
  export declare const Clients: {
39
47
  /** The client in `slot`, or null if the slot is empty. */
40
48
  fromSlot(slot: number): Client | null;
41
- /** Every currently-connected client. */
49
+ /** Every currently-connected client (bots included). */
42
50
  all(): Client[];
43
51
  };
package/commands.d.ts CHANGED
@@ -1,7 +1,25 @@
1
1
  /** @s2script/commands — register server commands. NO runtime code (injected at load). */
2
+
3
+ /**
4
+ * Where a command was invoked from — SourceMod's *reply source*. Set by the dispatch path and
5
+ * exposed as {@link CommandInvocation.replySource}; it is what {@link CommandInvocation.reply}
6
+ * routes on.
7
+ *
8
+ * - `"server"` — the server console or rcon (`callerSlot` is `-1`)
9
+ * - `"console"` — a player's own developer console
10
+ * - `"chat"` — a `!` or `/` chat trigger
11
+ */
12
+ export type ReplySource = "server" | "console" | "chat";
13
+
14
+ /**
15
+ * The parsed invocation handed to a command callback: who called it, its arguments (multiple typed
16
+ * accessors), and a caller-appropriate `reply` channel. Valid only for the duration of the callback.
17
+ */
2
18
  export interface CommandInvocation {
3
19
  /** 0-based caller slot, or -1 for the server console. */
4
20
  readonly callerSlot: number;
21
+ /** Where this invocation came from — what {@link CommandInvocation.reply} routes on. */
22
+ readonly replySource: ReplySource;
5
23
  /** argString split on whitespace (0-based; the command name is NOT included). Kept for compat. */
6
24
  readonly args: string[];
7
25
  /** everything after the command name (raw) — SM `GetCmdArgString`. */
@@ -16,8 +34,33 @@ export interface CommandInvocation {
16
34
  argFloat(n: number, fallback?: number): number;
17
35
  /** every argument from index `n` onward, re-joined with a single space (a reason/message/value that spans spaces). */
18
36
  argsFrom(n: number): string;
19
- /** reply to the caller: server console → server print; a player → their chat. */
37
+ /**
38
+ * Reply to the caller in the channel they used — SourceMod's `ReplyToCommand`. Routed by
39
+ * {@link CommandInvocation.replySource}: `"server"` → the server console, `"console"` → the
40
+ * caller's own developer console (both control-bytes-stripped), `"chat"` → their chat, one frame later.
41
+ *
42
+ * `Chat.color`'s global prefix applies to the chat path only and never decorates a console reply.
43
+ * To pin a channel regardless of how the command was invoked, use {@link
44
+ * CommandInvocation.replyToChat} or {@link CommandInvocation.replyToConsole}.
45
+ *
46
+ * @example
47
+ * // `!help` answers in chat; `sm_help` typed at a console answers in that console.
48
+ * ctx.commands.register("sm_help", (cmd) => cmd.reply("[SM] Commands: …"));
49
+ */
20
50
  reply(message: string): void;
51
+ /**
52
+ * Force the reply into the caller's chat, whichever channel they actually used — SM `PrintToChat`.
53
+ * Sent raw (colour is content you own) and deferred one frame, so a `!cmd` answer lands *after*
54
+ * the player's own chat line rather than above it. The server console (`callerSlot` `-1`) has no
55
+ * chat channel and degrades to the server console.
56
+ */
57
+ replyToChat(message: string): void;
58
+ /**
59
+ * Force the reply into the caller's developer console — SM `PrintToConsole`. Control bytes are
60
+ * stripped (a chat colour *is* a control byte, and renders as garbage in a console), and the line
61
+ * is printed immediately. The server console (`callerSlot` `-1`) prints to the server console.
62
+ */
63
+ replyToConsole(message: string): void;
21
64
  /** reply to the caller, translated for THEIR language (SM's `%t` on the reply path). Soft-deps
22
65
  * `@s2script/translations` — degrades to the raw `key` if it isn't loaded. */
23
66
  replyT(key: string, ...args: (string | number)[]): void;
@@ -32,13 +75,31 @@ export interface ChatTrigger {
32
75
  readonly argString: string;
33
76
  }
34
77
 
78
+ /**
79
+ * Command-registry utilities: dispatch by name, parse/route chat triggers, and enumerate the global
80
+ * registry. Commands themselves are registered through the plugin context (`ctx.commands.register*`).
81
+ * @example
82
+ * import { Commands } from "@s2script/sdk/commands";
83
+ * // sm_help backend: every registered command + its required admin flag mask.
84
+ * const cmds = Commands.list().slice().sort((a, b) => (a.name < b.name ? -1 : 1));
85
+ */
35
86
  export declare const Commands: {
36
- /** Invoke a registered command by name in THIS plugin (applying its gating). Returns true if it exists. */
37
- dispatch(name: string, slot: number, argString: string): boolean;
87
+ /**
88
+ * Invoke a registered command by name in THIS plugin (applying its gating). Returns true if it
89
+ * exists.
90
+ *
91
+ * `replySource` sets where the command's {@link CommandInvocation.reply} lands. Omit it and it
92
+ * falls back to the slot — the server console at `-1`, else that player's own console, matching
93
+ * SourceMod's `FakeClientCommand`. Pass `"chat"` when re-dispatching on a player's behalf from a
94
+ * chat context.
95
+ */
96
+ dispatch(name: string, slot: number, argString: string, replySource?: ReplySource): boolean;
38
97
  /** Parse a chat message for a trigger (`!`/`/`). Returns the parsed trigger, or null if it's ordinary chat. */
39
98
  parseChatTrigger(message: string): ChatTrigger | null;
40
99
  /** If `message` is a trigger, dispatch the command (tries `name` then `sm_<name>`) as `slot`; returns
41
- * `{ silent, ran }` (the caller should suppress the chat message), or null if it was ordinary chat. */
100
+ * `{ silent, ran }` (the caller should suppress the chat message), or null if it was ordinary chat.
101
+ * Always dispatches with `replySource` `"chat"` — including the silent `/` trigger, where `silent`
102
+ * suppresses the player's own line but the answer still belongs in chat. */
42
103
  handleChatTrigger(slot: number, message: string): { silent: boolean; ran: boolean } | null;
43
104
  /** The trigger characters — SM PublicChatTrigger (`"!"`) / SilentChatTrigger (`"/"`). Mutate to reconfigure. */
44
105
  readonly triggers: { public: string; silent: string };
package/config.d.ts CHANGED
@@ -1,11 +1,23 @@
1
1
  /** @s2script/config — typed access to the plugin's materialized config. NO runtime code. */
2
2
  /** A materialized config value: a scalar, or a nested section object of further values. */
3
3
  export type ConfigValue = string | number | boolean | { [k: string]: ConfigValue };
4
+ /** The whole materialized config: top-level keys to {@link ConfigValue}s. Passed to `ctx.config.onChange`. */
4
5
  export type Config = Record<string, ConfigValue>;
6
+ /**
7
+ * Typed access to this plugin's materialized config values (declared under `s2script.config` in the manifest).
8
+ * @example
9
+ * import { config } from "@s2script/sdk/config";
10
+ * // plugins/antiflood/src/plugin.ts:31 — re-read on live-reload
11
+ * const maxTokens = config.getInt("max_tokens");
12
+ */
5
13
  export declare const config: {
14
+ /** A config value as a string. `""` if the key is absent. */
6
15
  getString(key: string): string;
16
+ /** A config value as an integer. `0` if the key is absent or non-numeric. */
7
17
  getInt(key: string): number;
18
+ /** A config value as a float. `0` if the key is absent or non-numeric. */
8
19
  getFloat(key: string): number;
20
+ /** A config value as a boolean. `false` if the key is absent. */
9
21
  getBool(key: string): boolean;
10
22
  /** Read a raw file from the configs dir (name includes its extension, e.g. "maplist.txt"). null if absent. */
11
23
  readFile(name: string): string | null;
package/console.d.ts CHANGED
@@ -5,8 +5,17 @@
5
5
 
6
6
  /** Engine-provided console (log/error/warn/info). Also available as the global `console`. */
7
7
  export declare const console: {
8
+ /**
9
+ * Write a line to the server console (and the log). Arguments are stringified and space-joined.
10
+ * @example
11
+ * import { console } from "@s2script/sdk/console";
12
+ * console.log("[antiflood] onLoad — chat flood protection active");
13
+ */
8
14
  log(...data: any[]): void;
15
+ /** Write a line at error severity. */
9
16
  error(...data: any[]): void;
17
+ /** Write a line at warning severity. */
10
18
  warn(...data: any[]): void;
19
+ /** Write a line at info severity. */
11
20
  info(...data: any[]): void;
12
21
  };
package/cookies.d.ts CHANGED
@@ -1,10 +1,43 @@
1
1
  /** @s2script/cookies — SM-parity client preference cookies. NO runtime code (injected as __s2pkg_cookies). */
2
2
  import type { Client } from "./clients";
3
- export enum CookieAccess { Public, Protected, Private }
4
- export interface Cookie { readonly name: string; readonly access: CookieAccess; readonly default: string; }
5
- export interface CookieOptions { description?: string; access?: CookieAccess; default?: string; }
3
+
4
+ /** SM-parity access level carried as metadata on a {@link Cookie} definition (client cookie-menu visibility/editability). */
5
+ export enum CookieAccess {
6
+ /** Visible and editable by the client in the cookie menu. */
7
+ Public,
8
+ /** Visible to the client but not editable. */
9
+ Protected,
10
+ /** Hidden from the client; plugin-only. */
11
+ Private,
12
+ }
13
+ /** A registered cookie definition — the handle passed to {@link Cookies.get}/{@link Cookies.set}. */
14
+ export interface Cookie {
15
+ /** Unique cookie name (the DB key). */
16
+ readonly name: string;
17
+ /** Client visibility/editability, per {@link CookieAccess}. */
18
+ readonly access: CookieAccess;
19
+ /** Value returned by {@link Cookies.get} when the client has no stored value. */
20
+ readonly default: string;
21
+ }
22
+ /** Options for {@link Cookies.register}. */
23
+ export interface CookieOptions {
24
+ /** Human-readable description (shown in a cookie menu). */
25
+ description?: string;
26
+ /** Client visibility/editability. @defaultValue {@link CookieAccess.Public} */
27
+ access?: CookieAccess;
28
+ /** Fallback value when the client has no stored value. @defaultValue `""` */
29
+ default?: string;
30
+ }
31
+ /** Entry point for registering and reading/writing client preference cookies. */
6
32
  export declare const Cookies: {
7
- /** Register (or return an existing) cookie definition. */
33
+ /**
34
+ * Register (or return an existing) cookie definition. Idempotent per plugin context — the same name
35
+ * returns the already-registered {@link Cookie}.
36
+ * @example
37
+ * import { Cookies } from "@s2script/sdk/cookies";
38
+ * const boots = Cookies.register("demo_boots", { default: "0" });
39
+ * const n = parseInt(Cookies.get(client, boots), 10);
40
+ */
8
41
  register(name: string, opts?: CookieOptions): Cookie;
9
42
  /** Cache value for this client (a stored "" is a real value), else the cookie's default. Default for bots. */
10
43
  get(client: Client, cookie: Cookie): string;
package/damage.d.ts CHANGED
@@ -4,7 +4,13 @@
4
4
  */
5
5
  import type { EntityRef } from "./entity";
6
6
 
7
- /** A block-scoped view of the current damage event (valid only inside a Damage.onPre handler). */
7
+ /**
8
+ * A block-scoped view of the current damage event (valid only inside a Damage.onPre handler).
9
+ * @example
10
+ * import type { DamageInfo } from "@s2script/sdk/damage";
11
+ * // plugins/basecommands/src/plugin.ts:81 — halve the damage (assign 0 to block it entirely)
12
+ * ctx.entities.onDamage((info: DamageInfo) => { info.damage = info.damage / 2; });
13
+ */
8
14
  export interface DamageInfo {
9
15
  /** The damage amount (m_flDamage). Assigning MODIFIES the live damage; set to 0 to block. */
10
16
  damage: number;