@aifivem/lib 0.6.0 → 0.8.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/package.json +3 -3
- package/src/client/action.ts +38 -38
- package/src/client/callback.ts +70 -70
- package/src/client/controls.ts +73 -73
- package/src/client/entity.ts +15 -15
- package/src/client/headshot.ts +26 -26
- package/src/client/index.ts +2 -5
- package/src/client/localPed.ts +169 -169
- package/src/client/location.ts +54 -54
- package/src/client/netEvent.ts +40 -40
- package/src/client/nuiScreen.ts +87 -87
- package/src/client/phone.ts +14 -0
- package/src/client/players.ts +34 -34
- package/src/client/raycast.ts +48 -48
- package/src/client/shot.ts +29 -29
- package/src/client/vehicleProps.ts +107 -107
- package/src/fivem/callbackNames.ts +12 -12
- package/src/fivem/locale.ts +57 -57
- package/src/server/callback.ts +112 -112
- package/src/server/characters.ts +12 -3
- package/src/server/dataFile.ts +81 -81
- package/src/server/illegal.ts +26 -0
- package/src/server/index.ts +2 -0
- package/src/server/mdt.ts +13 -0
- package/src/server/netEvent.ts +58 -58
- package/src/server/phone.ts +11 -5
- package/src/server/position.ts +20 -20
- package/src/server/rateLimit.ts +53 -53
- package/src/server/stress.ts +4 -1
- package/src/server/warrants.ts +37 -0
- package/src/shared/format.ts +26 -26
- package/src/shared/grid.ts +20 -20
- package/src/shared/index.ts +151 -151
- package/src/shared/lang.ts +39 -39
- package/src/shared/read.ts +60 -60
- package/src/shared/strict.ts +70 -70
- package/src/shared/vec.ts +19 -19
- package/src/shared/vehicleProps.ts +138 -138
- package/src/shared/wait.ts +27 -27
package/src/client/nuiScreen.ts
CHANGED
|
@@ -1,87 +1,87 @@
|
|
|
1
|
-
import { hud } from "./hud";
|
|
2
|
-
|
|
3
|
-
/** A message to this resource's NUI page: `{ action, data }`. */
|
|
4
|
-
export interface NuiPageMessage {
|
|
5
|
-
action: string;
|
|
6
|
-
data?: unknown;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export interface NuiScreenOptions {
|
|
10
|
-
/** Show the mouse cursor while open (default true). */
|
|
11
|
-
cursor?: boolean;
|
|
12
|
-
/** Runs after the screen closed (the page's own close button included): the script's cleanup. */
|
|
13
|
-
onClose?: () => void;
|
|
14
|
-
/** The page's `close` callback closes the screen (default true; false when only the script may close it). */
|
|
15
|
-
closeCallback?: boolean;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
type Reply = (result: unknown) => void;
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* This resource's full-screen NUI: `open` takes the focus, hides every HUD (lib `hud`) and sends the open message;
|
|
22
|
-
* `close` gives the focus back, shows the HUDs, sends `{ action: "close" }` and runs `onClose`. The page's `close`
|
|
23
|
-
* callback closes it. For full-screen UIs (overlays such as a chat box or a wheel keep the HUD and their own focus).
|
|
24
|
-
* One per resource, created once at module level.
|
|
25
|
-
*/
|
|
26
|
-
export class NuiScreen<M extends NuiPageMessage = NuiPageMessage> {
|
|
27
|
-
private shown = false;
|
|
28
|
-
|
|
29
|
-
/** `name` is the HUD hide reason (`<resource>:<name>`). */
|
|
30
|
-
constructor(
|
|
31
|
-
private readonly name: string,
|
|
32
|
-
private readonly options: NuiScreenOptions = {},
|
|
33
|
-
) {
|
|
34
|
-
if (options.closeCallback !== false)
|
|
35
|
-
RegisterNuiCallback("close", (_data: unknown, cb: Reply) => {
|
|
36
|
-
this.close();
|
|
37
|
-
cb({ ok: true });
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
get isOpen(): boolean {
|
|
42
|
-
return this.shown;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/** Focuses the page (once) and sends `message`. */
|
|
46
|
-
open(message: M): void {
|
|
47
|
-
if (!this.shown) {
|
|
48
|
-
this.shown = true;
|
|
49
|
-
SetNuiFocus(true, this.options.cursor ?? true);
|
|
50
|
-
hud.hide(this.name);
|
|
51
|
-
}
|
|
52
|
-
this.send(message);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
close(): void {
|
|
56
|
-
if (!this.shown) return;
|
|
57
|
-
this.shown = false;
|
|
58
|
-
SetNuiFocus(false, false);
|
|
59
|
-
hud.show(this.name);
|
|
60
|
-
SendNUIMessage({ action: "close", data: null });
|
|
61
|
-
this.options.onClose?.();
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/** A typed message to the page. */
|
|
65
|
-
send(message: M): void {
|
|
66
|
-
SendNUIMessage(message);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* A NUI callback of the page: `parse` checks the data (null answers `{ ok: false }`), the handler's result (awaited)
|
|
71
|
-
* is the reply, `{ ok: true }` when it returns nothing.
|
|
72
|
-
*/
|
|
73
|
-
on<A>(
|
|
74
|
-
name: string,
|
|
75
|
-
parse: (data: unknown) => A | null,
|
|
76
|
-
handler: (data: A) => unknown,
|
|
77
|
-
): void {
|
|
78
|
-
RegisterNuiCallback(name, (raw: unknown, cb: Reply) => {
|
|
79
|
-
const data = parse(raw);
|
|
80
|
-
if (data === null) return cb({ ok: false });
|
|
81
|
-
Promise.resolve(handler(data)).then(
|
|
82
|
-
(result) => cb(result ?? { ok: true }),
|
|
83
|
-
() => cb({ ok: false }),
|
|
84
|
-
);
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
}
|
|
1
|
+
import { hud } from "./hud";
|
|
2
|
+
|
|
3
|
+
/** A message to this resource's NUI page: `{ action, data }`. */
|
|
4
|
+
export interface NuiPageMessage {
|
|
5
|
+
action: string;
|
|
6
|
+
data?: unknown;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface NuiScreenOptions {
|
|
10
|
+
/** Show the mouse cursor while open (default true). */
|
|
11
|
+
cursor?: boolean;
|
|
12
|
+
/** Runs after the screen closed (the page's own close button included): the script's cleanup. */
|
|
13
|
+
onClose?: () => void;
|
|
14
|
+
/** The page's `close` callback closes the screen (default true; false when only the script may close it). */
|
|
15
|
+
closeCallback?: boolean;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
type Reply = (result: unknown) => void;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* This resource's full-screen NUI: `open` takes the focus, hides every HUD (lib `hud`) and sends the open message;
|
|
22
|
+
* `close` gives the focus back, shows the HUDs, sends `{ action: "close" }` and runs `onClose`. The page's `close`
|
|
23
|
+
* callback closes it. For full-screen UIs (overlays such as a chat box or a wheel keep the HUD and their own focus).
|
|
24
|
+
* One per resource, created once at module level.
|
|
25
|
+
*/
|
|
26
|
+
export class NuiScreen<M extends NuiPageMessage = NuiPageMessage> {
|
|
27
|
+
private shown = false;
|
|
28
|
+
|
|
29
|
+
/** `name` is the HUD hide reason (`<resource>:<name>`). */
|
|
30
|
+
constructor(
|
|
31
|
+
private readonly name: string,
|
|
32
|
+
private readonly options: NuiScreenOptions = {},
|
|
33
|
+
) {
|
|
34
|
+
if (options.closeCallback !== false)
|
|
35
|
+
RegisterNuiCallback("close", (_data: unknown, cb: Reply) => {
|
|
36
|
+
this.close();
|
|
37
|
+
cb({ ok: true });
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
get isOpen(): boolean {
|
|
42
|
+
return this.shown;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** Focuses the page (once) and sends `message`. */
|
|
46
|
+
open(message: M): void {
|
|
47
|
+
if (!this.shown) {
|
|
48
|
+
this.shown = true;
|
|
49
|
+
SetNuiFocus(true, this.options.cursor ?? true);
|
|
50
|
+
hud.hide(this.name);
|
|
51
|
+
}
|
|
52
|
+
this.send(message);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
close(): void {
|
|
56
|
+
if (!this.shown) return;
|
|
57
|
+
this.shown = false;
|
|
58
|
+
SetNuiFocus(false, false);
|
|
59
|
+
hud.show(this.name);
|
|
60
|
+
SendNUIMessage({ action: "close", data: null });
|
|
61
|
+
this.options.onClose?.();
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** A typed message to the page. */
|
|
65
|
+
send(message: M): void {
|
|
66
|
+
SendNUIMessage(message);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* A NUI callback of the page: `parse` checks the data (null answers `{ ok: false }`), the handler's result (awaited)
|
|
71
|
+
* is the reply, `{ ok: true }` when it returns nothing.
|
|
72
|
+
*/
|
|
73
|
+
on<A>(
|
|
74
|
+
name: string,
|
|
75
|
+
parse: (data: unknown) => A | null,
|
|
76
|
+
handler: (data: A) => unknown,
|
|
77
|
+
): void {
|
|
78
|
+
RegisterNuiCallback(name, (raw: unknown, cb: Reply) => {
|
|
79
|
+
const data = parse(raw);
|
|
80
|
+
if (data === null) return cb({ ok: false });
|
|
81
|
+
Promise.resolve(handler(data)).then(
|
|
82
|
+
(result) => cb(result ?? { ok: true }),
|
|
83
|
+
() => cb({ ok: false }),
|
|
84
|
+
);
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { CORE } from "@aifivem/shared";
|
|
2
|
+
|
|
3
|
+
/** The local player's phone through ai-core's client phone layer, whatever phone runs (`docs/compat/phone.md`). */
|
|
4
|
+
export const phone = {
|
|
5
|
+
/**
|
|
6
|
+
* `fn(phone)` when the local player opens the phone (`phone`: the phone's resource name): once per opening, at most
|
|
7
|
+
* once per 10 s; nothing for a phone without an open signal.
|
|
8
|
+
*/
|
|
9
|
+
onUsed(fn: (phone: string) => void): void {
|
|
10
|
+
on(CORE.clientPhoneUsedEvent, (phone: unknown) => {
|
|
11
|
+
if (typeof phone === "string") fn(phone);
|
|
12
|
+
});
|
|
13
|
+
},
|
|
14
|
+
};
|
package/src/client/players.ts
CHANGED
|
@@ -1,37 +1,37 @@
|
|
|
1
|
-
import type { Vec3 } from "../shared/vec";
|
|
2
|
-
import { cache } from "./cache";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* The closest other player within `metres` of the local ped (or of `from`: a point in front for a tackle), as a server
|
|
6
|
-
* id; `filter` gets the server id and the ped (alive, on foot...). null when none. Walks the streamed players only.
|
|
7
|
-
*/
|
|
8
|
-
export function nearestPlayer(
|
|
9
|
-
metres: number,
|
|
10
|
-
options: {
|
|
11
|
-
from?: Vec3;
|
|
12
|
-
filter?: (serverId: number, ped: number) => boolean;
|
|
13
|
-
} = {},
|
|
14
|
-
): number | null {
|
|
15
|
-
let x: number;
|
|
16
|
-
let y: number;
|
|
17
|
-
let z: number;
|
|
18
|
-
if (options.from) ({ x, y, z } = options.from);
|
|
19
|
-
else [x = 0, y = 0, z = 0] = GetEntityCoords(cache.ped, false);
|
|
20
|
-
let best: number | null = null;
|
|
21
|
-
let bestDistance = metres;
|
|
22
|
-
for (const player of GetActivePlayers() as number[]) {
|
|
23
|
-
if (player === cache.playerId) continue;
|
|
24
|
-
const ped = GetPlayerPed(player);
|
|
25
|
-
const [px = 0, py = 0, pz = 0] = GetEntityCoords(ped, false);
|
|
26
|
-
const d = Math.hypot(px - x, py - y, pz - z);
|
|
27
|
-
if (d > bestDistance) continue;
|
|
28
|
-
const serverId = GetPlayerServerId(player);
|
|
29
|
-
if (options.filter && !options.filter(serverId, ped)) continue;
|
|
30
|
-
best = serverId;
|
|
31
|
-
bestDistance = d;
|
|
32
|
-
}
|
|
33
|
-
return best;
|
|
34
|
-
}
|
|
1
|
+
import type { Vec3 } from "../shared/vec";
|
|
2
|
+
import { cache } from "./cache";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The closest other player within `metres` of the local ped (or of `from`: a point in front for a tackle), as a server
|
|
6
|
+
* id; `filter` gets the server id and the ped (alive, on foot...). null when none. Walks the streamed players only.
|
|
7
|
+
*/
|
|
8
|
+
export function nearestPlayer(
|
|
9
|
+
metres: number,
|
|
10
|
+
options: {
|
|
11
|
+
from?: Vec3;
|
|
12
|
+
filter?: (serverId: number, ped: number) => boolean;
|
|
13
|
+
} = {},
|
|
14
|
+
): number | null {
|
|
15
|
+
let x: number;
|
|
16
|
+
let y: number;
|
|
17
|
+
let z: number;
|
|
18
|
+
if (options.from) ({ x, y, z } = options.from);
|
|
19
|
+
else [x = 0, y = 0, z = 0] = GetEntityCoords(cache.ped, false);
|
|
20
|
+
let best: number | null = null;
|
|
21
|
+
let bestDistance = metres;
|
|
22
|
+
for (const player of GetActivePlayers() as number[]) {
|
|
23
|
+
if (player === cache.playerId) continue;
|
|
24
|
+
const ped = GetPlayerPed(player);
|
|
25
|
+
const [px = 0, py = 0, pz = 0] = GetEntityCoords(ped, false);
|
|
26
|
+
const d = Math.hypot(px - x, py - y, pz - z);
|
|
27
|
+
if (d > bestDistance) continue;
|
|
28
|
+
const serverId = GetPlayerServerId(player);
|
|
29
|
+
if (options.filter && !options.filter(serverId, ped)) continue;
|
|
30
|
+
best = serverId;
|
|
31
|
+
bestDistance = d;
|
|
32
|
+
}
|
|
33
|
+
return best;
|
|
34
|
+
}
|
|
35
35
|
|
|
36
36
|
/**
|
|
37
37
|
* The ped of a player by server id: `cache.ped` for the local player, 0 when that player is not in scope (never the
|
package/src/client/raycast.ts
CHANGED
|
@@ -1,48 +1,48 @@
|
|
|
1
|
-
import type { Vec3 } from "../shared/vec";
|
|
2
|
-
import { cache } from "./cache";
|
|
3
|
-
|
|
4
|
-
/** What a line probe hit first: the point, the surface normal and the entity (0 = the map). */
|
|
5
|
-
export interface RayHit {
|
|
6
|
-
coords: Vec3;
|
|
7
|
-
normal: Vec3;
|
|
8
|
-
entity: number;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export interface RaycastOptions {
|
|
12
|
-
/** What the probe tests: 1 map, 2 vehicles, 4 peds, 8 ragdolls, 16 objects (default 1 | 2 | 16). */
|
|
13
|
-
flags?: number;
|
|
14
|
-
/** An entity the probe passes through (default the local ped). */
|
|
15
|
-
ignore?: number;
|
|
16
|
-
/** Probe option bits: 1 ignore glass, 2 ignore see-through, 4 ignore no-collision (default 7). */
|
|
17
|
-
options?: number;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* A line probe answered in the same frame (`StartExpensiveSynchronousShapeTestLosProbe`): what it hit first, or null.
|
|
22
|
-
* It blocks until the test is done, so keep it to one or two per frame.
|
|
23
|
-
*/
|
|
24
|
-
export function raycast(
|
|
25
|
-
from: Vec3,
|
|
26
|
-
to: Vec3,
|
|
27
|
-
{ flags = 1 | 2 | 16, ignore = cache.ped, options = 7 }: RaycastOptions = {},
|
|
28
|
-
): RayHit | null {
|
|
29
|
-
const [, hit, end, normal, entity] = GetShapeTestResult(
|
|
30
|
-
StartExpensiveSynchronousShapeTestLosProbe(
|
|
31
|
-
from.x,
|
|
32
|
-
from.y,
|
|
33
|
-
from.z,
|
|
34
|
-
to.x,
|
|
35
|
-
to.y,
|
|
36
|
-
to.z,
|
|
37
|
-
flags,
|
|
38
|
-
ignore,
|
|
39
|
-
options,
|
|
40
|
-
),
|
|
41
|
-
);
|
|
42
|
-
if (!hit) return null;
|
|
43
|
-
return {
|
|
44
|
-
coords: { x: end[0] ?? 0, y: end[1] ?? 0, z: end[2] ?? 0 },
|
|
45
|
-
normal: { x: normal[0] ?? 0, y: normal[1] ?? 0, z: normal[2] ?? 0 },
|
|
46
|
-
entity,
|
|
47
|
-
};
|
|
48
|
-
}
|
|
1
|
+
import type { Vec3 } from "../shared/vec";
|
|
2
|
+
import { cache } from "./cache";
|
|
3
|
+
|
|
4
|
+
/** What a line probe hit first: the point, the surface normal and the entity (0 = the map). */
|
|
5
|
+
export interface RayHit {
|
|
6
|
+
coords: Vec3;
|
|
7
|
+
normal: Vec3;
|
|
8
|
+
entity: number;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface RaycastOptions {
|
|
12
|
+
/** What the probe tests: 1 map, 2 vehicles, 4 peds, 8 ragdolls, 16 objects (default 1 | 2 | 16). */
|
|
13
|
+
flags?: number;
|
|
14
|
+
/** An entity the probe passes through (default the local ped). */
|
|
15
|
+
ignore?: number;
|
|
16
|
+
/** Probe option bits: 1 ignore glass, 2 ignore see-through, 4 ignore no-collision (default 7). */
|
|
17
|
+
options?: number;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* A line probe answered in the same frame (`StartExpensiveSynchronousShapeTestLosProbe`): what it hit first, or null.
|
|
22
|
+
* It blocks until the test is done, so keep it to one or two per frame.
|
|
23
|
+
*/
|
|
24
|
+
export function raycast(
|
|
25
|
+
from: Vec3,
|
|
26
|
+
to: Vec3,
|
|
27
|
+
{ flags = 1 | 2 | 16, ignore = cache.ped, options = 7 }: RaycastOptions = {},
|
|
28
|
+
): RayHit | null {
|
|
29
|
+
const [, hit, end, normal, entity] = GetShapeTestResult(
|
|
30
|
+
StartExpensiveSynchronousShapeTestLosProbe(
|
|
31
|
+
from.x,
|
|
32
|
+
from.y,
|
|
33
|
+
from.z,
|
|
34
|
+
to.x,
|
|
35
|
+
to.y,
|
|
36
|
+
to.z,
|
|
37
|
+
flags,
|
|
38
|
+
ignore,
|
|
39
|
+
options,
|
|
40
|
+
),
|
|
41
|
+
);
|
|
42
|
+
if (!hit) return null;
|
|
43
|
+
return {
|
|
44
|
+
coords: { x: end[0] ?? 0, y: end[1] ?? 0, z: end[2] ?? 0 },
|
|
45
|
+
normal: { x: normal[0] ?? 0, y: normal[1] ?? 0, z: normal[2] ?? 0 },
|
|
46
|
+
entity,
|
|
47
|
+
};
|
|
48
|
+
}
|
package/src/client/shot.ts
CHANGED
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
import { cache, onCache } from "./cache";
|
|
2
|
-
import { TickLoop } from "./tickLoop";
|
|
3
|
-
|
|
4
|
-
type ShotHandler = (weapon: number) => void;
|
|
5
|
-
const handlers = new Set<ShotHandler>();
|
|
6
|
-
|
|
7
|
-
/** `IsPedShooting` is true only in the frame of the shot, so it is read every frame, but only while a weapon is held. */
|
|
8
|
-
const frame = new TickLoop(() => {
|
|
9
|
-
const weapon = cache.weapon;
|
|
10
|
-
if (weapon === false || !IsPedShooting(cache.ped)) return;
|
|
11
|
-
for (const handler of handlers) handler(weapon);
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
const update = (): void =>
|
|
15
|
-
frame.set(handlers.size > 0 && cache.weapon !== false);
|
|
16
|
-
onCache("weapon", update);
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Runs `handler(weapon)` in the frame the local ped fires a shot (stress, shot alerts). One per-frame check for the
|
|
20
|
-
* resource, on only while a weapon is in hand. Keep the handler cheap (it runs inside the frame).
|
|
21
|
-
*/
|
|
22
|
-
export function onShot(handler: ShotHandler): () => void {
|
|
23
|
-
handlers.add(handler);
|
|
24
|
-
update();
|
|
25
|
-
return () => {
|
|
26
|
-
handlers.delete(handler);
|
|
27
|
-
update();
|
|
28
|
-
};
|
|
29
|
-
}
|
|
1
|
+
import { cache, onCache } from "./cache";
|
|
2
|
+
import { TickLoop } from "./tickLoop";
|
|
3
|
+
|
|
4
|
+
type ShotHandler = (weapon: number) => void;
|
|
5
|
+
const handlers = new Set<ShotHandler>();
|
|
6
|
+
|
|
7
|
+
/** `IsPedShooting` is true only in the frame of the shot, so it is read every frame, but only while a weapon is held. */
|
|
8
|
+
const frame = new TickLoop(() => {
|
|
9
|
+
const weapon = cache.weapon;
|
|
10
|
+
if (weapon === false || !IsPedShooting(cache.ped)) return;
|
|
11
|
+
for (const handler of handlers) handler(weapon);
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
const update = (): void =>
|
|
15
|
+
frame.set(handlers.size > 0 && cache.weapon !== false);
|
|
16
|
+
onCache("weapon", update);
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Runs `handler(weapon)` in the frame the local ped fires a shot (stress, shot alerts). One per-frame check for the
|
|
20
|
+
* resource, on only while a weapon is in hand. Keep the handler cheap (it runs inside the frame).
|
|
21
|
+
*/
|
|
22
|
+
export function onShot(handler: ShotHandler): () => void {
|
|
23
|
+
handlers.add(handler);
|
|
24
|
+
update();
|
|
25
|
+
return () => {
|
|
26
|
+
handlers.delete(handler);
|
|
27
|
+
update();
|
|
28
|
+
};
|
|
29
|
+
}
|
|
@@ -1,107 +1,107 @@
|
|
|
1
|
-
import type { VehicleProps, VehicleSetup } from "../shared/vehicleProps";
|
|
2
|
-
|
|
3
|
-
const MOD_TYPES = Array.from({ length: 50 }, (_, i) => i);
|
|
4
|
-
const TOGGLE_MODS = [17, 18, 19, 20, 21, 22];
|
|
5
|
-
|
|
6
|
-
/** Reads every property of a vehicle the local client can see. */
|
|
7
|
-
export function getVehicleProps(vehicle: number): VehicleProps {
|
|
8
|
-
const [primary, secondary] = GetVehicleColours(vehicle);
|
|
9
|
-
const [pearl, wheel] = GetVehicleExtraColours(vehicle);
|
|
10
|
-
const mods: Record<number, number> = {};
|
|
11
|
-
for (const type of MOD_TYPES) {
|
|
12
|
-
if (TOGGLE_MODS.includes(type))
|
|
13
|
-
mods[type] = IsToggleModOn(vehicle, type) ? 1 : 0;
|
|
14
|
-
else mods[type] = GetVehicleMod(vehicle, type);
|
|
15
|
-
}
|
|
16
|
-
const extras: Record<number, boolean> = {};
|
|
17
|
-
for (let id = 0; id <= 14; id++)
|
|
18
|
-
if (DoesExtraExist(vehicle, id))
|
|
19
|
-
extras[id] = IsVehicleExtraTurnedOn(vehicle, id);
|
|
20
|
-
const custom = (
|
|
21
|
-
get: (v: number) => [number, number, number],
|
|
22
|
-
has: boolean,
|
|
23
|
-
) => (has ? get(vehicle) : null);
|
|
24
|
-
return {
|
|
25
|
-
v: 1,
|
|
26
|
-
model: GetEntityModel(vehicle),
|
|
27
|
-
plate: GetVehicleNumberPlateText(vehicle).trim(),
|
|
28
|
-
plateIndex: GetVehicleNumberPlateTextIndex(vehicle),
|
|
29
|
-
colors: [primary ?? 0, secondary ?? 0],
|
|
30
|
-
extraColors: [pearl ?? 0, wheel ?? 0],
|
|
31
|
-
customPrimary: custom(
|
|
32
|
-
GetVehicleCustomPrimaryColour,
|
|
33
|
-
GetIsVehiclePrimaryColourCustom(vehicle),
|
|
34
|
-
),
|
|
35
|
-
customSecondary: custom(
|
|
36
|
-
GetVehicleCustomSecondaryColour,
|
|
37
|
-
GetIsVehicleSecondaryColourCustom(vehicle),
|
|
38
|
-
),
|
|
39
|
-
wheelType: GetVehicleWheelType(vehicle),
|
|
40
|
-
windowTint: GetVehicleWindowTint(vehicle),
|
|
41
|
-
livery: GetVehicleLivery(vehicle),
|
|
42
|
-
mods,
|
|
43
|
-
xenonColor: GetVehicleXenonLightsColor(vehicle),
|
|
44
|
-
neon: [0, 1, 2, 3].map((i) =>
|
|
45
|
-
IsVehicleNeonLightEnabled(vehicle, i),
|
|
46
|
-
) as VehicleProps["neon"],
|
|
47
|
-
neonColor: GetVehicleNeonLightsColour(vehicle),
|
|
48
|
-
tyreSmoke: GetVehicleTyreSmokeColor(vehicle),
|
|
49
|
-
extras,
|
|
50
|
-
dirt: GetVehicleDirtLevel(vehicle),
|
|
51
|
-
engineHealth: GetVehicleEngineHealth(vehicle),
|
|
52
|
-
bodyHealth: GetVehicleBodyHealth(vehicle),
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/** Applies stored properties (only to a vehicle this client controls; others get them through the network). */
|
|
57
|
-
export function setVehicleProps(vehicle: number, props: VehicleProps): void {
|
|
58
|
-
SetVehicleModKit(vehicle, 0);
|
|
59
|
-
SetVehicleNumberPlateText(vehicle, props.plate);
|
|
60
|
-
SetVehicleNumberPlateTextIndex(vehicle, props.plateIndex);
|
|
61
|
-
SetVehicleColours(vehicle, props.colors[0], props.colors[1]);
|
|
62
|
-
SetVehicleExtraColours(vehicle, props.extraColors[0], props.extraColors[1]);
|
|
63
|
-
if (props.customPrimary)
|
|
64
|
-
SetVehicleCustomPrimaryColour(vehicle, ...props.customPrimary);
|
|
65
|
-
if (props.customSecondary)
|
|
66
|
-
SetVehicleCustomSecondaryColour(vehicle, ...props.customSecondary);
|
|
67
|
-
SetVehicleWheelType(vehicle, props.wheelType);
|
|
68
|
-
SetVehicleWindowTint(vehicle, props.windowTint);
|
|
69
|
-
for (const [type, index] of Object.entries(props.mods)) {
|
|
70
|
-
const t = Number(type);
|
|
71
|
-
if (TOGGLE_MODS.includes(t)) ToggleVehicleMod(vehicle, t, index === 1);
|
|
72
|
-
else SetVehicleMod(vehicle, t, index, false);
|
|
73
|
-
}
|
|
74
|
-
SetVehicleLivery(vehicle, props.livery);
|
|
75
|
-
SetVehicleXenonLightsColor(vehicle, props.xenonColor);
|
|
76
|
-
props.neon.forEach((on, i) => SetVehicleNeonLightEnabled(vehicle, i, on));
|
|
77
|
-
SetVehicleNeonLightsColour(vehicle, ...props.neonColor);
|
|
78
|
-
SetVehicleTyreSmokeColor(vehicle, ...props.tyreSmoke);
|
|
79
|
-
for (const [id, on] of Object.entries(props.extras))
|
|
80
|
-
SetVehicleExtra(vehicle, Number(id), !on);
|
|
81
|
-
SetVehicleDirtLevel(vehicle, props.dirt);
|
|
82
|
-
SetVehicleEngineHealth(vehicle, props.engineHealth);
|
|
83
|
-
SetVehicleBodyHealth(vehicle, props.bodyHealth);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
/** Engine, brakes, transmission, suspension, armour: the mods `maxed` sets to their top level. */
|
|
87
|
-
const PERFORMANCE_MODS = [11, 12, 13, 15, 16];
|
|
88
|
-
|
|
89
|
-
/** Applies a spawn setup (only to a vehicle this client controls). */
|
|
90
|
-
export function setVehicleSetup(vehicle: number, setup: VehicleSetup): void {
|
|
91
|
-
SetVehicleModKit(vehicle, 0);
|
|
92
|
-
if (setup.maxed) {
|
|
93
|
-
for (const mod of PERFORMANCE_MODS)
|
|
94
|
-
SetVehicleMod(vehicle, mod, GetNumVehicleMods(vehicle, mod) - 1, false);
|
|
95
|
-
ToggleVehicleMod(vehicle, 18, true);
|
|
96
|
-
ToggleVehicleMod(vehicle, 22, true);
|
|
97
|
-
}
|
|
98
|
-
if (setup.colors) SetVehicleColours(vehicle, ...setup.colors);
|
|
99
|
-
if (setup.primary) SetVehicleCustomPrimaryColour(vehicle, ...setup.primary);
|
|
100
|
-
if (setup.secondary)
|
|
101
|
-
SetVehicleCustomSecondaryColour(vehicle, ...setup.secondary);
|
|
102
|
-
if (setup.livery !== undefined) SetVehicleLivery(vehicle, setup.livery);
|
|
103
|
-
if (setup.windowTint !== undefined)
|
|
104
|
-
SetVehicleWindowTint(vehicle, setup.windowTint);
|
|
105
|
-
if (setup.dirt !== undefined) SetVehicleDirtLevel(vehicle, setup.dirt);
|
|
106
|
-
if (setup.engineOn) SetVehicleEngineOn(vehicle, true, true, false);
|
|
107
|
-
}
|
|
1
|
+
import type { VehicleProps, VehicleSetup } from "../shared/vehicleProps";
|
|
2
|
+
|
|
3
|
+
const MOD_TYPES = Array.from({ length: 50 }, (_, i) => i);
|
|
4
|
+
const TOGGLE_MODS = [17, 18, 19, 20, 21, 22];
|
|
5
|
+
|
|
6
|
+
/** Reads every property of a vehicle the local client can see. */
|
|
7
|
+
export function getVehicleProps(vehicle: number): VehicleProps {
|
|
8
|
+
const [primary, secondary] = GetVehicleColours(vehicle);
|
|
9
|
+
const [pearl, wheel] = GetVehicleExtraColours(vehicle);
|
|
10
|
+
const mods: Record<number, number> = {};
|
|
11
|
+
for (const type of MOD_TYPES) {
|
|
12
|
+
if (TOGGLE_MODS.includes(type))
|
|
13
|
+
mods[type] = IsToggleModOn(vehicle, type) ? 1 : 0;
|
|
14
|
+
else mods[type] = GetVehicleMod(vehicle, type);
|
|
15
|
+
}
|
|
16
|
+
const extras: Record<number, boolean> = {};
|
|
17
|
+
for (let id = 0; id <= 14; id++)
|
|
18
|
+
if (DoesExtraExist(vehicle, id))
|
|
19
|
+
extras[id] = IsVehicleExtraTurnedOn(vehicle, id);
|
|
20
|
+
const custom = (
|
|
21
|
+
get: (v: number) => [number, number, number],
|
|
22
|
+
has: boolean,
|
|
23
|
+
) => (has ? get(vehicle) : null);
|
|
24
|
+
return {
|
|
25
|
+
v: 1,
|
|
26
|
+
model: GetEntityModel(vehicle),
|
|
27
|
+
plate: GetVehicleNumberPlateText(vehicle).trim(),
|
|
28
|
+
plateIndex: GetVehicleNumberPlateTextIndex(vehicle),
|
|
29
|
+
colors: [primary ?? 0, secondary ?? 0],
|
|
30
|
+
extraColors: [pearl ?? 0, wheel ?? 0],
|
|
31
|
+
customPrimary: custom(
|
|
32
|
+
GetVehicleCustomPrimaryColour,
|
|
33
|
+
GetIsVehiclePrimaryColourCustom(vehicle),
|
|
34
|
+
),
|
|
35
|
+
customSecondary: custom(
|
|
36
|
+
GetVehicleCustomSecondaryColour,
|
|
37
|
+
GetIsVehicleSecondaryColourCustom(vehicle),
|
|
38
|
+
),
|
|
39
|
+
wheelType: GetVehicleWheelType(vehicle),
|
|
40
|
+
windowTint: GetVehicleWindowTint(vehicle),
|
|
41
|
+
livery: GetVehicleLivery(vehicle),
|
|
42
|
+
mods,
|
|
43
|
+
xenonColor: GetVehicleXenonLightsColor(vehicle),
|
|
44
|
+
neon: [0, 1, 2, 3].map((i) =>
|
|
45
|
+
IsVehicleNeonLightEnabled(vehicle, i),
|
|
46
|
+
) as VehicleProps["neon"],
|
|
47
|
+
neonColor: GetVehicleNeonLightsColour(vehicle),
|
|
48
|
+
tyreSmoke: GetVehicleTyreSmokeColor(vehicle),
|
|
49
|
+
extras,
|
|
50
|
+
dirt: GetVehicleDirtLevel(vehicle),
|
|
51
|
+
engineHealth: GetVehicleEngineHealth(vehicle),
|
|
52
|
+
bodyHealth: GetVehicleBodyHealth(vehicle),
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** Applies stored properties (only to a vehicle this client controls; others get them through the network). */
|
|
57
|
+
export function setVehicleProps(vehicle: number, props: VehicleProps): void {
|
|
58
|
+
SetVehicleModKit(vehicle, 0);
|
|
59
|
+
SetVehicleNumberPlateText(vehicle, props.plate);
|
|
60
|
+
SetVehicleNumberPlateTextIndex(vehicle, props.plateIndex);
|
|
61
|
+
SetVehicleColours(vehicle, props.colors[0], props.colors[1]);
|
|
62
|
+
SetVehicleExtraColours(vehicle, props.extraColors[0], props.extraColors[1]);
|
|
63
|
+
if (props.customPrimary)
|
|
64
|
+
SetVehicleCustomPrimaryColour(vehicle, ...props.customPrimary);
|
|
65
|
+
if (props.customSecondary)
|
|
66
|
+
SetVehicleCustomSecondaryColour(vehicle, ...props.customSecondary);
|
|
67
|
+
SetVehicleWheelType(vehicle, props.wheelType);
|
|
68
|
+
SetVehicleWindowTint(vehicle, props.windowTint);
|
|
69
|
+
for (const [type, index] of Object.entries(props.mods)) {
|
|
70
|
+
const t = Number(type);
|
|
71
|
+
if (TOGGLE_MODS.includes(t)) ToggleVehicleMod(vehicle, t, index === 1);
|
|
72
|
+
else SetVehicleMod(vehicle, t, index, false);
|
|
73
|
+
}
|
|
74
|
+
SetVehicleLivery(vehicle, props.livery);
|
|
75
|
+
SetVehicleXenonLightsColor(vehicle, props.xenonColor);
|
|
76
|
+
props.neon.forEach((on, i) => SetVehicleNeonLightEnabled(vehicle, i, on));
|
|
77
|
+
SetVehicleNeonLightsColour(vehicle, ...props.neonColor);
|
|
78
|
+
SetVehicleTyreSmokeColor(vehicle, ...props.tyreSmoke);
|
|
79
|
+
for (const [id, on] of Object.entries(props.extras))
|
|
80
|
+
SetVehicleExtra(vehicle, Number(id), !on);
|
|
81
|
+
SetVehicleDirtLevel(vehicle, props.dirt);
|
|
82
|
+
SetVehicleEngineHealth(vehicle, props.engineHealth);
|
|
83
|
+
SetVehicleBodyHealth(vehicle, props.bodyHealth);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** Engine, brakes, transmission, suspension, armour: the mods `maxed` sets to their top level. */
|
|
87
|
+
const PERFORMANCE_MODS = [11, 12, 13, 15, 16];
|
|
88
|
+
|
|
89
|
+
/** Applies a spawn setup (only to a vehicle this client controls). */
|
|
90
|
+
export function setVehicleSetup(vehicle: number, setup: VehicleSetup): void {
|
|
91
|
+
SetVehicleModKit(vehicle, 0);
|
|
92
|
+
if (setup.maxed) {
|
|
93
|
+
for (const mod of PERFORMANCE_MODS)
|
|
94
|
+
SetVehicleMod(vehicle, mod, GetNumVehicleMods(vehicle, mod) - 1, false);
|
|
95
|
+
ToggleVehicleMod(vehicle, 18, true);
|
|
96
|
+
ToggleVehicleMod(vehicle, 22, true);
|
|
97
|
+
}
|
|
98
|
+
if (setup.colors) SetVehicleColours(vehicle, ...setup.colors);
|
|
99
|
+
if (setup.primary) SetVehicleCustomPrimaryColour(vehicle, ...setup.primary);
|
|
100
|
+
if (setup.secondary)
|
|
101
|
+
SetVehicleCustomSecondaryColour(vehicle, ...setup.secondary);
|
|
102
|
+
if (setup.livery !== undefined) SetVehicleLivery(vehicle, setup.livery);
|
|
103
|
+
if (setup.windowTint !== undefined)
|
|
104
|
+
SetVehicleWindowTint(vehicle, setup.windowTint);
|
|
105
|
+
if (setup.dirt !== undefined) SetVehicleDirtLevel(vehicle, setup.dirt);
|
|
106
|
+
if (setup.engineOn) SetVehicleEngineOn(vehicle, true, true, false);
|
|
107
|
+
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Callback wire format, the same on both sides:
|
|
3
|
-
* request `aicore:cb:<name>` (callerResource, id, ...args)
|
|
4
|
-
* response `aicore:cbr:<callerResource>` (id, ok, result)
|
|
5
|
-
* The response goes only to the resource that asked, so two resources never see each other's replies.
|
|
6
|
-
*/
|
|
7
|
-
export const requestEvent = (name: string): string => `aicore:cb:${name}`;
|
|
8
|
-
export const responseEvent = (resource: string): string =>
|
|
9
|
-
`aicore:cbr:${resource}`;
|
|
10
|
-
|
|
11
|
-
/** Default time a caller waits for an answer before the promise rejects. */
|
|
12
|
-
export const DEFAULT_CALLBACK_TIMEOUT = 30_000;
|
|
1
|
+
/**
|
|
2
|
+
* Callback wire format, the same on both sides:
|
|
3
|
+
* request `aicore:cb:<name>` (callerResource, id, ...args)
|
|
4
|
+
* response `aicore:cbr:<callerResource>` (id, ok, result)
|
|
5
|
+
* The response goes only to the resource that asked, so two resources never see each other's replies.
|
|
6
|
+
*/
|
|
7
|
+
export const requestEvent = (name: string): string => `aicore:cb:${name}`;
|
|
8
|
+
export const responseEvent = (resource: string): string =>
|
|
9
|
+
`aicore:cbr:${resource}`;
|
|
10
|
+
|
|
11
|
+
/** Default time a caller waits for an answer before the promise rejects. */
|
|
12
|
+
export const DEFAULT_CALLBACK_TIMEOUT = 30_000;
|