@aifivem/shared 0.0.0-stage → 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 +23 -4
- package/src/action.ts +6 -0
- package/src/admin/dataSpec.ts +63 -0
- package/src/admin/events.ts +45 -0
- package/src/admin/lookups.ts +29 -0
- package/src/admin/panel.ts +105 -0
- package/src/admin/schema.ts +58 -0
- package/src/admin/widgets.ts +123 -0
- package/src/appearance.ts +115 -0
- package/src/banking.ts +58 -0
- package/src/bans.ts +91 -0
- package/src/billing.ts +112 -0
- package/src/characters.ts +71 -0
- package/src/commands.ts +80 -0
- package/src/core.ts +125 -0
- package/src/deaths.ts +44 -0
- package/src/definitions.ts +26 -0
- package/src/dispatch.ts +103 -0
- package/src/doorlock.ts +29 -0
- package/src/ems.ts +50 -0
- package/src/exports/aiInventory.ts +96 -0
- package/src/exports/citizen.ts +45 -0
- package/src/exports/coreCharacters.ts +167 -0
- package/src/exports/coreClient.ts +79 -0
- package/src/exports/coreGroups.ts +29 -0
- package/src/exports/coreLayers.ts +45 -0
- package/src/exports/coreMoney.ts +97 -0
- package/src/exports/coreServer.ts +91 -0
- package/src/exports/coreServices.ts +60 -0
- package/src/exports/resources.ts +107 -0
- package/src/fuel.ts +48 -0
- package/src/garages.ts +101 -0
- package/src/index.ts +49 -0
- package/src/inventory/adapters.ts +86 -0
- package/src/inventory/exports.ts +92 -0
- package/src/inventory/items.ts +92 -0
- package/src/logs.ts +45 -0
- package/src/mdt.ts +78 -0
- package/src/medical.ts +18 -0
- package/src/menu.ts +94 -0
- package/src/minigame.ts +45 -0
- package/src/multichar.ts +44 -0
- package/src/phone.ts +39 -0
- package/src/player.ts +159 -0
- package/src/radial.ts +44 -0
- package/src/ui.ts +92 -0
- package/src/validation.ts +82 -0
- package/src/vehicleKeys.ts +78 -0
- package/src/vehicles.ts +117 -0
- package/src/vrp.ts +51 -0
- package/src/world.ts +26 -0
- package/README.md +0 -3
package/src/bans.ts
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/** Identifier types a ban matches, as the connection gate sees them (values without the `type:` prefix). */
|
|
2
|
+
export const BAN_IDENTIFIERS = ["fivem", "license", "discord", "ip"] as const;
|
|
3
|
+
export type BanIdentifier = (typeof BAN_IDENTIFIERS)[number];
|
|
4
|
+
|
|
5
|
+
/** An active ban (`IsBanned`, `GetBans`). Times in epoch ms; `expires` null = permanent. */
|
|
6
|
+
export interface BanInfo {
|
|
7
|
+
/** 0 until the row is written (the ban already holds). */
|
|
8
|
+
id: number;
|
|
9
|
+
identifiers: Partial<Record<BanIdentifier, string>>;
|
|
10
|
+
/** The player's name when banned. */
|
|
11
|
+
name: string;
|
|
12
|
+
reason: string;
|
|
13
|
+
by: string;
|
|
14
|
+
created: number;
|
|
15
|
+
expires: number | null;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** Who to ban or check: an online player's server id, or identifiers (`license:abc` or `abc` under its type). */
|
|
19
|
+
export type BanTarget =
|
|
20
|
+
number | { identifiers: Partial<Record<BanIdentifier, string>> };
|
|
21
|
+
|
|
22
|
+
/** One page of active bans, newest first. */
|
|
23
|
+
export interface BansPage {
|
|
24
|
+
bans: BanInfo[];
|
|
25
|
+
total: number;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** A stored ban in any state (`GetBanHistory`, `ListBans`). Times in epoch ms. */
|
|
29
|
+
export interface BanRecord extends BanInfo {
|
|
30
|
+
/** When the ban was lifted, null while it was not. */
|
|
31
|
+
revoked: number | null;
|
|
32
|
+
revokedBy: string | null;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export type BanStatus = "active" | "expired" | "revoked";
|
|
36
|
+
|
|
37
|
+
/** A ban's state at `now` (epoch ms; a client passes the server's time, see `ServerClock`). */
|
|
38
|
+
export function banStatus(ban: BanRecord, now: number): BanStatus {
|
|
39
|
+
if (ban.revoked !== null) return "revoked";
|
|
40
|
+
return ban.expires !== null && ban.expires <= now ? "expired" : "active";
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** Which bans a list shows. */
|
|
44
|
+
export const BAN_FILTERS = ["active", "expired", "revoked", "all"] as const;
|
|
45
|
+
export type BanFilter = (typeof BAN_FILTERS)[number];
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Where a list page goes on: the last row's id, and its sort time (`revoked` for revoked bans, `expires` for expired
|
|
49
|
+
* ones; null for active and all, which sort by id).
|
|
50
|
+
*/
|
|
51
|
+
export interface BanCursor {
|
|
52
|
+
id: number;
|
|
53
|
+
at: number | null;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* A ban list query. `search`: a ban id or a number (`123`: ban id, fivem or discord), `fivem:` / `license:` /
|
|
58
|
+
* `discord:` / `ip:` + value, a 40-hex license, an IPv4, else a name prefix (2+ characters).
|
|
59
|
+
*/
|
|
60
|
+
export interface BanQuery {
|
|
61
|
+
filter?: BanFilter;
|
|
62
|
+
search?: string;
|
|
63
|
+
cursor?: BanCursor | null;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* One page of a ban list: active and all newest first, revoked by the time they were lifted, expired by the time
|
|
68
|
+
* they ended (latest first). `next` null on the last page.
|
|
69
|
+
*/
|
|
70
|
+
export interface BanListPage {
|
|
71
|
+
bans: BanRecord[];
|
|
72
|
+
next: BanCursor | null;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** A change to an active ban: a new reason, a new end counted from now (`minutes`; null = permanent). */
|
|
76
|
+
export interface BanEdit {
|
|
77
|
+
reason?: string;
|
|
78
|
+
minutes?: number | null;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** Ban lengths the admin tools offer (minutes; null = permanent); `id` names the lang key of each. */
|
|
82
|
+
export const BAN_DURATIONS = [
|
|
83
|
+
{ id: "1H", minutes: 60 },
|
|
84
|
+
{ id: "1D", minutes: 1440 },
|
|
85
|
+
{ id: "3D", minutes: 4320 },
|
|
86
|
+
{ id: "1W", minutes: 10_080 },
|
|
87
|
+
{ id: "2W", minutes: 20_160 },
|
|
88
|
+
{ id: "1M", minutes: 43_200 },
|
|
89
|
+
{ id: "3M", minutes: 129_600 },
|
|
90
|
+
{ id: "PERM", minutes: null },
|
|
91
|
+
] as const satisfies ReadonlyArray<{ id: string; minutes: number | null }>;
|
package/src/billing.ts
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A bill a script sends through ai-core's billing layer (lib `billing.send`): from a job (fines, service fees) or from
|
|
3
|
+
* a player, to a player. Texts are already translated.
|
|
4
|
+
*/
|
|
5
|
+
export interface BillRequest {
|
|
6
|
+
/** The player who gets the bill (server id); or `toCitizenid`. */
|
|
7
|
+
to?: number;
|
|
8
|
+
/**
|
|
9
|
+
* The character who gets the bill by citizen id, online or offline (instead of `to`). An offline character gets it
|
|
10
|
+
* only from ai-core's own bills; a billing script needs the player online.
|
|
11
|
+
*/
|
|
12
|
+
toCitizenid?: string;
|
|
13
|
+
/** Whole dollars. */
|
|
14
|
+
amount: number;
|
|
15
|
+
/** What it is for ("Speeding", "Engine repair"). */
|
|
16
|
+
label: string;
|
|
17
|
+
/** The player who issues it (officer, mechanic); a bill without `job` pays this player. */
|
|
18
|
+
from?: number;
|
|
19
|
+
/** The job whose account gets the payment; without it the bill is personal (`from` is then required). */
|
|
20
|
+
job?: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** A bill as an adapter gets it: the request with what ai-core knows about the players filled in. */
|
|
24
|
+
export interface BillSend extends BillRequest {
|
|
25
|
+
/** The recipient's server id (adapters only get bills to online players). */
|
|
26
|
+
to: number;
|
|
27
|
+
toCitizenid: string;
|
|
28
|
+
fromCitizenid?: string;
|
|
29
|
+
fromName?: string;
|
|
30
|
+
/** The job's label from ai-core's job definitions. */
|
|
31
|
+
jobLabel?: string;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** One open (unpaid) bill of a player. */
|
|
35
|
+
export interface UnpaidBill {
|
|
36
|
+
/** The billing script's own id or reference. */
|
|
37
|
+
id: string;
|
|
38
|
+
label: string;
|
|
39
|
+
/** What is still owed. */
|
|
40
|
+
amount: number;
|
|
41
|
+
/** Who sent it (job label or player name). */
|
|
42
|
+
sender: string;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** One billing script behind ai-core's billing layer (server side). */
|
|
46
|
+
export interface BillingAdapter {
|
|
47
|
+
resource: string;
|
|
48
|
+
/** The version the adapter is written for; ai-core warns when another one runs. Absent for ai-core's own bills. */
|
|
49
|
+
version?: string;
|
|
50
|
+
/** False when the script refused it or cannot send this kind (a personal bill, a bill without an issuer). */
|
|
51
|
+
send(bill: BillSend): boolean;
|
|
52
|
+
/** The player's open bills; `done(null)` when the script cannot list them. Absent = cannot list. */
|
|
53
|
+
unpaid?(
|
|
54
|
+
source: number,
|
|
55
|
+
citizenid: string,
|
|
56
|
+
done: (bills: UnpaidBill[] | null) => void,
|
|
57
|
+
): void;
|
|
58
|
+
/** The player pays one of their bills; absent when the script takes payments only in its own screen. */
|
|
59
|
+
pay?(source: number, id: string): boolean;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const text = (v: unknown, max: number): string | undefined =>
|
|
63
|
+
typeof v === "string" && v.trim() ? v.trim().slice(0, max) : undefined;
|
|
64
|
+
const id = (v: unknown): number | undefined =>
|
|
65
|
+
typeof v === "number" && Number.isInteger(v) && v > 0 ? v : undefined;
|
|
66
|
+
|
|
67
|
+
/** A bill from untrusted input (another resource's export call); null when it is not a valid bill. */
|
|
68
|
+
export function toBillRequest(value: unknown): BillRequest | null {
|
|
69
|
+
if (typeof value !== "object" || value === null || Array.isArray(value))
|
|
70
|
+
return null;
|
|
71
|
+
const v = value as Record<string, unknown>;
|
|
72
|
+
const to = id(v.to);
|
|
73
|
+
const toCitizenid =
|
|
74
|
+
typeof v.toCitizenid === "string" &&
|
|
75
|
+
/^[A-Za-z0-9]{1,16}$/.test(v.toCitizenid)
|
|
76
|
+
? v.toCitizenid
|
|
77
|
+
: undefined;
|
|
78
|
+
const label = text(v.label, 80);
|
|
79
|
+
const amount = v.amount;
|
|
80
|
+
if (
|
|
81
|
+
(to === undefined) === (toCitizenid === undefined) ||
|
|
82
|
+
!label ||
|
|
83
|
+
typeof amount !== "number" ||
|
|
84
|
+
!Number.isSafeInteger(amount) ||
|
|
85
|
+
amount < 1 ||
|
|
86
|
+
amount > 10_000_000
|
|
87
|
+
)
|
|
88
|
+
return null;
|
|
89
|
+
const from = id(v.from);
|
|
90
|
+
const job =
|
|
91
|
+
typeof v.job === "string" && /^[a-z0-9_]{2,32}$/.test(v.job)
|
|
92
|
+
? v.job
|
|
93
|
+
: undefined;
|
|
94
|
+
if (job === undefined && from === undefined) return null;
|
|
95
|
+
if (to !== undefined && from === to) return null;
|
|
96
|
+
return { to, toCitizenid, amount, label, from, job };
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** ai-core's billing exports: whatever billing script runs (ai-core's own bills without one). */
|
|
100
|
+
export type BillingServerExports = {
|
|
101
|
+
/** The billing script bills go to ("ai-core" for ai-core's own bills). */
|
|
102
|
+
GetBillingSystem(): string | null;
|
|
103
|
+
/** Sends a bill; false when it is invalid or the billing script refused it. */
|
|
104
|
+
SendBill(bill: BillRequest): boolean;
|
|
105
|
+
/** A player's open bills; `done(null)` when the billing script cannot list them. A callback: no promise crosses a resource boundary. */
|
|
106
|
+
GetUnpaidBills(
|
|
107
|
+
source: number,
|
|
108
|
+
done: (bills: UnpaidBill[] | null) => void,
|
|
109
|
+
): void;
|
|
110
|
+
/** The player pays one of their open bills; false when refused or the billing script takes payments only in its own screen. */
|
|
111
|
+
PayBill(source: number, id: string): boolean;
|
|
112
|
+
};
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import type { ActionResult } from "./action";
|
|
2
|
+
import type { CharacterInfo, GangMembership, JobMembership } from "./player";
|
|
3
|
+
|
|
4
|
+
/** A character with its account id (`ai_core_users.id`). */
|
|
5
|
+
export type CharacterWithUser = CharacterInfo & { userId: number };
|
|
6
|
+
|
|
7
|
+
/** A stored character of an account (`GetCharactersOfUser`); `lastPlayed` in epoch ms, null = never played. */
|
|
8
|
+
export interface StoredCharacter extends CharacterWithUser {
|
|
9
|
+
lastPlayed: number | null;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/** Everything ai-core keeps about one character, loaded or not (`GetOfflineCharacter`). */
|
|
13
|
+
export interface OfflineCharacter {
|
|
14
|
+
info: CharacterWithUser;
|
|
15
|
+
/** Balance by account type. */
|
|
16
|
+
money: Record<string, number>;
|
|
17
|
+
jobs: JobMembership[];
|
|
18
|
+
gangs: GangMembership[];
|
|
19
|
+
activeGang: string | null;
|
|
20
|
+
metadata: Record<string, unknown>;
|
|
21
|
+
position: { x: number; y: number; z: number; heading: number } | null;
|
|
22
|
+
/** Last save (epoch ms); null = never played. */
|
|
23
|
+
lastSeen: number | null;
|
|
24
|
+
/** The player's server id while the character is loaded, else null. */
|
|
25
|
+
source: number | null;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** One holder of a job or gang (`GetJobMembers` / `GetGangMembers`), loaded or not. */
|
|
29
|
+
export interface GroupMember {
|
|
30
|
+
charId: number;
|
|
31
|
+
citizenid: string;
|
|
32
|
+
firstname: string;
|
|
33
|
+
lastname: string;
|
|
34
|
+
grade: number;
|
|
35
|
+
/** The player's server id while the character is loaded, else null. */
|
|
36
|
+
source: number | null;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** A page of members by character id; `next` is the `after` of the next page, null on the last one. */
|
|
40
|
+
export interface MembersPage {
|
|
41
|
+
members: GroupMember[];
|
|
42
|
+
next: number | null;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** A character a search found, loaded or not. */
|
|
46
|
+
export interface CharacterMatch {
|
|
47
|
+
charId: number;
|
|
48
|
+
citizenid: string;
|
|
49
|
+
firstname: string;
|
|
50
|
+
lastname: string;
|
|
51
|
+
/** The player's server id while the character is loaded, else null. */
|
|
52
|
+
source: number | null;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** A page of a character search, newest characters first; `next` is the `cursor` of the next page, null on the last. */
|
|
56
|
+
export interface CharacterSearchPage {
|
|
57
|
+
characters: CharacterMatch[];
|
|
58
|
+
next: number | null;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** What a character write answers: ok, or a lang key of ai-core (`locales/en.json`). */
|
|
62
|
+
export type CharacterResult = ActionResult;
|
|
63
|
+
|
|
64
|
+
/** The character fields `SetCharacterInfo` changes; each one is checked like the creation form. */
|
|
65
|
+
export interface CharacterInfoPatch {
|
|
66
|
+
firstname?: string;
|
|
67
|
+
lastname?: string;
|
|
68
|
+
birthdate?: string;
|
|
69
|
+
nationality?: string;
|
|
70
|
+
sex?: "male" | "female";
|
|
71
|
+
}
|
package/src/commands.ts
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Commands and keybinds: what every resource announces to ai-core (lib `addCommand` and `Keybind`) so the admin panel
|
|
3
|
+
* lists them and sets keybind defaults.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export type CommandParamType = "number" | "playerId" | "string" | "longString";
|
|
7
|
+
|
|
8
|
+
/** One argument of a command, parsed and checked before the handler runs. */
|
|
9
|
+
export interface CommandParam {
|
|
10
|
+
/** Name in the usage line, the chat suggestion and the handler's `args`. */
|
|
11
|
+
name: string;
|
|
12
|
+
/** number: any number; playerId: the server id of an online player; string: one word; longString: the rest of the line (last param). */
|
|
13
|
+
type: CommandParamType;
|
|
14
|
+
/** Lang text shown in the chat suggestion. */
|
|
15
|
+
help?: string;
|
|
16
|
+
optional?: boolean;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** A command of the lib's `addCommand`, as the resource announces it to ai-core. */
|
|
20
|
+
export interface CommandInfo {
|
|
21
|
+
/** The first is the name, the rest are aliases. */
|
|
22
|
+
names: string[];
|
|
23
|
+
help: string;
|
|
24
|
+
params: CommandParam[];
|
|
25
|
+
/** null: everyone; otherwise the aces any of which allows it (`command.<name>` always allows too). */
|
|
26
|
+
aces: string[] | null;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** A keybind of the lib's `Keybind`, as the resource announces it to ai-core's client. */
|
|
30
|
+
export interface KeybindInfo {
|
|
31
|
+
resource: string;
|
|
32
|
+
/** Stable id; the key mapping command is `<name>_<key>`. */
|
|
33
|
+
name: string;
|
|
34
|
+
/** Lang text shown in GTA's key settings. */
|
|
35
|
+
description: string;
|
|
36
|
+
/** The script's own default key ("" = none). */
|
|
37
|
+
defaultKey: string;
|
|
38
|
+
/** RegisterKeyMapping input mapper ("keyboard", "MOUSE_BUTTON", "PAD_DIGITALBUTTON"). */
|
|
39
|
+
mapper: string;
|
|
40
|
+
/** When HUDs list it in their key hints (the owner can change it in the panel); absent = never. */
|
|
41
|
+
hint?: KeyHintWhen;
|
|
42
|
+
/** Font Awesome solid icon name (without `fa-`) next to the hint. */
|
|
43
|
+
icon?: string;
|
|
44
|
+
/** A short text for the hint (one or two words); the description when absent. */
|
|
45
|
+
hintLabel?: string;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** When a key hint shows: on foot, in a vehicle, or always. */
|
|
49
|
+
export type KeyHintWhen = "foot" | "vehicle" | "always";
|
|
50
|
+
|
|
51
|
+
/** One row of the key hints HUDs show: the key as the player has it bound, and what it does (translated). */
|
|
52
|
+
export interface KeyHintView {
|
|
53
|
+
id: string;
|
|
54
|
+
key: string;
|
|
55
|
+
label: string;
|
|
56
|
+
/** Font Awesome solid icon name without `fa-`; HUDs draw a key icon when they do not know it. */
|
|
57
|
+
icon?: string;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** A hint a script shows for a while (admin noclip keys): a keybind's current key, or a literal key text. */
|
|
61
|
+
export interface KeyHintRequest {
|
|
62
|
+
label: string;
|
|
63
|
+
keybind?: string;
|
|
64
|
+
key?: string;
|
|
65
|
+
/** Font Awesome solid icon name without `fa-`. */
|
|
66
|
+
icon?: string;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export const KEY_HINTS = {
|
|
70
|
+
/** ai-core client -> HUDs (local): (KeyHintView[]) the hints to show now, after every change. */
|
|
71
|
+
changedEvent: "ai-core:client:keyHints",
|
|
72
|
+
} as const;
|
|
73
|
+
|
|
74
|
+
/** Client local events between the lib's `Keybind` and ai-core's client. */
|
|
75
|
+
export const KEYBIND = {
|
|
76
|
+
/** lib -> ai-core: (info: KeybindInfo) a keybind waits for its default key. */
|
|
77
|
+
announceEvent: "ai-core:client:keybind",
|
|
78
|
+
/** ai-core -> lib: (resource, name, key) the default key to register: the panel's value, else the script's. */
|
|
79
|
+
keyEvent: "ai-core:client:keybindKey",
|
|
80
|
+
} as const;
|
package/src/core.ts
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/** Names owned by ai-core that other resources, the bridges and the build step use. */
|
|
2
|
+
export const CORE = {
|
|
3
|
+
resource: "ai-core",
|
|
4
|
+
/** Client -> server: (resource: string, text: string). Sent by the reporter every client bundle carries. */
|
|
5
|
+
clientErrorEvent: "ai-core:clientError",
|
|
6
|
+
|
|
7
|
+
// Server local events (other resources and the bridges mirror player state from these deltas).
|
|
8
|
+
/** (src, character: CharacterInfo) after a character is loaded and spawned. */
|
|
9
|
+
playerLoadedEvent: "ai-core:playerLoaded",
|
|
10
|
+
/** (src, charId) the loaded character was sent into the world (after `playerLoaded`; after the pick when the player chooses where to appear). */
|
|
11
|
+
playerSpawnedEvent: "ai-core:playerSpawned",
|
|
12
|
+
/** (src, charId, reason: UnloadReason) before a character's state is dropped. */
|
|
13
|
+
playerUnloadedEvent: "ai-core:playerUnloaded",
|
|
14
|
+
/** (src, account: string, balance: number, delta: number, reason: string) */
|
|
15
|
+
moneyChangedEvent: "ai-core:moneyChanged",
|
|
16
|
+
/** (src, jobs: JobMembership[]) */
|
|
17
|
+
jobsChangedEvent: "ai-core:jobsChanged",
|
|
18
|
+
/** (src, job: string | null) */
|
|
19
|
+
dutyChangedEvent: "ai-core:dutyChanged",
|
|
20
|
+
/** (src, gangs: GangMembership[]) */
|
|
21
|
+
gangsChangedEvent: "ai-core:gangsChanged",
|
|
22
|
+
/** (src, gang: string | null) */
|
|
23
|
+
activeGangChangedEvent: "ai-core:activeGangChanged",
|
|
24
|
+
/** Server local: (src, key, value | null) a character metadata value changed. */
|
|
25
|
+
metaChangedEvent: "ai-core:metaChanged",
|
|
26
|
+
/** Server local: (file: "jobs" | "gangs", name) a job or gang definition changed (panel edit, or a script registered / removed one). */
|
|
27
|
+
definitionsChangedEvent: "ai-core:definitionsChanged",
|
|
28
|
+
/** Server local: (charId, userId) a character was deleted (soft delete: character screen, admin panel, `DeleteCharacter`). */
|
|
29
|
+
characterDeletedEvent: "ai-core:characterDeleted",
|
|
30
|
+
/** GlobalState prefixes: `<prefix><name>` = a job / gang definition a script registered (`RegisterJobDefinition`); panel ones are not here. */
|
|
31
|
+
runtimeJobPrefix: "ai:jobdef:",
|
|
32
|
+
runtimeGangPrefix: "ai:gangdef:",
|
|
33
|
+
/** (src, charIds: number[]) each time a player's character screen loads; ai-core sends the looks, a clothing script may answer with portraits. */
|
|
34
|
+
characterScreenEvent: "ai-core:characterScreen",
|
|
35
|
+
/** (resource: string | null) the inventory behind ai-core's inventory layer changed (the bridge drops its item cache). */
|
|
36
|
+
inventoryChangedEvent: "ai-core:inventoryChanged",
|
|
37
|
+
/** (src, name: string, status: Record<string, number> | null) a player used an item; status = the needs it gives, from inventories that define them. */
|
|
38
|
+
itemUsedEvent: "ai-core:itemUsed",
|
|
39
|
+
/** (src, killer: number | null, weaponHash: number, info: DeathInfo) a player with a loaded character died; fired from FXServer's `onPedDeath` (ai-core requires FXServer 38039+); `info` (`deaths.ts`) says who, how and from where, built on the server. */
|
|
40
|
+
playerDiedEvent: "ai-core:playerDied",
|
|
41
|
+
|
|
42
|
+
// Client local events (same payloads, for client scripts and bridges).
|
|
43
|
+
clientPlayerLoadedEvent: "ai-core:client:playerLoaded",
|
|
44
|
+
clientPlayerUnloadedEvent: "ai-core:client:playerUnloaded",
|
|
45
|
+
/** (charId: number, url: string) a portrait image of a character on the character screen (e.g. `https://nui-img/<txd>/<txd>`). */
|
|
46
|
+
clientCharacterPortraitEvent: "ai-core:client:characterPortrait",
|
|
47
|
+
/** Server -> client (latent): (looks: { id: number, look: CharacterAppearance }[]) the character screen's looks, read through the appearance layer; ai-core dresses its scene peds with them. */
|
|
48
|
+
characterLooksEvent: "ai-core:client:characterLooks",
|
|
49
|
+
/** (key: keyof PlayerCache, value) a cached value of the local player changed (one watcher in ai-core for every resource). */
|
|
50
|
+
clientCacheEvent: "ai-core:client:cache",
|
|
51
|
+
/** Client local event: (visible: boolean) HUDs show or hide (a full-screen UI opened or closed; lib `hud`). */
|
|
52
|
+
clientHudVisibleEvent: "ai-core:client:hudVisible",
|
|
53
|
+
/** Client local: (paused: boolean) the weather and time sync is paused (interiors, scenes) or runs again. */
|
|
54
|
+
clientWorldSyncEvent: "ai-core:client:worldSync",
|
|
55
|
+
/** Client local: (file: "jobs" | "gangs", name, definition | null) a job or gang definition changed. */
|
|
56
|
+
clientDefinitionsEvent: "ai-core:client:definitions",
|
|
57
|
+
/** Server -> client callback: (model: string) the `CreateVehicleServerSetter` type of a model, null when the game has no such vehicle (ai-core's client answers for every resource, lib `spawnVehicle`). */
|
|
58
|
+
vehicleTypeCallback: "ai-core:vehicleType",
|
|
59
|
+
/** GlobalState: "prompt" | "target", how lib `Points` let players interact (ai-core panel setting). */
|
|
60
|
+
interactionStateKey: "ai:interaction",
|
|
61
|
+
/** GlobalState: boolean, players can hurt each other (ai-core panel setting `pvp`, `/togglepvp`). */
|
|
62
|
+
pvpStateKey: "ai:pvp",
|
|
63
|
+
/** GlobalState: the resource name of the death script ai-core's medical layer uses (client adapter pick). */
|
|
64
|
+
medicalStateKey: "ai:medical",
|
|
65
|
+
/** Client local: (dead: boolean) the local player went down (dead or last stand) or got up, in any death script. */
|
|
66
|
+
clientDeadEvent: "ai-core:client:dead",
|
|
67
|
+
/** GlobalState: the resource name of the MDT ai-core's MDT layer uses (client adapter pick). */
|
|
68
|
+
mdtStateKey: "ai:mdt",
|
|
69
|
+
/** Server -> client: (bills: { id, label, amount, sender }[]) the player's open ai-core bills (a new one arrived, or at load); the client lists them to pay. */
|
|
70
|
+
billsEvent: "ai-core:client:bills",
|
|
71
|
+
/** Callback: (id) -> ActionResult the player pays one of their ai-core bills. */
|
|
72
|
+
payBillCallback: "ai-core:payBill",
|
|
73
|
+
/** Client local: (worn: boolean | null) the local player's seat belt changed, in whichever seat belt script runs. */
|
|
74
|
+
clientSeatbeltEvent: "ai-core:client:seatbelt",
|
|
75
|
+
/** Server -> client: (amount: number) stress for a HUD that takes it only from its player's client (QB `hud:server:*Stress`). */
|
|
76
|
+
stressRelayEvent: "ai-core:client:stress",
|
|
77
|
+
/** GlobalState: the resource name of the notification UI ai-lib's notifications go to (unset = ai-lib's own cards). */
|
|
78
|
+
notifyStateKey: "ai:notify",
|
|
79
|
+
|
|
80
|
+
// Callbacks (character screen).
|
|
81
|
+
charactersCallback: "ai-core:characters",
|
|
82
|
+
createCharacterCallback: "ai-core:createCharacter",
|
|
83
|
+
deleteCharacterCallback: "ai-core:deleteCharacter",
|
|
84
|
+
selectCharacterCallback: "ai-core:selectCharacter",
|
|
85
|
+
|
|
86
|
+
/** Server -> client: (spawn: SpawnPoint) puts the loaded character into the world. */
|
|
87
|
+
spawnEvent: "ai-core:client:spawn",
|
|
88
|
+
/** Server -> client: (options: { id, label, last }[]) the character is loaded; the player picks where to appear. */
|
|
89
|
+
chooseSpawnEvent: "ai-core:client:chooseSpawn",
|
|
90
|
+
/** Callback: (id) -> { ok } the picked spawn option (from `chooseSpawnEvent`); `spawnEvent` follows. */
|
|
91
|
+
spawnChoiceCallback: "ai-core:spawnChoice",
|
|
92
|
+
/** Server -> client: () the character was let go (switch); show the character screen again. */
|
|
93
|
+
openCharactersEvent: "ai-core:client:openCharacters",
|
|
94
|
+
/** GlobalState: the resource name of the external character screen (a multichar) while one runs; unset = ai-core's own screen. */
|
|
95
|
+
characterScreenKey: "ai:characterScreen",
|
|
96
|
+
/** Server -> client: (armour, health) the character loaded under an external character screen, which spawns the ped itself. */
|
|
97
|
+
externalLoadedEvent: "ai-core:client:externalLoaded",
|
|
98
|
+
/** Client -> server: () the character loaded under an external screen stands in the world (`playerSpawned` follows). */
|
|
99
|
+
externalSpawnedEvent: "ai-core:externalSpawned",
|
|
100
|
+
/** Server -> client: () the character was let go under an external character screen (that screen shows itself again). */
|
|
101
|
+
externalLogoutEvent: "ai-core:client:externalLogout",
|
|
102
|
+
} as const;
|
|
103
|
+
|
|
104
|
+
/** GlobalState key holding how many players are on duty in a job (counts only, never member lists). */
|
|
105
|
+
export const DUTY_COUNT_PREFIX = "ai:duty:";
|
|
106
|
+
export const dutyCountKey = (job: string): string =>
|
|
107
|
+
`${DUTY_COUNT_PREFIX}${job}`;
|
|
108
|
+
|
|
109
|
+
/** GlobalState key holding the resource name of the active inventory (null while none runs). */
|
|
110
|
+
export const INVENTORY_STATE_KEY = "ai:inventory";
|
|
111
|
+
|
|
112
|
+
/** Client local event: (worn: boolean | null) the local player's seat belt changed (ai-smallresources, read by HUDs). */
|
|
113
|
+
export const SEATBELT_EVENT = "ai-smallresources:seatbelt";
|
|
114
|
+
/** Player state bag keys several resources read (written by one server resource each). */
|
|
115
|
+
export const PLAYER_BAGS = {
|
|
116
|
+
/** true while downed (ai-death). */
|
|
117
|
+
dead: "dead",
|
|
118
|
+
/** true while handcuffed (ai-police). */
|
|
119
|
+
cuffed: "cuffed",
|
|
120
|
+
/** pma-voice's voice range `{ index, distance, mode }` (ai-voice writes it). */
|
|
121
|
+
proximity: "proximity",
|
|
122
|
+
} as const;
|
|
123
|
+
|
|
124
|
+
/** Why a character is let go: the player left, or went back to the character screen. */
|
|
125
|
+
export type UnloadReason = "dropped" | "switch";
|
package/src/deaths.ts
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/** What killed a player, from the weapon hash FXServer reports. */
|
|
2
|
+
export type DeathCause =
|
|
3
|
+
| "firearm"
|
|
4
|
+
| "melee"
|
|
5
|
+
| "explosion"
|
|
6
|
+
| "fire"
|
|
7
|
+
| "vehicle"
|
|
8
|
+
| "fall"
|
|
9
|
+
| "drown"
|
|
10
|
+
| "animal"
|
|
11
|
+
| "other";
|
|
12
|
+
|
|
13
|
+
/** Who killed a player: another player, an NPC (or its vehicle), the player themselves, or the world (a fall, drowning). */
|
|
14
|
+
export type DeathKiller = "player" | "npc" | "self" | "world";
|
|
15
|
+
|
|
16
|
+
/** A point in the world. */
|
|
17
|
+
export interface DeathPoint {
|
|
18
|
+
x: number;
|
|
19
|
+
y: number;
|
|
20
|
+
z: number;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* The details of a player's death, built by ai-core on the server from FXServer's `onPedDeath` and the synced
|
|
25
|
+
* entities (never from a client's report): the 4th argument of `CORE.playerDiedEvent (source, killer, weaponHash, info)`.
|
|
26
|
+
*/
|
|
27
|
+
export interface DeathInfo {
|
|
28
|
+
/** The killer's server id when another player killed them (also `killer`, the event's 2nd argument), else null. */
|
|
29
|
+
killer: number | null;
|
|
30
|
+
killedBy: DeathKiller;
|
|
31
|
+
cause: DeathCause;
|
|
32
|
+
/** The weapon hash FXServer reported (`WEAPON_FALL`, `WEAPON_RUN_OVER_BY_CAR`, a gun...). */
|
|
33
|
+
weapon: number;
|
|
34
|
+
/** Where the player died (rounded to 0.1 m). */
|
|
35
|
+
coords: DeathPoint;
|
|
36
|
+
/** Where the killing ped was (a player or an NPC), else null. */
|
|
37
|
+
killerCoords: DeathPoint | null;
|
|
38
|
+
/** Metres between the two (rounded to 0.1 m), else null. */
|
|
39
|
+
distance: number | null;
|
|
40
|
+
/** The player sat in a vehicle when they died. */
|
|
41
|
+
inVehicle: boolean;
|
|
42
|
+
/** The killer drove or sat in a vehicle (a drive-by, a run over). */
|
|
43
|
+
killerInVehicle: boolean;
|
|
44
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/** A grade of a job or gang definition (panel content). */
|
|
2
|
+
export interface GradeDefinition {
|
|
3
|
+
label: string;
|
|
4
|
+
salary: number;
|
|
5
|
+
boss: boolean;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export interface JobDefinition {
|
|
9
|
+
label: string;
|
|
10
|
+
type: string;
|
|
11
|
+
defaultDuty: boolean;
|
|
12
|
+
/** Shown in job centers (ESX esx_joblisting: `whitelisted` = not listed). */
|
|
13
|
+
listed?: boolean;
|
|
14
|
+
grades: GradeDefinition[];
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface GangDefinition {
|
|
18
|
+
label: string;
|
|
19
|
+
grades: GradeDefinition[];
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface AccountTypeDefinition {
|
|
23
|
+
label: string;
|
|
24
|
+
start: number;
|
|
25
|
+
allowNegative: boolean;
|
|
26
|
+
}
|
package/src/dispatch.ts
ADDED
|
@@ -0,0 +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
|
+
};
|