@sagl/server 0.0.0-stage → 0.1.0-next.49

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.
Files changed (129) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +61 -2
  3. package/dist/actions.d.ts +46 -0
  4. package/dist/actions.js +80 -0
  5. package/dist/actions.js.map +1 -0
  6. package/dist/animations.d.ts +32 -0
  7. package/dist/animations.js +95 -0
  8. package/dist/animations.js.map +1 -0
  9. package/dist/audio.d.ts +180 -0
  10. package/dist/audio.js +353 -0
  11. package/dist/audio.js.map +1 -0
  12. package/dist/audio_effects.d.ts +219 -0
  13. package/dist/audio_effects.js +84 -0
  14. package/dist/audio_effects.js.map +1 -0
  15. package/dist/camera.d.ts +188 -0
  16. package/dist/camera.js +247 -0
  17. package/dist/camera.js.map +1 -0
  18. package/dist/claims.d.ts +27 -0
  19. package/dist/claims.js +48 -0
  20. package/dist/claims.js.map +1 -0
  21. package/dist/commands.d.ts +135 -0
  22. package/dist/commands.js +373 -0
  23. package/dist/commands.js.map +1 -0
  24. package/dist/console.d.ts +21 -0
  25. package/dist/console.js +100 -0
  26. package/dist/console.js.map +1 -0
  27. package/dist/constants.d.ts +654 -0
  28. package/dist/constants.js +657 -0
  29. package/dist/constants.js.map +1 -0
  30. package/dist/cutscene.d.ts +47 -0
  31. package/dist/cutscene.js +190 -0
  32. package/dist/cutscene.js.map +1 -0
  33. package/dist/draw.d.ts +106 -0
  34. package/dist/draw.js +132 -0
  35. package/dist/draw.js.map +1 -0
  36. package/dist/effects.d.ts +91 -0
  37. package/dist/effects.js +116 -0
  38. package/dist/effects.js.map +1 -0
  39. package/dist/gangzones.d.ts +47 -0
  40. package/dist/gangzones.js +122 -0
  41. package/dist/gangzones.js.map +1 -0
  42. package/dist/geo.d.ts +11 -0
  43. package/dist/geo.js +25 -0
  44. package/dist/geo.js.map +1 -0
  45. package/dist/hud.d.ts +159 -0
  46. package/dist/hud.js +247 -0
  47. package/dist/hud.js.map +1 -0
  48. package/dist/index.d.ts +40 -0
  49. package/dist/index.js +43 -0
  50. package/dist/index.js.map +1 -0
  51. package/dist/interaction.d.ts +81 -0
  52. package/dist/interaction.js +143 -0
  53. package/dist/interaction.js.map +1 -0
  54. package/dist/junctions.d.ts +1 -0
  55. package/dist/junctions.js +330 -0
  56. package/dist/junctions.js.map +1 -0
  57. package/dist/map.d.ts +55 -0
  58. package/dist/map.js +71 -0
  59. package/dist/map.js.map +1 -0
  60. package/dist/menu.d.ts +96 -0
  61. package/dist/menu.js +129 -0
  62. package/dist/menu.js.map +1 -0
  63. package/dist/mission.d.ts +482 -0
  64. package/dist/mission.js +1258 -0
  65. package/dist/mission.js.map +1 -0
  66. package/dist/models.d.ts +56 -0
  67. package/dist/models.js +71 -0
  68. package/dist/models.js.map +1 -0
  69. package/dist/modshop.d.ts +229 -0
  70. package/dist/modshop.js +904 -0
  71. package/dist/modshop.js.map +1 -0
  72. package/dist/modshop_data.d.ts +44 -0
  73. package/dist/modshop_data.js +287 -0
  74. package/dist/modshop_data.js.map +1 -0
  75. package/dist/native.d.ts +809 -0
  76. package/dist/native.js +27 -0
  77. package/dist/native.js.map +1 -0
  78. package/dist/objects.d.ts +249 -0
  79. package/dist/objects.js +455 -0
  80. package/dist/objects.js.map +1 -0
  81. package/dist/paint.d.ts +124 -0
  82. package/dist/paint.js +84 -0
  83. package/dist/paint.js.map +1 -0
  84. package/dist/paynspray.d.ts +44 -0
  85. package/dist/paynspray.js +177 -0
  86. package/dist/paynspray.js.map +1 -0
  87. package/dist/ped.d.ts +335 -0
  88. package/dist/ped.js +536 -0
  89. package/dist/ped.js.map +1 -0
  90. package/dist/player.d.ts +685 -0
  91. package/dist/player.js +1163 -0
  92. package/dist/player.js.map +1 -0
  93. package/dist/screeneffects.d.ts +99 -0
  94. package/dist/screeneffects.js +257 -0
  95. package/dist/screeneffects.js.map +1 -0
  96. package/dist/scripts.d.ts +69 -0
  97. package/dist/scripts.js +125 -0
  98. package/dist/scripts.js.map +1 -0
  99. package/dist/server.d.ts +713 -0
  100. package/dist/server.js +1080 -0
  101. package/dist/server.js.map +1 -0
  102. package/dist/shopblips.d.ts +9 -0
  103. package/dist/shopblips.js +30 -0
  104. package/dist/shopblips.js.map +1 -0
  105. package/dist/special.d.ts +33 -0
  106. package/dist/special.js +26 -0
  107. package/dist/special.js.map +1 -0
  108. package/dist/splash.d.ts +42 -0
  109. package/dist/splash.js +55 -0
  110. package/dist/splash.js.map +1 -0
  111. package/dist/text.d.ts +19 -0
  112. package/dist/text.js +25 -0
  113. package/dist/text.js.map +1 -0
  114. package/dist/ui.d.ts +141 -0
  115. package/dist/ui.js +243 -0
  116. package/dist/ui.js.map +1 -0
  117. package/dist/vehicle.d.ts +306 -0
  118. package/dist/vehicle.js +612 -0
  119. package/dist/vehicle.js.map +1 -0
  120. package/dist/vehiclecolors.d.ts +26 -0
  121. package/dist/vehiclecolors.js +49 -0
  122. package/dist/vehiclecolors.js.map +1 -0
  123. package/dist/world.d.ts +222 -0
  124. package/dist/world.js +227 -0
  125. package/dist/world.js.map +1 -0
  126. package/dist/zone.d.ts +89 -0
  127. package/dist/zone.js +140 -0
  128. package/dist/zone.js.map +1 -0
  129. package/package.json +33 -4
@@ -0,0 +1,713 @@
1
+ import { type WeaponViolationReason } from "./native.js";
2
+ import { Player, type Vector3 } from "./player.js";
3
+ import { Vehicle } from "./vehicle.js";
4
+ import { Ped, type PedSettings } from "./ped.js";
5
+ import { Garage, Zone } from "./zone.js";
6
+ import { Actions } from "./actions.js";
7
+ import { CullZone, World, type Population, type TrafficLights } from "./world.js";
8
+ import { Console } from "./console.js";
9
+ import { GameMap, type MapColor } from "./map.js";
10
+ import { GangZone, type GangZoneArea } from "./gangzones.js";
11
+ import { ServerDraw } from "./draw.js";
12
+ import { Missions, type MissionEvent } from "./mission.js";
13
+ import { PayNSpray } from "./paynspray.js";
14
+ import type { Livery, PaintFinish } from "./paint.js";
15
+ import { ScreenEffects } from "./screeneffects.js";
16
+ import { VehicleColors } from "./vehiclecolors.js";
17
+ import { ModShops } from "./modshop.js";
18
+ import { CutscenePlay, type CutsceneOptions } from "./cutscene.js";
19
+ import { Interactions } from "./interaction.js";
20
+ import { ServerAudio } from "./audio.js";
21
+ import { ServerEffects } from "./effects.js";
22
+ import { Claims } from "./claims.js";
23
+ import { Commands } from "./commands.js";
24
+ /** How chat lines go out (`server.chat`). */
25
+ export interface ChatOptions {
26
+ /** A line as everyone sees it. Default: "Name: text", the name in `player.color`. `{RRGGBB}` colours a part. */
27
+ format: (player: Player, text: string) => string;
28
+ /** The flood limit: a burst of this many lines... */
29
+ floodLines: number;
30
+ /** ...then this many a second. */
31
+ floodPerSecond: number;
32
+ }
33
+ import { ServerAnimations } from "./animations.js";
34
+ import { ServerModels } from "./models.js";
35
+ import { type GameObject, type Pickup, type Label, type LabelTarget, type LabelOptions, type ObjectOptions, type PickupOptions, type Rotation } from "./objects.js";
36
+ import { Channel, ClientScripts, type ChannelData, type ClientScriptError } from "./scripts.js";
37
+ /** How name tags show: see `server.nameTags`. */
38
+ export interface NameTagOptions {
39
+ distance?: number;
40
+ lineOfSight?: boolean;
41
+ ids?: boolean;
42
+ bars?: boolean;
43
+ }
44
+ export interface ServerOptions {
45
+ /** UDP port. Default 7777. */
46
+ port?: number;
47
+ /** Shown to players when they join. */
48
+ name?: string;
49
+ /** Player slots. Default 32. */
50
+ maxPlayers?: number;
51
+ /** Money each player starts with. Default 0. */
52
+ startMoney?: number;
53
+ /**
54
+ * Players walk and run like their skin (true) or like CJ (false, the
55
+ * default); holding a gun, like CJ either way. `player.skinAnimations`
56
+ * changes it per player.
57
+ */
58
+ skinAnimations?: boolean;
59
+ /**
60
+ * The game's own entrances (yellow door markers into its interiors)
61
+ * work. Default true. Off, only the server puts players in interiors
62
+ * (`player.interior`), as SA-MP's DisableInteriorEnterExits. On, a player
63
+ * walking through one fires `playerInterior`.
64
+ */
65
+ gameEntrances?: boolean;
66
+ /**
67
+ * Players' loading screen stays up after they join, as a splash screen
68
+ * (their game's sound muted), until you hide it (`player.splash.hide()`):
69
+ * set the scene behind it first (where they are, the camera, the HUD).
70
+ * `timeoutMs` (default 30000) hides it anyway if you haven't, with a
71
+ * warning. Default off: it goes as they spawn.
72
+ */
73
+ splash?: boolean | {
74
+ timeoutMs?: number;
75
+ };
76
+ /**
77
+ * Players can pull each other out of vehicles, as SA-MP's (and the
78
+ * game's): `playerCarjack` hears it. Default true.
79
+ */
80
+ carjacking?: boolean;
81
+ /**
82
+ * Vehicles' indicators: `keys` gives drivers theirs (`,` left, `.` right,
83
+ * `;` hazards by default, rebound in Settings, Controls; default true), `autoCancel` turns them off after the turn
84
+ * as a real stalk does (default true), `sound` is the driver's tick: a
85
+ * client file, or false for none (default: the built-in one).
86
+ * `vehicle.indicators` sets them whatever this says.
87
+ */
88
+ indicators?: {
89
+ keys?: boolean;
90
+ autoCancel?: boolean;
91
+ sound?: string | false;
92
+ };
93
+ /** World 0's weather (`Weather`), default `Weather.SunnyLA`. */
94
+ weather?: number;
95
+ /** In-game time at startup. Default 12:00, frozen. */
96
+ time?: {
97
+ hour: number;
98
+ minute: number;
99
+ frozen?: boolean;
100
+ };
101
+ /**
102
+ * Proxy mode: players may only connect through these proxies (IP
103
+ * addresses), and the player IP each proxy forwards is trusted. Leave out
104
+ * for players connecting directly.
105
+ */
106
+ trustedProxies?: string[];
107
+ /** How often the network is serviced, in ms. Default 5. */
108
+ tickMs?: number;
109
+ /**
110
+ * A directory whose files players download when they join (behind a
111
+ * loading screen) and keep: rejoining, they fetch only what changed, and
112
+ * delete what's gone. Client scripts, map overlays and script UI can use
113
+ * them by path (`"ui/shop.rml"`), so they aren't sent again and again.
114
+ * Paths: letters, digits, `. _ -` and `/`; files up to 64 MB.
115
+ */
116
+ clientFiles?: string;
117
+ /** How the server looks to joining players: see `Branding`. */
118
+ branding?: Branding;
119
+ }
120
+ /**
121
+ * The server's look, sent to players first thing as they join: the loading
122
+ * screen shows the logo (while the other client files download) and the
123
+ * server's name, and SAGL's menus take the colours.
124
+ */
125
+ export interface Branding {
126
+ /**
127
+ * A client file (see `clientFiles`): a square PNG or JPEG of up to 1 MB,
128
+ * e.g. `"branding/logo.png"` (256x256 is plenty).
129
+ */
130
+ logo?: string;
131
+ /** A client file shown behind the loading screen (PNG or JPG), covering it. */
132
+ background?: string;
133
+ /**
134
+ * The loading screen shows the server's name beside the logo. Default
135
+ * false: the logo stands in for the name.
136
+ */
137
+ showName?: boolean;
138
+ /** Replaces the light blue of menu items, headings and bars: `"#RRGGBB"` or 0xRRGGBBAA. */
139
+ primary?: MapColor;
140
+ /** Replaces the dark blue behind focused items and slider tracks. */
141
+ secondary?: MapColor;
142
+ }
143
+ export type QuitReason = "quit" | "timeout" | "kicked";
144
+ export interface VehicleOptions {
145
+ /** From the game's palette (0-126); random if left out. */
146
+ colors?: [number, number];
147
+ /**
148
+ * Radio station (`RadioStation`). Left out, the first person in it gets
149
+ * what the game picks for that model (K-Rose in a country pickup, ...).
150
+ */
151
+ radio?: number;
152
+ /** Virtual world. Default 0. */
153
+ world?: number;
154
+ /**
155
+ * Treated as traffic: removed when no player is near (or a while after it
156
+ * is wrecked), unless it is someone's last car, and faded in and out.
157
+ */
158
+ ambient?: boolean;
159
+ /**
160
+ * Seconds after it is wrecked, or left empty away from where it was
161
+ * created, that it is put back there new (`vehicleRespawn`), once nobody
162
+ * is near enough to see. Left out: never (destroy it yourself).
163
+ */
164
+ respawnDelay?: number;
165
+ /**
166
+ * Licence plate: up to 8 of A-Z, 0-9 and spaces. Left out: a random one,
167
+ * as the game makes them (the same for everyone).
168
+ */
169
+ plate?: string;
170
+ }
171
+ /** Ambient population a player's game proposed (`populationSpawn`). */
172
+ export interface AmbientSpawn {
173
+ /** The vehicle model, or null for a ped on foot. */
174
+ vehicle: number | null;
175
+ position: Vector3;
176
+ /** Degrees. */
177
+ heading: number;
178
+ /** The ped on foot, or the vehicle's occupants (seat 0 driver). pedType is ePedType. */
179
+ peds: {
180
+ model: number;
181
+ pedType: number;
182
+ weapon: number;
183
+ seat: number;
184
+ }[];
185
+ }
186
+ export interface PedOptions {
187
+ /** Virtual world. Default 0. */
188
+ world?: number;
189
+ /** `Weapon` in its hand. Default unarmed. */
190
+ weapon?: number;
191
+ /** Default 100. */
192
+ health?: number;
193
+ /**
194
+ * What it does when nothing is happening: "stand" (the default) where it
195
+ * was created, or "wander" around. Either way it reacts to what happens
196
+ * around it as any ped would.
197
+ */
198
+ behaviour?: "stand" | "wander";
199
+ /**
200
+ * A mission character: `PedSettings`, starting from `{ reactions:
201
+ * "self-defence", keepTask: true }` (it ignores gunfire and keeps to its
202
+ * orders, but fights back). Left out: it behaves as the game's peds of its
203
+ * kind. `ped.set()` changes them later.
204
+ */
205
+ mission?: PedSettings | true;
206
+ /** Who sees it: see `ped.visibleTo`. Default `"world"`. */
207
+ visibleTo?: readonly Player[] | "world";
208
+ /** Whose game runs it: see `ped.controller`. Default: the nearest player's. */
209
+ controller?: Player;
210
+ }
211
+ /**
212
+ * Something that hit a vehicle: it crashed into something, or a weapon hit
213
+ * it. Reported by the game simulating the vehicle (its driver's, or a
214
+ * nearby player's for an empty one).
215
+ */
216
+ export interface VehicleHit {
217
+ /** `"collision"`: it crashed into something (or something into it). `"weapon"`: bullets, fire, explosions. */
218
+ cause: "collision" | "weapon";
219
+ /**
220
+ * What it hit, or what hit it: `"vehicle"`, `"ped"` (a player or a ped),
221
+ * `"object"` (doors, fences, lamp posts...), `"world"` (walls, buildings),
222
+ * `"ground"` (only when landing did harm); null for a weapon with no owner.
223
+ */
224
+ with: "world" | "ground" | "vehicle" | "ped" | "object" | null;
225
+ /** `Weapon`, or 49 (rammed) for a crash. */
226
+ weapon: number;
227
+ /** The other vehicle, if it was one of the server's. */
228
+ vehicle: Vehicle | null;
229
+ /** The player involved: the one it hit, the other vehicle's driver, or the shooter. */
230
+ player: Player | null;
231
+ /** The server ped involved, the same way. */
232
+ ped: Ped | null;
233
+ /** Its health before the hit. */
234
+ healthBefore: number;
235
+ /** Its health after (the same if the hit did no harm). */
236
+ health: number;
237
+ /** What the hit cost in health. */
238
+ loss: number;
239
+ /** How hard: the game's measure of a crash's impact, or a weapon's damage. */
240
+ intensity: number;
241
+ position: Vector3;
242
+ }
243
+ /** A shot a player fired, as checked by the server. */
244
+ export interface Shot {
245
+ /** `Weapon`. */
246
+ weapon: number;
247
+ /** Muzzle and aim point. */
248
+ origin: Vector3;
249
+ target: Vector3;
250
+ }
251
+ /** An explosion a player caused, matched to something they threw or fired. */
252
+ export interface Explosion {
253
+ /** eExplosionType: 0 grenade, 1 molotov, 2 rocket, 4 car, ... */
254
+ type: number;
255
+ /** The `Weapon` whose projectile went off; 0 for a vehicle they wrecked. */
256
+ weapon: number;
257
+ /** The vehicle that blew up, if it was one of the server's. */
258
+ vehicle: Vehicle | null;
259
+ position: Vector3;
260
+ }
261
+ /** A hit the server has validated, before it is applied. */
262
+ export interface Hit {
263
+ /** eWeaponType: 0 unarmed, 22 pistol, 31 M4, ... */
264
+ weapon: number;
265
+ /** ePedPieceTypes: 3 torso, 4 groin, 5/6 arms, 7/8 legs, 9 head. */
266
+ bodyPart: number;
267
+ /** Damage before the victim's armour is applied. */
268
+ damage: number;
269
+ /** Side of the victim that was hit, 0-3. */
270
+ direction: number;
271
+ /**
272
+ * Kills outright whatever the victim's health: a headshot on a ped, as
273
+ * the shooter's game decided it (always with a sniper or rifle). Returning
274
+ * a damage number replaces this with exactly that damage.
275
+ */
276
+ lethal?: boolean;
277
+ }
278
+ /**
279
+ * Event handlers. Handlers are called synchronously from the network loop.
280
+ * They may be async, but only `playerDamage` uses a return value, and it must
281
+ * return synchronously to count.
282
+ */
283
+ export interface ServerEvents {
284
+ /** A player finished joining. Everyone else has already been told. */
285
+ playerJoin: (player: Player) => void | Promise<void>;
286
+ /** A player left. The Player object is disconnected after this. */
287
+ playerQuit: (player: Player, reason: QuitReason) => void | Promise<void>;
288
+ /**
289
+ * `attacker` hit `victim` (as the attacker's game saw it, validated by the
290
+ * server). Return false to cancel the hit, or a number to replace its damage.
291
+ */
292
+ playerDamage: (victim: Player, attacker: Player | Ped, hit: Hit) => boolean | number | void;
293
+ /** The player died. `killer` is whoever last hit them within 10 s. */
294
+ playerDeath: (player: Player, killer: Player | Ped | null, weapon: number) => void | Promise<void>;
295
+ /** The player is alive in the world: after joining, and after each respawn. */
296
+ playerSpawn: (player: Player) => void | Promise<void>;
297
+ /**
298
+ * The player opened/closed the pause menu, or their game window lost/gained
299
+ * focus. Their character stays in the world either way.
300
+ */
301
+ playerPause: (player: Player, paused: boolean, focused: boolean) => void | Promise<void>;
302
+ /**
303
+ * A chat line from them (not a /command). Return false to drop it, or a
304
+ * string to send instead of their text; otherwise it goes to everyone as
305
+ * `server.chat.format` makes it ("Name: text").
306
+ */
307
+ playerChat: (player: Player, text: string) => boolean | string | void;
308
+ /**
309
+ * A /command line no registered command (`server.commands`) is called:
310
+ * the whole line, as SA-MP's OnPlayerCommandText. Return true if you
311
+ * handled it; otherwise they're told it's an unknown command.
312
+ */
313
+ playerCommandText: (player: Player, text: string) => boolean | void;
314
+ /** They came into their checkpoint (`player.setCheckpoint`). */
315
+ playerEnterCheckpoint: (player: Player) => void | Promise<void>;
316
+ /** They left it. */
317
+ playerLeaveCheckpoint: (player: Player) => void | Promise<void>;
318
+ /** They came into their race checkpoint (`player.setRaceCheckpoint`). */
319
+ playerEnterRaceCheckpoint: (player: Player) => void | Promise<void>;
320
+ /** They left it. */
321
+ playerLeaveRaceCheckpoint: (player: Player) => void | Promise<void>;
322
+ /**
323
+ * Their client script put an object in their hands (`model`), or took
324
+ * one away (`model` null), in `slot`. Return false to refuse: only they
325
+ * see it, until the slot is set again. Must return synchronously.
326
+ */
327
+ playerAttachObject: (player: Player, slot: number, model: number | null) => boolean | void;
328
+ /**
329
+ * `jacker` is pulling `victim` out of `vehicle` (carjacking on): as it
330
+ * starts. The jacker sits there once the victim's out.
331
+ */
332
+ playerCarjack: (jacker: Player, victim: Player, vehicle: Vehicle) => void | Promise<void>;
333
+ /** They pressed the key they bound to one of the server's actions (`server.actions`). */
334
+ playerAction: (player: Player, id: string) => void | Promise<void>;
335
+ /**
336
+ * The buttons they hold changed (`Key` bits; `player.keys` is the same):
337
+ * `keyPressed(keys, old, Key.Sprint)` for one going down. As their syncs
338
+ * show it, so a tap between two of them still shows (they're latched).
339
+ */
340
+ playerKeys: (player: Player, keys: number, old: number) => void | Promise<void>;
341
+ /** Their game took them into another interior by itself (one of the game's entrances, when on). */
342
+ playerInterior: (player: Player, interior: number, old: number) => void | Promise<void>;
343
+ /** The player got into a vehicle, as driver or passenger (`player.seat`). */
344
+ playerEnterVehicle: (player: Player, vehicle: Vehicle) => void | Promise<void>;
345
+ /** The player got out (or died, left, or it was destroyed). */
346
+ playerExitVehicle: (player: Player, vehicle: Vehicle) => void | Promise<void>;
347
+ /**
348
+ * Someone in the vehicle tuned its radio (it's shared by everyone in it).
349
+ * Return false to refuse (their radio goes back), or a station to tune to
350
+ * instead. Must return synchronously. To fix a vehicle's radio, set
351
+ * `vehicle.radio` (e.g. `RadioStation.Off`) and refuse every change.
352
+ */
353
+ vehicleRadio: (player: Player, vehicle: Vehicle, station: number) => boolean | number | void;
354
+ /**
355
+ * The vehicle is about to blow up (fire, damage), wrecked by `killer` if
356
+ * anyone. Return false to save it: it is repaired instead. Must return
357
+ * synchronously.
358
+ */
359
+ vehicleDeath: (vehicle: Vehicle, killer: Player | null) => boolean | void;
360
+ /**
361
+ * Something hit the vehicle: a crash (into a vehicle, a ped, an object, a
362
+ * wall, or the ground when that did harm) or a weapon. Hits from the same
363
+ * thing within 150 ms come as one. Return false to undo it (its health
364
+ * and dents are put back), or a number for the health it costs instead.
365
+ * Must return synchronously.
366
+ */
367
+ vehicleHit: (vehicle: Vehicle, hit: VehicleHit) => boolean | number | void;
368
+ /** It was put back where it was created, new (`respawn()`, or its respawn delay). */
369
+ vehicleRespawn: (vehicle: Vehicle) => void;
370
+ /**
371
+ * `attacker` hit a ped (validated as hits on players are). Return false to
372
+ * cancel the hit, or a number to replace its damage. Must return
373
+ * synchronously.
374
+ */
375
+ pedDamage: (ped: Ped, attacker: Player | Ped, hit: Hit) => boolean | number | void;
376
+ /**
377
+ * How a ped's order goes (`ped.walkTo()`, `ped.sequence()`, ...): a step
378
+ * done, the order done, or failed. Every ped's, in one place; `ped.on()`
379
+ * has the same for one ped.
380
+ */
381
+ pedOrder: (ped: Ped, info: {
382
+ orderId: number;
383
+ step: number;
384
+ state: "stepDone" | "done" | "failed";
385
+ reason?: string;
386
+ }) => void;
387
+ /** A ped died; `killer` landed the last hit within 10 s, if anyone. */
388
+ pedDeath: (ped: Ped, killer: Player | Ped | null, weapon: number) => void | Promise<void>;
389
+ /** A mission started, passed, failed or refused someone, or a player joined or left one: for logs and audits. */
390
+ missionEvent: (event: MissionEvent) => void | Promise<void>;
391
+ /**
392
+ * The game simulating a ped reported something impossible (it moved too
393
+ * fast, healed, changed weapon...). The report was refused; after a few,
394
+ * another player's game takes the ped over.
395
+ */
396
+ pedViolation: (player: Player, ped: Ped, reason: string) => void | Promise<void>;
397
+ /**
398
+ * A player's game proposed ambient population (a ped on foot, or a
399
+ * vehicle with its occupants), within the world's population settings and
400
+ * budgets. Return false to refuse it. Must return synchronously.
401
+ */
402
+ populationSpawn: (spawn: AmbientSpawn, player: Player) => boolean | void;
403
+ /**
404
+ * The player fired one round. Already checked (they own the weapon, have
405
+ * ammo and aren't firing too fast) and counted. Return false to cancel: no
406
+ * one else sees the shot and its hits don't count. Must return
407
+ * synchronously.
408
+ */
409
+ playerShoot: (player: Player, shot: Shot) => boolean | void;
410
+ /**
411
+ * The player's client used or held a weapon it shouldn't: one the server
412
+ * didn't give (`notOwned`), with no ammo left (`noAmmo`), or faster than
413
+ * the weapon fires (`fireRate`), or from somewhere they aren't
414
+ * (`position`). It was refused either way; this is for logging or
415
+ * punishing.
416
+ */
417
+ playerWeaponViolation: (player: Player, reason: WeaponViolationReason, weapon: number) => void | Promise<void>;
418
+ /**
419
+ * The player's game says their crimes (or losing the cops) changed their
420
+ * wanted level (only where the population's `wanted` is on). Return false
421
+ * to keep the old level, or a number for another. Must return
422
+ * synchronously.
423
+ */
424
+ playerWantedLevel: (player: Player, level: number, old: number) => boolean | number | void;
425
+ /**
426
+ * The player's client scripts sent data on a channel (`sagl.emit`); also
427
+ * given to that channel's handlers (`server.channel(name).on`).
428
+ */
429
+ clientMessage: (player: Player, channel: string, data: ChannelData) => void;
430
+ /** A client script threw (or failed to run) in the player's game. */
431
+ clientScriptError: (player: Player, error: ClientScriptError) => void;
432
+ /**
433
+ * The player's grenade, molotov, rocket or satchel went off (or a vehicle
434
+ * they wrecked blew up). Return false to cancel: its blast and fire hurt no
435
+ * player (everyone's game still shows it). Must return synchronously.
436
+ */
437
+ playerExplosion: (player: Player, explosion: Explosion) => boolean | void;
438
+ /** The player (on foot or driving) went into a zone. */
439
+ zoneEnter: (player: Player, zone: Zone) => void | Promise<void>;
440
+ /** The player came out of a zone. */
441
+ zoneLeave: (player: Player, zone: Zone) => void | Promise<void>;
442
+ /** The player moved while inside a zone: every position update (~20 a second). */
443
+ zoneMove: (player: Player, zone: Zone) => void | Promise<void>;
444
+ /** A Pay 'n' Spray or mod shop gave the player's car new colours (as SA-MP's OnVehicleRespray). */
445
+ vehicleRespray: (player: Player, vehicle: Vehicle, colors: [number, number]) => void | Promise<void>;
446
+ /** The player bought a part for their car in a mod shop (as SA-MP's OnVehicleMod). */
447
+ vehicleMod: (player: Player, vehicle: Vehicle, part: number, price: number) => void | Promise<void>;
448
+ /** The player bought a paint job (0-2) in a mod shop (as SA-MP's OnVehiclePaintjob). */
449
+ vehiclePaintjob: (player: Player, vehicle: Vehicle, paintjob: number, price: number) => void | Promise<void>;
450
+ /** The player bought a paint finish (null: standard paint) for their car in a mod shop. */
451
+ vehicleFinish: (player: Player, vehicle: Vehicle, finish: PaintFinish | null, price: number) => void | Promise<void>;
452
+ /** The player bought a licence plate for their car in a mod shop. */
453
+ vehiclePlate: (player: Player, vehicle: Vehicle, plate: string, price: number) => void | Promise<void>;
454
+ /** The player drove into a mod shop (`ModShop`; 0: one you made; `site` its id), or out (as SA-MP's OnEnterExitModShop). */
455
+ modShop: (player: Player, vehicle: Vehicle, shop: number, entered: boolean, site: string) => void | Promise<void>;
456
+ /** The player bought a livery (null: took it off) for their car in a mod shop. */
457
+ vehicleLivery: (player: Player, vehicle: Vehicle, livery: Livery | null, price: number) => void | Promise<void>;
458
+ }
459
+ /**
460
+ * A SAGL server.
461
+ *
462
+ * ```ts
463
+ * const server = new Server({ port: 7777, name: "My server" });
464
+ * server.on("playerJoin", (p) => server.broadcast(`${p.name} joined`));
465
+ * server.listen();
466
+ * ```
467
+ */
468
+ export declare class Server {
469
+ #private;
470
+ readonly options: Readonly<ServerOptions>;
471
+ /** Operator console on stdin; add commands with `server.console.command()`. */
472
+ readonly console: Console;
473
+ /** JavaScript run (sandboxed) in every player's game: see `ClientScripts`. */
474
+ readonly clientScripts: ClientScripts;
475
+ /** The pause menu's map, everyone's: see `GameMap`. */
476
+ readonly map: GameMap;
477
+ /** Drawing on everyone's screen (players joining later too), SA-MP textdraw style: see `ScreenDraw`. */
478
+ readonly draw: ServerDraw;
479
+ /** Missions: starting them, start markers, who's in which. See `Missions`. */
480
+ readonly missions: Missions;
481
+ /** Car colours: the game's, and your own (ids 128 up). See `VehicleColors`. */
482
+ readonly vehicleColors: VehicleColors;
483
+ /** Full-screen effects (your shaders) on everyone's screen, players joining later too. See `ScreenEffects`. */
484
+ readonly screenEffects: ScreenEffects;
485
+ /** The game's Pay 'n' Sprays, on by default. See `PayNSpray`. */
486
+ readonly payNSpray: PayNSpray;
487
+ /** The game's mod shops (TransFender, Loco Low Co, Wheel Arch Angels), on by default. See `ModShops`. */
488
+ readonly modShops: ModShops;
489
+ /** What players can walk up to and use: vending machines, payphones... See `Interactions`. */
490
+ readonly interactions: Interactions;
491
+ /** Things players do with a key they choose (Settings, Controls): see `Actions`. */
492
+ readonly actions: Actions;
493
+ /** Sounds from client files, positioned or not: see `ServerAudio`. */
494
+ readonly audio: ServerAudio;
495
+ /** The game's particle effects and coloured dust: see `ServerEffects`. */
496
+ readonly effects: ServerEffects;
497
+ /** First come, first served: one player at a time holds a thing. See `Claims`. */
498
+ readonly claims: Claims;
499
+ /** Chat commands, built as Minecraft's (`command(...)`): see `Commands`. */
500
+ readonly commands: Commands;
501
+ /** How chat lines go out, and its flood limit: see `ChatOptions`. */
502
+ readonly chat: ChatOptions;
503
+ /** The server's own animation sets (IFP client files): see `ServerAnimations`. */
504
+ readonly animations: ServerAnimations;
505
+ /** The server's own models (DFF/TXD client files), as SA-MP's AddSimpleModel: see `ServerModels`. */
506
+ readonly models: ServerModels;
507
+ /** Floating text in the world: `server.labels.add(text, at, options)`. See `Label`. */
508
+ readonly labels: {
509
+ add(text: string, at: LabelTarget, options?: LabelOptions): Label;
510
+ };
511
+ constructor(options?: ServerOptions);
512
+ /** Protocol version clients must speak. */
513
+ static get protocolVersion(): number;
514
+ /** SAGL's version this server is (as the client and the SDK: one version for all of SAGL). */
515
+ static get version(): string;
516
+ /**
517
+ * Starts accepting players. Also starts the operator console unless
518
+ * `{ console: false }`, and stops cleanly on SIGINT/SIGTERM.
519
+ */
520
+ listen({ console: withConsole }?: {
521
+ console?: boolean;
522
+ }): this;
523
+ /** Disconnects everyone and stops the network. */
524
+ close(): void;
525
+ /** The server's branding, for players joining from now. */
526
+ get branding(): Branding;
527
+ set branding(b: Branding);
528
+ /** What players download from the `clientFiles` directory: path, size, SHA-256 (hex). */
529
+ get clientFiles(): {
530
+ path: string;
531
+ size: number;
532
+ sha256: string;
533
+ }[];
534
+ /**
535
+ * Reads the `clientFiles` directory again (after changing it); players
536
+ * joining from now get it as it is. Returns how many files there are.
537
+ */
538
+ rescanClientFiles(): number;
539
+ /**
540
+ * The named channel between the gamemode and its client scripts (made on
541
+ * first use): `.on((player, data) => ...)` for what scripts send,
542
+ * `.send(player, data)` / `.broadcast(data)` to them. Data is JSON.
543
+ */
544
+ channel(name: string): Channel;
545
+ on<E extends keyof ServerEvents>(event: E, listener: ServerEvents[E]): this;
546
+ off<E extends keyof ServerEvents>(event: E, listener: ServerEvents[E]): this;
547
+ /**
548
+ * How name tags show, for everyone: within `distance` m (default 70),
549
+ * hidden behind buildings and objects (`lineOfSight`, default true), with
550
+ * their id (`ids`, default true), with health and armour bars under them
551
+ * (`bars`, default false). Setting it sets what's given. Each player's own:
552
+ * `player.nameTag`.
553
+ */
554
+ get nameTags(): Required<NameTagOptions>;
555
+ set nameTags(options: NameTagOptions);
556
+ /**
557
+ * A gang zone: a coloured rectangle on the radar and maps (SA-MP's
558
+ * GangZoneCreate), shown to no one until `show()`. See `GangZone`.
559
+ */
560
+ createGangZone(area: GangZoneArea, color: MapColor): GangZone;
561
+ /** Every gang zone not destroyed. */
562
+ get gangZones(): GangZone[];
563
+ /**
564
+ * The game's stunt bonuses for everyone (EnableStuntBonusForAll), players
565
+ * joining later too; `player.stuntBonus` changes one player's.
566
+ */
567
+ get stuntBonus(): boolean;
568
+ set stuntBonus(on: boolean);
569
+ /** Connected players. */
570
+ get players(): Player[];
571
+ player(id: number): Player | undefined;
572
+ /**
573
+ * Shows a message to every player. `color` is 0xRRGGBB. `markdown`: the
574
+ * text is markdown (bold, italic, code, links). `{key:ID}` shows an
575
+ * action's key either way.
576
+ */
577
+ broadcast(text: string, color?: number, options?: {
578
+ markdown?: boolean;
579
+ }): void;
580
+ /**
581
+ * An explosion at a spot, as SA-MP's CreateExplosion: the game's own
582
+ * (`ExplosionType`: grenade, molotov, rocket, car, small, tiny...), its
583
+ * blast, fire and damage, in the games of `to` (default everyone). It's
584
+ * no one's: a player it hurts is hurt as by a fall (no attacker), and a
585
+ * vehicle it wrecks is wrecked by nobody.
586
+ */
587
+ createExplosion(position: Vector3, type?: number, options?: {
588
+ to?: readonly Player[];
589
+ }): void;
590
+ /** Empties everyone's chat log. */
591
+ clearChat(): void;
592
+ /** A random valid ped model. */
593
+ randomSkin(): number;
594
+ /**
595
+ * Creates a vehicle for everyone, standing on the ground at `position`.
596
+ * `heading` in degrees (0 = north, anticlockwise).
597
+ */
598
+ createVehicle(model: number, position: Vector3, heading?: number, options?: VehicleOptions): Vehicle;
599
+ /**
600
+ * Creates a ped standing at `position` (feet) facing `heading` degrees:
601
+ * a ped model (skin), or one of the story's characters by name ("ryder",
602
+ * "sweet", "smoke", "cesar"...), which each player's game loads (up to 10
603
+ * different ones near a player at once).
604
+ * The nearest player's game runs its AI.
605
+ */
606
+ createPed(model: number | string, position: Vector3, heading?: number, options?: PedOptions): Ped;
607
+ /** Removes a ped for everyone (same as `ped.destroy()`). */
608
+ destroyPed(ped: Ped): void;
609
+ /** Every ped, the ambient population's included. */
610
+ get peds(): Ped[];
611
+ /** A ped by id. */
612
+ ped(id: number): Ped | undefined;
613
+ /** Removes a vehicle for everyone (same as `vehicle.destroy()`). */
614
+ destroyVehicle(vehicle: Vehicle): void;
615
+ /** Every vehicle, the ambient traffic's included. */
616
+ get vehicles(): Vehicle[];
617
+ vehicle(id: number): Vehicle | undefined;
618
+ /**
619
+ * World 0's ambient population (and every world's without its own): see
620
+ * `world.population`. Off by default.
621
+ */
622
+ get population(): Population;
623
+ set population(settings: Partial<Population>);
624
+ /**
625
+ * Watches an area: a sphere (`{ center, radius }`) or an axis-aligned box
626
+ * between two corners (`{ min, max }`).
627
+ */
628
+ createZone(shape: ({
629
+ center: Vector3;
630
+ radius: number;
631
+ } | {
632
+ min: Vector3;
633
+ max: Vector3;
634
+ }) & {
635
+ /** Only players in this virtual world trigger it. Default: any world. */
636
+ world?: number;
637
+ }): Zone;
638
+ destroyZone(zone: Zone): void;
639
+ get zones(): Zone[];
640
+ /** The game's garages, by id. */
641
+ get garages(): readonly Garage[];
642
+ garage(id: number): Garage | undefined;
643
+ /**
644
+ * Lets players in `viewer` world see (not meet) players and vehicles in
645
+ * `target` world, one way: a safehouse world viewing world 0 sees the
646
+ * street; world 0 still doesn't see in.
647
+ */
648
+ /**
649
+ * One of the game's objects (any object model: crates, gates, barriers,
650
+ * switches...) where you put it, for everyone (or `visibleTo`). It stays
651
+ * put: players' games never push or break it. With `health` it's
652
+ * breakable: players' shots, blows and cars wear it down until it's
653
+ * destroyed (`onDestroyed`). `move()` glides it (gates, shutters).
654
+ */
655
+ createObject(model: number, position: Vector3, rotation?: Rotation, options?: ObjectOptions): GameObject;
656
+ /**
657
+ * A pickup, spinning and glowing as the game's: a weapon (`weapon`,
658
+ * `ammo`), `health`, `armour` or `money`, given when a player walks into
659
+ * it (checked by the server), or any `model` with `onPickup` doing the
660
+ * rest. Taken once, or back after `respawn` ms.
661
+ */
662
+ createPickup(options: PickupOptions): Pickup;
663
+ /**
664
+ * Plays one of the game's cutscenes (from `anim/cuts.img`, e.g.
665
+ * `"ryder2a"`) for these players together: each game loads it (their
666
+ * screens fade out), it starts for everyone once all have it, and `done`
667
+ * resolves when everyone's has finished. The first player is the leader:
668
+ * their skip ends it for everyone (see `CutsceneOptions`).
669
+ */
670
+ playCutscene(players: Player | readonly Player[], name: string, options?: CutsceneOptions): CutscenePlay;
671
+ setWorldView(viewer: number, target: number, visible?: boolean): void;
672
+ /** Whether `viewer` world sees `target` world. */
673
+ worldSees(viewer: number, target: number): boolean;
674
+ /** A virtual world's settings: its time and weather (world 0's by default). */
675
+ world(id: number): World;
676
+ /**
677
+ * An area with effects like the game's own cull and audio zones, applied by
678
+ * the games of players in `world` (default: every world): interior music
679
+ * (`audio`, an `AudioZone`), `attributes` (`ZoneAttribute` bits, e.g. no
680
+ * rain) and/or a `mirror` (the plane at `coord` across `axis` 0 x / 1 y /
681
+ * 2 z, facing `sign`). An axis-aligned box between `min` and `max`.
682
+ */
683
+ createCullZone(zone: {
684
+ min: Vector3;
685
+ max: Vector3;
686
+ world?: number;
687
+ audio?: number;
688
+ attributes?: number;
689
+ mirror?: {
690
+ axis: 0 | 1 | 2;
691
+ sign: 1 | -1;
692
+ coord: number;
693
+ };
694
+ }): CullZone;
695
+ destroyCullZone(zone: CullZone): void;
696
+ /** World 0's weather (`Weather`); other worlds follow it unless set apart. */
697
+ get weather(): number;
698
+ set weather(weather: number);
699
+ /** World 0's traffic lights (every world's without its own): see `TrafficLights`. */
700
+ get trafficLights(): TrafficLights;
701
+ /** In-game time (world 0's). Setting it keeps the current frozen/running state. */
702
+ get time(): {
703
+ hour: number;
704
+ minute: number;
705
+ frozen: boolean;
706
+ };
707
+ set time(value: {
708
+ hour: number;
709
+ minute: number;
710
+ });
711
+ freezeTime(): void;
712
+ unfreezeTime(): void;
713
+ }