@aifivem/shared 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/package.json +1 -1
- package/src/action.ts +6 -6
- package/src/commands.ts +80 -80
- package/src/core.ts +125 -125
- package/src/dispatch.ts +103 -103
- package/src/logs.ts +45 -45
- package/src/menu.ts +94 -94
- package/src/minigame.ts +45 -45
- package/src/phone.ts +39 -39
- package/src/player.ts +159 -159
- package/src/radial.ts +44 -44
- package/src/validation.ts +82 -82
- package/src/vehicleKeys.ts +64 -64
- package/src/vrp.ts +51 -51
- package/src/world.ts +26 -26
package/src/dispatch.ts
CHANGED
|
@@ -1,103 +1,103 @@
|
|
|
1
|
-
/** A point on the map. */
|
|
2
|
-
export interface DispatchCoords {
|
|
3
|
-
x: number;
|
|
4
|
-
y: number;
|
|
5
|
-
z: number;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* A police (or other job) alert a script sends through ai-core's dispatch layer (lib `dispatch.alert`); the active
|
|
10
|
-
* alert system shows it to the on-duty members of `jobs`. Texts are already translated.
|
|
11
|
-
*/
|
|
12
|
-
export interface DispatchAlert {
|
|
13
|
-
/** Radio code shown before the title ("10-71"). */
|
|
14
|
-
code?: string;
|
|
15
|
-
/** The headline ("Shots fired"). */
|
|
16
|
-
title: string;
|
|
17
|
-
/** One more line (the shop's name). */
|
|
18
|
-
message?: string;
|
|
19
|
-
/** Where it happened; without it the `source` player's position, else no map point. */
|
|
20
|
-
coords?: DispatchCoords;
|
|
21
|
-
/** Jobs whose on-duty members get it; default: the alert system's police jobs. */
|
|
22
|
-
jobs?: string[];
|
|
23
|
-
/** The player the alert is about (shooter, robber): systems that describe the suspect (vehicle, gender) read this player. */
|
|
24
|
-
source?: number;
|
|
25
|
-
/** Map blip: a GTA blip sprite and colour (default: the alert system's). */
|
|
26
|
-
blip?: { sprite: number; color?: number; scale?: number };
|
|
27
|
-
/** Seconds the alert stays (card, blip, waypoint key); default: the alert system's own. */
|
|
28
|
-
duration?: number;
|
|
29
|
-
/** Font Awesome solid icon name without `fa-` ("gun"). */
|
|
30
|
-
icon?: string;
|
|
31
|
-
/** `high` makes the card stand out (armed robbery, officer down). */
|
|
32
|
-
priority?: "normal" | "high";
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/** One alert system behind ai-core's dispatch layer (server side). */
|
|
36
|
-
export interface DispatchAdapter {
|
|
37
|
-
resource: string;
|
|
38
|
-
/** The version the adapter is written for; ai-core warns when another one runs. Absent for ai-* systems. */
|
|
39
|
-
version?: string;
|
|
40
|
-
/** `coords` is filled from `source` when the caller left it out. */
|
|
41
|
-
alert(alert: DispatchAlert): void;
|
|
42
|
-
/** The system answers QB's `police:server:policeAlert` event itself: ai-core leaves that event to it. */
|
|
43
|
-
answersPoliceAlert?: boolean;
|
|
44
|
-
/** Runs next to ai-policealert on purpose (an MDT with alerts): it does not make ai-policealert unneeded. */
|
|
45
|
-
besideOurs?: boolean;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
const text = (v: unknown, max: number): string | undefined =>
|
|
49
|
-
typeof v === "string" && v.trim() ? v.trim().slice(0, max) : undefined;
|
|
50
|
-
const finite = (v: unknown): v is number =>
|
|
51
|
-
typeof v === "number" && Number.isFinite(v);
|
|
52
|
-
const obj = (v: unknown): Record<string, unknown> | null =>
|
|
53
|
-
typeof v === "object" && v !== null && !Array.isArray(v)
|
|
54
|
-
? (v as Record<string, unknown>)
|
|
55
|
-
: null;
|
|
56
|
-
|
|
57
|
-
/** An alert from untrusted input (another resource's export call); null without a title. Extra fields drop. */
|
|
58
|
-
export function toDispatchAlert(value: unknown): DispatchAlert | null {
|
|
59
|
-
const v = obj(value);
|
|
60
|
-
const title = text(v?.title, 80);
|
|
61
|
-
if (!v || !title) return null;
|
|
62
|
-
const c = obj(v.coords);
|
|
63
|
-
const b = obj(v.blip);
|
|
64
|
-
const jobs = Array.isArray(v.jobs)
|
|
65
|
-
? v.jobs
|
|
66
|
-
.filter((j): j is string => typeof j === "string" && j.length <= 32)
|
|
67
|
-
.slice(0, 10)
|
|
68
|
-
: [];
|
|
69
|
-
return {
|
|
70
|
-
code: text(v.code, 12),
|
|
71
|
-
title,
|
|
72
|
-
message: text(v.message, 160),
|
|
73
|
-
coords:
|
|
74
|
-
c && finite(c.x) && finite(c.y) && finite(c.z)
|
|
75
|
-
? { x: c.x, y: c.y, z: c.z }
|
|
76
|
-
: undefined,
|
|
77
|
-
jobs: jobs.length ? jobs : undefined,
|
|
78
|
-
source:
|
|
79
|
-
finite(v.source) && Number.isInteger(v.source) && v.source > 0
|
|
80
|
-
? v.source
|
|
81
|
-
: undefined,
|
|
82
|
-
blip:
|
|
83
|
-
b && finite(b.sprite)
|
|
84
|
-
? {
|
|
85
|
-
sprite: Math.trunc(b.sprite),
|
|
86
|
-
color: finite(b.color) ? Math.trunc(b.color) : undefined,
|
|
87
|
-
scale: finite(b.scale)
|
|
88
|
-
? Math.min(3, Math.max(0.1, b.scale))
|
|
89
|
-
: undefined,
|
|
90
|
-
}
|
|
91
|
-
: undefined,
|
|
92
|
-
duration: finite(v.duration)
|
|
93
|
-
? Math.min(3600, Math.max(1, Math.round(v.duration)))
|
|
94
|
-
: undefined,
|
|
95
|
-
icon: text(v.icon, 40),
|
|
96
|
-
priority: v.priority === "high" ? "high" : "normal",
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
/** ai-core's dispatch export: whatever alert system runs shows the alert (none: false). */
|
|
101
|
-
export type DispatchServerExports = {
|
|
102
|
-
SendDispatchAlert(alert: DispatchAlert): boolean;
|
|
103
|
-
};
|
|
1
|
+
/** A point on the map. */
|
|
2
|
+
export interface DispatchCoords {
|
|
3
|
+
x: number;
|
|
4
|
+
y: number;
|
|
5
|
+
z: number;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* A police (or other job) alert a script sends through ai-core's dispatch layer (lib `dispatch.alert`); the active
|
|
10
|
+
* alert system shows it to the on-duty members of `jobs`. Texts are already translated.
|
|
11
|
+
*/
|
|
12
|
+
export interface DispatchAlert {
|
|
13
|
+
/** Radio code shown before the title ("10-71"). */
|
|
14
|
+
code?: string;
|
|
15
|
+
/** The headline ("Shots fired"). */
|
|
16
|
+
title: string;
|
|
17
|
+
/** One more line (the shop's name). */
|
|
18
|
+
message?: string;
|
|
19
|
+
/** Where it happened; without it the `source` player's position, else no map point. */
|
|
20
|
+
coords?: DispatchCoords;
|
|
21
|
+
/** Jobs whose on-duty members get it; default: the alert system's police jobs. */
|
|
22
|
+
jobs?: string[];
|
|
23
|
+
/** The player the alert is about (shooter, robber): systems that describe the suspect (vehicle, gender) read this player. */
|
|
24
|
+
source?: number;
|
|
25
|
+
/** Map blip: a GTA blip sprite and colour (default: the alert system's). */
|
|
26
|
+
blip?: { sprite: number; color?: number; scale?: number };
|
|
27
|
+
/** Seconds the alert stays (card, blip, waypoint key); default: the alert system's own. */
|
|
28
|
+
duration?: number;
|
|
29
|
+
/** Font Awesome solid icon name without `fa-` ("gun"). */
|
|
30
|
+
icon?: string;
|
|
31
|
+
/** `high` makes the card stand out (armed robbery, officer down). */
|
|
32
|
+
priority?: "normal" | "high";
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** One alert system behind ai-core's dispatch layer (server side). */
|
|
36
|
+
export interface DispatchAdapter {
|
|
37
|
+
resource: string;
|
|
38
|
+
/** The version the adapter is written for; ai-core warns when another one runs. Absent for ai-* systems. */
|
|
39
|
+
version?: string;
|
|
40
|
+
/** `coords` is filled from `source` when the caller left it out. */
|
|
41
|
+
alert(alert: DispatchAlert): void;
|
|
42
|
+
/** The system answers QB's `police:server:policeAlert` event itself: ai-core leaves that event to it. */
|
|
43
|
+
answersPoliceAlert?: boolean;
|
|
44
|
+
/** Runs next to ai-policealert on purpose (an MDT with alerts): it does not make ai-policealert unneeded. */
|
|
45
|
+
besideOurs?: boolean;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const text = (v: unknown, max: number): string | undefined =>
|
|
49
|
+
typeof v === "string" && v.trim() ? v.trim().slice(0, max) : undefined;
|
|
50
|
+
const finite = (v: unknown): v is number =>
|
|
51
|
+
typeof v === "number" && Number.isFinite(v);
|
|
52
|
+
const obj = (v: unknown): Record<string, unknown> | null =>
|
|
53
|
+
typeof v === "object" && v !== null && !Array.isArray(v)
|
|
54
|
+
? (v as Record<string, unknown>)
|
|
55
|
+
: null;
|
|
56
|
+
|
|
57
|
+
/** An alert from untrusted input (another resource's export call); null without a title. Extra fields drop. */
|
|
58
|
+
export function toDispatchAlert(value: unknown): DispatchAlert | null {
|
|
59
|
+
const v = obj(value);
|
|
60
|
+
const title = text(v?.title, 80);
|
|
61
|
+
if (!v || !title) return null;
|
|
62
|
+
const c = obj(v.coords);
|
|
63
|
+
const b = obj(v.blip);
|
|
64
|
+
const jobs = Array.isArray(v.jobs)
|
|
65
|
+
? v.jobs
|
|
66
|
+
.filter((j): j is string => typeof j === "string" && j.length <= 32)
|
|
67
|
+
.slice(0, 10)
|
|
68
|
+
: [];
|
|
69
|
+
return {
|
|
70
|
+
code: text(v.code, 12),
|
|
71
|
+
title,
|
|
72
|
+
message: text(v.message, 160),
|
|
73
|
+
coords:
|
|
74
|
+
c && finite(c.x) && finite(c.y) && finite(c.z)
|
|
75
|
+
? { x: c.x, y: c.y, z: c.z }
|
|
76
|
+
: undefined,
|
|
77
|
+
jobs: jobs.length ? jobs : undefined,
|
|
78
|
+
source:
|
|
79
|
+
finite(v.source) && Number.isInteger(v.source) && v.source > 0
|
|
80
|
+
? v.source
|
|
81
|
+
: undefined,
|
|
82
|
+
blip:
|
|
83
|
+
b && finite(b.sprite)
|
|
84
|
+
? {
|
|
85
|
+
sprite: Math.trunc(b.sprite),
|
|
86
|
+
color: finite(b.color) ? Math.trunc(b.color) : undefined,
|
|
87
|
+
scale: finite(b.scale)
|
|
88
|
+
? Math.min(3, Math.max(0.1, b.scale))
|
|
89
|
+
: undefined,
|
|
90
|
+
}
|
|
91
|
+
: undefined,
|
|
92
|
+
duration: finite(v.duration)
|
|
93
|
+
? Math.min(3600, Math.max(1, Math.round(v.duration)))
|
|
94
|
+
: undefined,
|
|
95
|
+
icon: text(v.icon, 40),
|
|
96
|
+
priority: v.priority === "high" ? "high" : "normal",
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** ai-core's dispatch export: whatever alert system runs shows the alert (none: false). */
|
|
101
|
+
export type DispatchServerExports = {
|
|
102
|
+
SendDispatchAlert(alert: DispatchAlert): boolean;
|
|
103
|
+
};
|
package/src/logs.ts
CHANGED
|
@@ -1,45 +1,45 @@
|
|
|
1
|
-
/** Log contracts: every ai-* resource logs through ai-core, which sends to the providers turned on in its panel. */
|
|
2
|
-
|
|
3
|
-
export type LogLevel = "debug" | "info" | "warn" | "error";
|
|
4
|
-
|
|
5
|
-
export interface LogOptions {
|
|
6
|
-
level?: LogLevel;
|
|
7
|
-
/** The player who did it (server id); their name, character and identifiers are added. */
|
|
8
|
-
source?: number;
|
|
9
|
-
/** The player it was done to. */
|
|
10
|
-
target?: number;
|
|
11
|
-
/** Extra fields (amounts, item names, coordinates...). */
|
|
12
|
-
metadata?: Record<string, unknown>;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
/** How a resource describes one of its log channels. Webhook urls are never here: they live in ai-core's panel-edited data/secrets.json. */
|
|
16
|
-
export interface LogChannel {
|
|
17
|
-
/** Dataset name for Fivemanage / FiveM Stats (default: the resource name). */
|
|
18
|
-
dataset?: string;
|
|
19
|
-
/** false turns the channel off. */
|
|
20
|
-
active?: boolean;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export interface LogPlayer {
|
|
24
|
-
serverId: number;
|
|
25
|
-
name: string;
|
|
26
|
-
identifiers: Record<string, string>;
|
|
27
|
-
citizenid?: string;
|
|
28
|
-
character?: string;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/** What every provider receives. */
|
|
32
|
-
export interface LogEntry {
|
|
33
|
-
resource: string;
|
|
34
|
-
channel: string;
|
|
35
|
-
level: LogLevel;
|
|
36
|
-
message: string;
|
|
37
|
-
/** Unix seconds. */
|
|
38
|
-
time: number;
|
|
39
|
-
dataset: string;
|
|
40
|
-
source?: number;
|
|
41
|
-
target?: number;
|
|
42
|
-
player?: LogPlayer;
|
|
43
|
-
targetPlayer?: LogPlayer;
|
|
44
|
-
metadata: Record<string, unknown>;
|
|
45
|
-
}
|
|
1
|
+
/** Log contracts: every ai-* resource logs through ai-core, which sends to the providers turned on in its panel. */
|
|
2
|
+
|
|
3
|
+
export type LogLevel = "debug" | "info" | "warn" | "error";
|
|
4
|
+
|
|
5
|
+
export interface LogOptions {
|
|
6
|
+
level?: LogLevel;
|
|
7
|
+
/** The player who did it (server id); their name, character and identifiers are added. */
|
|
8
|
+
source?: number;
|
|
9
|
+
/** The player it was done to. */
|
|
10
|
+
target?: number;
|
|
11
|
+
/** Extra fields (amounts, item names, coordinates...). */
|
|
12
|
+
metadata?: Record<string, unknown>;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** How a resource describes one of its log channels. Webhook urls are never here: they live in ai-core's panel-edited data/secrets.json. */
|
|
16
|
+
export interface LogChannel {
|
|
17
|
+
/** Dataset name for Fivemanage / FiveM Stats (default: the resource name). */
|
|
18
|
+
dataset?: string;
|
|
19
|
+
/** false turns the channel off. */
|
|
20
|
+
active?: boolean;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface LogPlayer {
|
|
24
|
+
serverId: number;
|
|
25
|
+
name: string;
|
|
26
|
+
identifiers: Record<string, string>;
|
|
27
|
+
citizenid?: string;
|
|
28
|
+
character?: string;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** What every provider receives. */
|
|
32
|
+
export interface LogEntry {
|
|
33
|
+
resource: string;
|
|
34
|
+
channel: string;
|
|
35
|
+
level: LogLevel;
|
|
36
|
+
message: string;
|
|
37
|
+
/** Unix seconds. */
|
|
38
|
+
time: number;
|
|
39
|
+
dataset: string;
|
|
40
|
+
source?: number;
|
|
41
|
+
target?: number;
|
|
42
|
+
player?: LogPlayer;
|
|
43
|
+
targetPlayer?: LogPlayer;
|
|
44
|
+
metadata: Record<string, unknown>;
|
|
45
|
+
}
|
package/src/menu.ts
CHANGED
|
@@ -1,94 +1,94 @@
|
|
|
1
|
-
/** Shared menu and input dialog contract (ai-core draws them for every resource through lib `menu` / `input`). */
|
|
2
|
-
|
|
3
|
-
export interface MenuItem {
|
|
4
|
-
id: string;
|
|
5
|
-
label: string;
|
|
6
|
-
/** Font Awesome solid icon name without `fa-`. */
|
|
7
|
-
icon?: string;
|
|
8
|
-
description?: string;
|
|
9
|
-
disabled?: boolean;
|
|
10
|
-
/** A switch row: picking it flips the switch in place and the menu stays open (`menu`'s `onToggle` hears it). */
|
|
11
|
-
checked?: boolean;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export interface MenuRequest {
|
|
15
|
-
title: string;
|
|
16
|
-
items: MenuItem[];
|
|
17
|
-
/** A sub menu: a short Escape answers `MENU_BACK` (the caller opens the menu before), holding Escape closes. */
|
|
18
|
-
back?: boolean;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/** ai-core's item picker (admin tools): every item of the active inventory with its picture, search and a count. */
|
|
22
|
-
export interface ItemPickerRequest {
|
|
23
|
-
title: string;
|
|
24
|
-
/** Whose inventory the items go to (server id): its free weight caps the list. The picking admin when absent. */
|
|
25
|
-
target?: number;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/** One item the picker shows. */
|
|
29
|
-
export interface PickerItem {
|
|
30
|
-
name: string;
|
|
31
|
-
label: string;
|
|
32
|
-
image?: string;
|
|
33
|
-
/** Weight of one, in the inventory's unit (grams for ai-inventory and ox_inventory). */
|
|
34
|
-
weight: number;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/** One row of the picker's list: what the player asked for. */
|
|
38
|
-
export interface PickedItem {
|
|
39
|
-
name: string;
|
|
40
|
-
count: number;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/** What the picker gets from the server: the items, and the target's weight when the inventory can tell it. */
|
|
44
|
-
export interface ItemPickerData {
|
|
45
|
-
items: PickerItem[];
|
|
46
|
-
room: { weight: number; maxWeight: number } | null;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/** Callback (admins only): (target: number | null) -> ItemPickerData. */
|
|
50
|
-
export const ITEM_PICKER_CALLBACK = "ai-core:admin:items";
|
|
51
|
-
|
|
52
|
-
/** What `menu()` resolves with when the player goes back from a sub menu (`back: true`). */
|
|
53
|
-
export const MENU_BACK = "__back";
|
|
54
|
-
|
|
55
|
-
export type InputField =
|
|
56
|
-
| {
|
|
57
|
-
name: string;
|
|
58
|
-
label: string;
|
|
59
|
-
type: "number";
|
|
60
|
-
min?: number;
|
|
61
|
-
max?: number;
|
|
62
|
-
placeholder?: string;
|
|
63
|
-
}
|
|
64
|
-
| {
|
|
65
|
-
name: string;
|
|
66
|
-
label: string;
|
|
67
|
-
type: "text";
|
|
68
|
-
maxLength?: number;
|
|
69
|
-
placeholder?: string;
|
|
70
|
-
/** A several-line text box (notes, descriptions). */
|
|
71
|
-
multiline?: boolean;
|
|
72
|
-
/** The text the field starts with. */
|
|
73
|
-
value?: string;
|
|
74
|
-
/** Shown, not edited (reading a note); an empty read-only field does not block the confirm. */
|
|
75
|
-
readOnly?: boolean;
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
export interface InputRequest {
|
|
79
|
-
title: string;
|
|
80
|
-
fields: InputField[];
|
|
81
|
-
/** Lang text of the confirm button (already translated). */
|
|
82
|
-
confirm: string;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
export const MENU_EVENTS = {
|
|
86
|
-
/** Client local: (resource, requestId, itemId | null) the player picked an item or closed the menu. */
|
|
87
|
-
menuResult: "ai-lib:client:menuResult",
|
|
88
|
-
/** Client local: (resource, requestId, itemId) the pointer or focus is on an item (previews). */
|
|
89
|
-
menuHover: "ai-lib:client:menuHover",
|
|
90
|
-
/** Client local: (resource, requestId, itemId, checked) the player flipped a switch row; the menu stays open. */
|
|
91
|
-
menuToggle: "ai-lib:client:menuToggle",
|
|
92
|
-
/** Client local: (resource, requestId, values | null) the player confirmed or closed the input dialog. */
|
|
93
|
-
inputResult: "ai-lib:client:inputResult",
|
|
94
|
-
} as const;
|
|
1
|
+
/** Shared menu and input dialog contract (ai-core draws them for every resource through lib `menu` / `input`). */
|
|
2
|
+
|
|
3
|
+
export interface MenuItem {
|
|
4
|
+
id: string;
|
|
5
|
+
label: string;
|
|
6
|
+
/** Font Awesome solid icon name without `fa-`. */
|
|
7
|
+
icon?: string;
|
|
8
|
+
description?: string;
|
|
9
|
+
disabled?: boolean;
|
|
10
|
+
/** A switch row: picking it flips the switch in place and the menu stays open (`menu`'s `onToggle` hears it). */
|
|
11
|
+
checked?: boolean;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface MenuRequest {
|
|
15
|
+
title: string;
|
|
16
|
+
items: MenuItem[];
|
|
17
|
+
/** A sub menu: a short Escape answers `MENU_BACK` (the caller opens the menu before), holding Escape closes. */
|
|
18
|
+
back?: boolean;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** ai-core's item picker (admin tools): every item of the active inventory with its picture, search and a count. */
|
|
22
|
+
export interface ItemPickerRequest {
|
|
23
|
+
title: string;
|
|
24
|
+
/** Whose inventory the items go to (server id): its free weight caps the list. The picking admin when absent. */
|
|
25
|
+
target?: number;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** One item the picker shows. */
|
|
29
|
+
export interface PickerItem {
|
|
30
|
+
name: string;
|
|
31
|
+
label: string;
|
|
32
|
+
image?: string;
|
|
33
|
+
/** Weight of one, in the inventory's unit (grams for ai-inventory and ox_inventory). */
|
|
34
|
+
weight: number;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** One row of the picker's list: what the player asked for. */
|
|
38
|
+
export interface PickedItem {
|
|
39
|
+
name: string;
|
|
40
|
+
count: number;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** What the picker gets from the server: the items, and the target's weight when the inventory can tell it. */
|
|
44
|
+
export interface ItemPickerData {
|
|
45
|
+
items: PickerItem[];
|
|
46
|
+
room: { weight: number; maxWeight: number } | null;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** Callback (admins only): (target: number | null) -> ItemPickerData. */
|
|
50
|
+
export const ITEM_PICKER_CALLBACK = "ai-core:admin:items";
|
|
51
|
+
|
|
52
|
+
/** What `menu()` resolves with when the player goes back from a sub menu (`back: true`). */
|
|
53
|
+
export const MENU_BACK = "__back";
|
|
54
|
+
|
|
55
|
+
export type InputField =
|
|
56
|
+
| {
|
|
57
|
+
name: string;
|
|
58
|
+
label: string;
|
|
59
|
+
type: "number";
|
|
60
|
+
min?: number;
|
|
61
|
+
max?: number;
|
|
62
|
+
placeholder?: string;
|
|
63
|
+
}
|
|
64
|
+
| {
|
|
65
|
+
name: string;
|
|
66
|
+
label: string;
|
|
67
|
+
type: "text";
|
|
68
|
+
maxLength?: number;
|
|
69
|
+
placeholder?: string;
|
|
70
|
+
/** A several-line text box (notes, descriptions). */
|
|
71
|
+
multiline?: boolean;
|
|
72
|
+
/** The text the field starts with. */
|
|
73
|
+
value?: string;
|
|
74
|
+
/** Shown, not edited (reading a note); an empty read-only field does not block the confirm. */
|
|
75
|
+
readOnly?: boolean;
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
export interface InputRequest {
|
|
79
|
+
title: string;
|
|
80
|
+
fields: InputField[];
|
|
81
|
+
/** Lang text of the confirm button (already translated). */
|
|
82
|
+
confirm: string;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export const MENU_EVENTS = {
|
|
86
|
+
/** Client local: (resource, requestId, itemId | null) the player picked an item or closed the menu. */
|
|
87
|
+
menuResult: "ai-lib:client:menuResult",
|
|
88
|
+
/** Client local: (resource, requestId, itemId) the pointer or focus is on an item (previews). */
|
|
89
|
+
menuHover: "ai-lib:client:menuHover",
|
|
90
|
+
/** Client local: (resource, requestId, itemId, checked) the player flipped a switch row; the menu stays open. */
|
|
91
|
+
menuToggle: "ai-lib:client:menuToggle",
|
|
92
|
+
/** Client local: (resource, requestId, values | null) the player confirmed or closed the input dialog. */
|
|
93
|
+
inputResult: "ai-lib:client:inputResult",
|
|
94
|
+
} as const;
|
package/src/minigame.ts
CHANGED
|
@@ -1,45 +1,45 @@
|
|
|
1
|
-
/** Minigames ai-core draws for every resource (lib `skillCheck` / `lockpick`); the answer arrives as `MENU_EVENTS.menuResult`. */
|
|
2
|
-
|
|
3
|
-
/** One ring of a skill check: the green arc's size in degrees and how many turns a second the needle makes. */
|
|
4
|
-
export interface SkillStage {
|
|
5
|
-
area: number;
|
|
6
|
-
speed: number;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
/** A named skill check stage (ox_lib's names) or ox_lib's `{ areaSize, speedMultiplier }`. */
|
|
10
|
-
export type SkillDifficulty =
|
|
11
|
-
"easy" | "medium" | "hard" | { areaSize: number; speedMultiplier: number };
|
|
12
|
-
|
|
13
|
-
export const SKILL_STAGES: Record<"easy" | "medium" | "hard", SkillStage> = {
|
|
14
|
-
easy: { area: 50, speed: 0.6 },
|
|
15
|
-
medium: { area: 40, speed: 0.85 },
|
|
16
|
-
hard: { area: 25, speed: 1 },
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
/** Lockpick difficulty: the sweet spot's width in degrees of the pick's half circle. */
|
|
20
|
-
export const LOCKPICK_AREAS: Record<"easy" | "medium" | "hard", number> = {
|
|
21
|
-
easy: 18,
|
|
22
|
-
medium: 11,
|
|
23
|
-
hard: 6,
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
export type LockpickResult = "opened" | "broken" | "cancelled";
|
|
27
|
-
|
|
28
|
-
export type MinigameRequest =
|
|
29
|
-
| { kind: "skillCheck"; stages: SkillStage[]; keys: string[] }
|
|
30
|
-
| { kind: "lockpick"; pins: number; area: number; picks: number };
|
|
31
|
-
|
|
32
|
-
/** A progress bar a server flow runs on a player's client (lib `progressFor`, ai-core's client draws it). */
|
|
33
|
-
export interface ServerProgress {
|
|
34
|
-
label: string;
|
|
35
|
-
/** Milliseconds. */
|
|
36
|
-
duration: number;
|
|
37
|
-
anim?: { dict: string; clip: string; flag?: number };
|
|
38
|
-
scenario?: string;
|
|
39
|
-
allowVehicle?: boolean;
|
|
40
|
-
canCancel?: boolean;
|
|
41
|
-
freeze?: boolean;
|
|
42
|
-
disable?: { move?: boolean; car?: boolean; mouse?: boolean; combat?: boolean };
|
|
43
|
-
/** The player turns to this point first. */
|
|
44
|
-
face?: { x: number; y: number; z: number };
|
|
45
|
-
}
|
|
1
|
+
/** Minigames ai-core draws for every resource (lib `skillCheck` / `lockpick`); the answer arrives as `MENU_EVENTS.menuResult`. */
|
|
2
|
+
|
|
3
|
+
/** One ring of a skill check: the green arc's size in degrees and how many turns a second the needle makes. */
|
|
4
|
+
export interface SkillStage {
|
|
5
|
+
area: number;
|
|
6
|
+
speed: number;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/** A named skill check stage (ox_lib's names) or ox_lib's `{ areaSize, speedMultiplier }`. */
|
|
10
|
+
export type SkillDifficulty =
|
|
11
|
+
"easy" | "medium" | "hard" | { areaSize: number; speedMultiplier: number };
|
|
12
|
+
|
|
13
|
+
export const SKILL_STAGES: Record<"easy" | "medium" | "hard", SkillStage> = {
|
|
14
|
+
easy: { area: 50, speed: 0.6 },
|
|
15
|
+
medium: { area: 40, speed: 0.85 },
|
|
16
|
+
hard: { area: 25, speed: 1 },
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
/** Lockpick difficulty: the sweet spot's width in degrees of the pick's half circle. */
|
|
20
|
+
export const LOCKPICK_AREAS: Record<"easy" | "medium" | "hard", number> = {
|
|
21
|
+
easy: 18,
|
|
22
|
+
medium: 11,
|
|
23
|
+
hard: 6,
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export type LockpickResult = "opened" | "broken" | "cancelled";
|
|
27
|
+
|
|
28
|
+
export type MinigameRequest =
|
|
29
|
+
| { kind: "skillCheck"; stages: SkillStage[]; keys: string[] }
|
|
30
|
+
| { kind: "lockpick"; pins: number; area: number; picks: number };
|
|
31
|
+
|
|
32
|
+
/** A progress bar a server flow runs on a player's client (lib `progressFor`, ai-core's client draws it). */
|
|
33
|
+
export interface ServerProgress {
|
|
34
|
+
label: string;
|
|
35
|
+
/** Milliseconds. */
|
|
36
|
+
duration: number;
|
|
37
|
+
anim?: { dict: string; clip: string; flag?: number };
|
|
38
|
+
scenario?: string;
|
|
39
|
+
allowVehicle?: boolean;
|
|
40
|
+
canCancel?: boolean;
|
|
41
|
+
freeze?: boolean;
|
|
42
|
+
disable?: { move?: boolean; car?: boolean; mouse?: boolean; combat?: boolean };
|
|
43
|
+
/** The player turns to this point first. */
|
|
44
|
+
face?: { x: number; y: number; z: number };
|
|
45
|
+
}
|
package/src/phone.ts
CHANGED
|
@@ -1,39 +1,39 @@
|
|
|
1
|
-
/** A mail a script sends to a player's phone. */
|
|
2
|
-
export interface PhoneMail {
|
|
3
|
-
/** Shown as the sender (a company, "Los Santos Customs"). */
|
|
4
|
-
sender: string;
|
|
5
|
-
subject: string;
|
|
6
|
-
message: string;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
/** A phone notification on a player's phone. */
|
|
10
|
-
export interface PhoneNotification {
|
|
11
|
-
title: string;
|
|
12
|
-
message: string;
|
|
13
|
-
/** Phone app id it belongs to when the phone knows it (`messages`, `mail`, `bank`). */
|
|
14
|
-
app?: string;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/** One phone script behind ai-core's phone layer (server side). */
|
|
18
|
-
export interface PhoneAdapter {
|
|
19
|
-
resource: string;
|
|
20
|
-
number(source: number): string | null;
|
|
21
|
-
sourceOf(number: string): number | null;
|
|
22
|
-
hasPhone(source: number): boolean;
|
|
23
|
-
/** `to` is a phone number (or the phone's mail address). */
|
|
24
|
-
mail(to: string, mail: PhoneMail): boolean;
|
|
25
|
-
/** A text from one number to another. */
|
|
26
|
-
message(from: string, to: string, text: string): boolean;
|
|
27
|
-
notify(source: number, notification: PhoneNotification): boolean;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/** ai-core's phone exports: whatever phone script runs answers (none: null / false). */
|
|
31
|
-
export type PhoneServerExports = {
|
|
32
|
-
GetPhoneNumber(source: number): string | null;
|
|
33
|
-
GetSourceByPhone(number: string): number | null;
|
|
34
|
-
HasPhone(source: number): boolean;
|
|
35
|
-
/** `to`: a player's server id or a phone number. */
|
|
36
|
-
SendPhoneMail(to: number | string, mail: PhoneMail): boolean;
|
|
37
|
-
SendPhoneMessage(from: string, to: number | string, text: string): boolean;
|
|
38
|
-
PhoneNotify(source: number, notification: PhoneNotification): boolean;
|
|
39
|
-
};
|
|
1
|
+
/** A mail a script sends to a player's phone. */
|
|
2
|
+
export interface PhoneMail {
|
|
3
|
+
/** Shown as the sender (a company, "Los Santos Customs"). */
|
|
4
|
+
sender: string;
|
|
5
|
+
subject: string;
|
|
6
|
+
message: string;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/** A phone notification on a player's phone. */
|
|
10
|
+
export interface PhoneNotification {
|
|
11
|
+
title: string;
|
|
12
|
+
message: string;
|
|
13
|
+
/** Phone app id it belongs to when the phone knows it (`messages`, `mail`, `bank`). */
|
|
14
|
+
app?: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** One phone script behind ai-core's phone layer (server side). */
|
|
18
|
+
export interface PhoneAdapter {
|
|
19
|
+
resource: string;
|
|
20
|
+
number(source: number): string | null;
|
|
21
|
+
sourceOf(number: string): number | null;
|
|
22
|
+
hasPhone(source: number): boolean;
|
|
23
|
+
/** `to` is a phone number (or the phone's mail address). */
|
|
24
|
+
mail(to: string, mail: PhoneMail): boolean;
|
|
25
|
+
/** A text from one number to another. */
|
|
26
|
+
message(from: string, to: string, text: string): boolean;
|
|
27
|
+
notify(source: number, notification: PhoneNotification): boolean;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** ai-core's phone exports: whatever phone script runs answers (none: null / false). */
|
|
31
|
+
export type PhoneServerExports = {
|
|
32
|
+
GetPhoneNumber(source: number): string | null;
|
|
33
|
+
GetSourceByPhone(number: string): number | null;
|
|
34
|
+
HasPhone(source: number): boolean;
|
|
35
|
+
/** `to`: a player's server id or a phone number. */
|
|
36
|
+
SendPhoneMail(to: number | string, mail: PhoneMail): boolean;
|
|
37
|
+
SendPhoneMessage(from: string, to: number | string, text: string): boolean;
|
|
38
|
+
PhoneNotify(source: number, notification: PhoneNotification): boolean;
|
|
39
|
+
};
|