@aifivem/shared 0.0.0-stage → 0.5.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/ui.ts
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import type { InputRequest, MenuRequest } from "./menu";
|
|
2
|
+
import type { MinigameRequest } from "./minigame";
|
|
3
|
+
import type { Notification } from "./player";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* ai-lib's shared player UI (notifications, the progress bar, prompts, menus, inputs, minigames): one page in the
|
|
7
|
+
* ai-lib resource that every resource draws through lib `notify` / `progress` / `showPrompt` / `menu` / `input` /
|
|
8
|
+
* `skillCheck` / `lockpick` (and the Lua `aiLib` ones). It runs without ai-core.
|
|
9
|
+
*/
|
|
10
|
+
export const LIB_UI = {
|
|
11
|
+
resource: "ai-lib",
|
|
12
|
+
/** Server -> client: (notification: Notification) a notification card on the player's screen. */
|
|
13
|
+
notifyEvent: "ai-lib:client:notify",
|
|
14
|
+
/** Client local: (resource: string, id: string) the interaction key was pressed while that resource's prompt was on top. */
|
|
15
|
+
promptPressedEvent: "ai-lib:client:promptPressed",
|
|
16
|
+
/** Client local: the player pressed the cancel key while a progress bar shows (lib `progress` with `canCancel`). */
|
|
17
|
+
cancelProgressEvent: "ai-lib:client:cancelProgress",
|
|
18
|
+
/** Server -> client callback: (ServerProgress) runs the progress bar for a server flow (lib `progressFor`), answers true when it ran out. */
|
|
19
|
+
progressForCallback: "ai-lib:progressFor",
|
|
20
|
+
/** Server -> client: the server flow's progress bar stops (a newer `progressFor` replaced it). */
|
|
21
|
+
progressForCancelEvent: "ai-lib:client:progressForCancel",
|
|
22
|
+
/** Server -> client callback: (MinigameRequest) plays a minigame for a server flow (lib `minigameFor`), answers its result. */
|
|
23
|
+
minigameForCallback: "ai-lib:minigameFor",
|
|
24
|
+
/** Client local: (owner: string, key: string, inside: boolean) the player entered or left a zone ai-lib checks for `owner` (lib `Zones`). */
|
|
25
|
+
zoneEvent: "ai-lib:client:zone",
|
|
26
|
+
/** Client local: (owner: string, key: string, entity: number) the nearest object of a model point ai-lib scans for `owner` changed (0 = none near; lib `Points.addModel`). */
|
|
27
|
+
modelPointEvent: "ai-lib:client:modelPoint",
|
|
28
|
+
} as const;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* NUI stacking (`SetNuiZindex`, higher on top): every resource with a page sets its layer at start, so the order
|
|
32
|
+
* does not depend on load order. Notifications and menus (ai-lib) are over everything, police alerts over the HUD.
|
|
33
|
+
*/
|
|
34
|
+
export const NUI_LAYER = {
|
|
35
|
+
hud: 10,
|
|
36
|
+
screen: 20,
|
|
37
|
+
death: 25,
|
|
38
|
+
radial: 30,
|
|
39
|
+
target: 35,
|
|
40
|
+
chat: 40,
|
|
41
|
+
alert: 50,
|
|
42
|
+
lib: 100,
|
|
43
|
+
} as const;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Where a world prompt floats: a fixed point, or spots on entities (offsets in the entity's own space, so the prompt
|
|
47
|
+
* moves and turns with it: a swinging door). Of several entity spots the one nearest the player is shown each frame.
|
|
48
|
+
*/
|
|
49
|
+
export type PromptAnchor =
|
|
50
|
+
| { x: number; y: number; z: number }
|
|
51
|
+
| {
|
|
52
|
+
anchors: Array<{
|
|
53
|
+
entity: number;
|
|
54
|
+
offset: { x: number; y: number; z: number };
|
|
55
|
+
}>;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
/** ai-lib's client exports (the UI host); lib `notify`, `progress`, prompts, `menu`, `input` and minigames call them. */
|
|
59
|
+
export type AiLibClientExports = {
|
|
60
|
+
Notify(notification: Notification): void;
|
|
61
|
+
/** Shows the progress bar for `duration` ms (the calling resource runs the action and its animation). */
|
|
62
|
+
ShowProgress(label: string, duration: number): void;
|
|
63
|
+
HideProgress(): void;
|
|
64
|
+
/** Shows (or updates) the calling resource's prompt `id` on the right of the screen. */
|
|
65
|
+
/** `at`: drawn over that world point or entity spot (doors) instead of the right-hand list. */
|
|
66
|
+
ShowPrompt(id: string, text: string, at?: PromptAnchor): void;
|
|
67
|
+
HidePrompt(id: string): void;
|
|
68
|
+
/** Checks a zone of the calling resource (lib `Zones` hands its zones over); enter / exit arrive as `LIB_UI.zoneEvent`. */
|
|
69
|
+
AddZone(key: string, shape: unknown, interval: number, inside: boolean): void;
|
|
70
|
+
RemoveZone(key: string): void;
|
|
71
|
+
/** Scans for the nearest object of a prompt-mode model point of the calling resource; changes arrive as `LIB_UI.modelPointEvent`. */
|
|
72
|
+
AddModelPoint(key: string, def: unknown, entity: number): void;
|
|
73
|
+
RemoveModelPoint(key: string): void;
|
|
74
|
+
/** Shows a menu for the calling resource; the pick arrives as `MENU_EVENTS.menuResult`. */
|
|
75
|
+
OpenMenu(requestId: number, request: MenuRequest): void;
|
|
76
|
+
/** Shows an input dialog for the calling resource; the values arrive as `MENU_EVENTS.inputResult`. */
|
|
77
|
+
OpenInput(requestId: number, request: InputRequest): void;
|
|
78
|
+
/** Starts a minigame (skill check, lockpick); its result arrives as `MENU_EVENTS.menuResult`. */
|
|
79
|
+
OpenMinigame(requestId: number, request: MinigameRequest): void;
|
|
80
|
+
/** Closes the calling resource's open menu or input dialog (answered with null like a player close). */
|
|
81
|
+
CloseDialog(): void;
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Another notification UI ai-lib's cards can go to (ai-core panel setting `notify`, client half of ai-core's notify
|
|
86
|
+
* layer `resource/client/notify/`): translates one card into that script's call.
|
|
87
|
+
*/
|
|
88
|
+
export interface NotifyClientAdapter {
|
|
89
|
+
resource: string;
|
|
90
|
+
version?: string;
|
|
91
|
+
notify(notification: Notification): void;
|
|
92
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import type { CreateCharacterInput, Sex } from "./player";
|
|
2
|
+
|
|
3
|
+
const NAME = /^[A-Za-zÀ-ɏ][A-Za-zÀ-ɏ' -]{1,19}$/;
|
|
4
|
+
const DATE = /^(\d{4})-(\d{2})-(\d{2})$/;
|
|
5
|
+
|
|
6
|
+
/** A first or last name: 2-20 letters (Latin, accents), spaces, apostrophes, dashes; trimmed. Null when invalid. */
|
|
7
|
+
export function toName(value: unknown): string | null {
|
|
8
|
+
if (typeof value !== "string") return null;
|
|
9
|
+
const name = value.trim().replace(/\s+/g, " ");
|
|
10
|
+
return NAME.test(name) ? name : null;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** A birth date `YYYY-MM-DD` for an age between `minAge` and 100. Null when invalid. */
|
|
14
|
+
export function toBirthdate(
|
|
15
|
+
value: unknown,
|
|
16
|
+
minAge = 18,
|
|
17
|
+
now = new Date(),
|
|
18
|
+
): string | null {
|
|
19
|
+
if (typeof value !== "string") return null;
|
|
20
|
+
const match = DATE.exec(value);
|
|
21
|
+
if (!match) return null;
|
|
22
|
+
const [year, month, day] = [
|
|
23
|
+
Number(match[1]),
|
|
24
|
+
Number(match[2]),
|
|
25
|
+
Number(match[3]),
|
|
26
|
+
];
|
|
27
|
+
const date = new Date(Date.UTC(year, month - 1, day));
|
|
28
|
+
if (
|
|
29
|
+
date.getUTCFullYear() !== year ||
|
|
30
|
+
date.getUTCMonth() !== month - 1 ||
|
|
31
|
+
date.getUTCDate() !== day
|
|
32
|
+
)
|
|
33
|
+
return null;
|
|
34
|
+
const age =
|
|
35
|
+
now.getUTCFullYear() -
|
|
36
|
+
year -
|
|
37
|
+
(now.getUTCMonth() < month - 1 ||
|
|
38
|
+
(now.getUTCMonth() === month - 1 && now.getUTCDate() < day)
|
|
39
|
+
? 1
|
|
40
|
+
: 0);
|
|
41
|
+
return age >= minAge && age <= 100 ? value : null;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function toSex(value: unknown): Sex | null {
|
|
45
|
+
return value === "male" || value === "female" ? value : null;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const NATIONALITY = /^[A-Za-zÀ-ɏ][A-Za-zÀ-ɏ' -]{1,31}$/;
|
|
49
|
+
|
|
50
|
+
/** A nationality: 2-32 letters (Latin, accents), spaces, apostrophes, dashes; trimmed. Null when invalid. */
|
|
51
|
+
export function toNationality(value: unknown): string | null {
|
|
52
|
+
if (typeof value !== "string") return null;
|
|
53
|
+
const text = value.trim().replace(/\s+/g, " ");
|
|
54
|
+
return NATIONALITY.test(text) ? text : null;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** The character creation form from the NUI, or the lang key of the first invalid field. */
|
|
58
|
+
export function toCreateCharacter(
|
|
59
|
+
value: unknown,
|
|
60
|
+
): CreateCharacterInput | { error: string } {
|
|
61
|
+
if (typeof value !== "object" || value === null)
|
|
62
|
+
return { error: "CHAR_ERR_INVALID" };
|
|
63
|
+
const input = value as Record<string, unknown>;
|
|
64
|
+
const slot =
|
|
65
|
+
typeof input.slot === "number" &&
|
|
66
|
+
Number.isInteger(input.slot) &&
|
|
67
|
+
input.slot >= 1
|
|
68
|
+
? input.slot
|
|
69
|
+
: null;
|
|
70
|
+
const firstname = toName(input.firstname);
|
|
71
|
+
const lastname = toName(input.lastname);
|
|
72
|
+
const birthdate = toBirthdate(input.birthdate);
|
|
73
|
+
const sex = toSex(input.sex);
|
|
74
|
+
const nationality = toNationality(input.nationality);
|
|
75
|
+
if (slot === null) return { error: "CHAR_ERR_INVALID" };
|
|
76
|
+
if (!firstname) return { error: "CHAR_ERR_FIRSTNAME" };
|
|
77
|
+
if (!lastname) return { error: "CHAR_ERR_LASTNAME" };
|
|
78
|
+
if (!birthdate) return { error: "CHAR_ERR_BIRTHDATE" };
|
|
79
|
+
if (!sex) return { error: "CHAR_ERR_SEX" };
|
|
80
|
+
if (!nationality) return { error: "CHAR_ERR_NATIONALITY" };
|
|
81
|
+
return { slot, firstname, lastname, birthdate, sex, nationality };
|
|
82
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/** A vehicle as key systems know it: the server entity (when it exists), its network id and its trimmed plate. */
|
|
2
|
+
export interface KeyTarget {
|
|
3
|
+
vehicle: number | null;
|
|
4
|
+
netId: number | null;
|
|
5
|
+
plate: string;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Why a player gets a vehicle's key; key systems treat each one differently (tgiann-hotwire: a bought vehicle gets a
|
|
10
|
+
* new key item, a garage vehicle its stored ignition state, a job or rented vehicle a key fixed in the ignition).
|
|
11
|
+
* - `purchase`: the player now owns the vehicle (dealer, admin give): a new key, older copies stop working.
|
|
12
|
+
* - `garage`: an owned vehicle taken out of storage: the owner already has the key.
|
|
13
|
+
* - `job`: a work vehicle for the shift.
|
|
14
|
+
* - `rental`: a rented vehicle for the rental time.
|
|
15
|
+
* - `temporary`: anything else short-lived (admin spawn, test drive, robbery vehicle); the default.
|
|
16
|
+
*/
|
|
17
|
+
export type KeyPurpose = "purchase" | "garage" | "job" | "rental" | "temporary";
|
|
18
|
+
export const KEY_PURPOSES: readonly KeyPurpose[] = [
|
|
19
|
+
"purchase",
|
|
20
|
+
"garage",
|
|
21
|
+
"job",
|
|
22
|
+
"rental",
|
|
23
|
+
"temporary",
|
|
24
|
+
];
|
|
25
|
+
|
|
26
|
+
/** A purpose from untrusted input; `temporary` for anything else. */
|
|
27
|
+
export function toKeyPurpose(value: unknown): KeyPurpose {
|
|
28
|
+
return KEY_PURPOSES.find((p) => p === value) ?? "temporary";
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* One key system behind ai-core's vehicle key layer (server side). A system with only a client API is reached through
|
|
33
|
+
* ai-core's client (`clientKeys` adapters); then `give` / `remove` forward to the player's client.
|
|
34
|
+
*/
|
|
35
|
+
export interface VehicleKeysAdapter {
|
|
36
|
+
resource: string;
|
|
37
|
+
give(source: number, target: KeyTarget, purpose: KeyPurpose): void;
|
|
38
|
+
remove(source: number, target: KeyTarget): void;
|
|
39
|
+
/** Absent when the system cannot answer: ai-core then counts the key as held. */
|
|
40
|
+
has?(source: number, target: KeyTarget): boolean;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** The client half of a key system that only has a client API. */
|
|
44
|
+
export interface VehicleKeysClientAdapter {
|
|
45
|
+
resource: string;
|
|
46
|
+
give(vehicle: number, plate: string, purpose: KeyPurpose): void;
|
|
47
|
+
remove(vehicle: number, plate: string): void;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** GlobalState key holding the resource name of the active key system (null while none runs). */
|
|
51
|
+
export const VEHICLE_KEYS_STATE_KEY = "ai:vehicleKeys";
|
|
52
|
+
/** Server -> client: ("give" | "remove", netId, plate, purpose) for key systems with a client API only. */
|
|
53
|
+
export const VEHICLE_KEYS_CLIENT_EVENT = "ai-core:client:vehicleKeys";
|
|
54
|
+
|
|
55
|
+
/** ai-core's vehicle key exports: a vehicle is a server entity handle or a plate; `purpose` defaults to `temporary`. */
|
|
56
|
+
export type VehicleKeysServerExports = {
|
|
57
|
+
GiveVehicleKeys(
|
|
58
|
+
source: number,
|
|
59
|
+
vehicle: number | string,
|
|
60
|
+
purpose?: KeyPurpose,
|
|
61
|
+
): void;
|
|
62
|
+
RemoveVehicleKeys(source: number, vehicle: number | string): void;
|
|
63
|
+
HasVehicleKeys(source: number, vehicle: number | string): boolean;
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
/** Client -> server callback `(netId | plate)`: whether the local player holds that vehicle's keys (the server layer's answer). */
|
|
67
|
+
export const VEHICLE_KEYS_HAS_CALLBACK = "ai-core:vehicleKeys:has";
|
|
68
|
+
/** Server -> one client: `(plate, held)` after ai-core's layer gave or took that player's key. */
|
|
69
|
+
export const VEHICLE_KEY_HELD_EVENT = "ai-core:client:vehicleKeyHeld";
|
|
70
|
+
|
|
71
|
+
/** ai-core's client vehicle key export. */
|
|
72
|
+
export type VehicleKeysClientExports = {
|
|
73
|
+
/**
|
|
74
|
+
* Whether the local player holds the keys of a vehicle (entity handle or plate), from a short-lived mirror of the
|
|
75
|
+
* server's answers: the first call for a vehicle the player has not entered answers false and asks the server.
|
|
76
|
+
*/
|
|
77
|
+
HasVehicleKeys(vehicle: number | string): boolean;
|
|
78
|
+
};
|
package/src/vehicles.ts
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import type { KeyPurpose } from "./vehicleKeys";
|
|
2
|
+
/** Owned vehicle contract (ai-vehicles keeps them; garages, shops, keys and fuel use them). */
|
|
3
|
+
|
|
4
|
+
/** `resource`: held by a script (a used car lot listing), no player has it. */
|
|
5
|
+
export type VehicleOwnerType = "character" | "job" | "gang" | "resource";
|
|
6
|
+
export type VehicleState = "garage" | "out" | "impound";
|
|
7
|
+
|
|
8
|
+
export interface VehicleOwner {
|
|
9
|
+
type: VehicleOwnerType;
|
|
10
|
+
/** Character id (as text), job or gang name, or the holding resource's name. */
|
|
11
|
+
id: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface OwnedVehicle {
|
|
15
|
+
id: number;
|
|
16
|
+
plate: string;
|
|
17
|
+
owner: VehicleOwner;
|
|
18
|
+
model: string;
|
|
19
|
+
/** VehicleProps (`@aifivem/lib/shared`) or null before the first save. */
|
|
20
|
+
props: unknown;
|
|
21
|
+
/** VehicleSetup (lib `spawnVehicle`'s `setup`) the vehicle spawns with while it has no props (a shop's colour). */
|
|
22
|
+
setup: unknown;
|
|
23
|
+
state: VehicleState;
|
|
24
|
+
garage: string | null;
|
|
25
|
+
fuel: number;
|
|
26
|
+
engine: number;
|
|
27
|
+
body: number;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** Entity state bags ai-vehicles sets on a spawned owned vehicle. */
|
|
31
|
+
export const VEHICLE_BAGS = {
|
|
32
|
+
/** true: an owned vehicle. */
|
|
33
|
+
owned: "ai:owned",
|
|
34
|
+
/** Its id in ai-vehicles. */
|
|
35
|
+
id: "ai:vid",
|
|
36
|
+
/** VehicleProps; the entity's owner client applies them (ai-core). */
|
|
37
|
+
props: "ai:props",
|
|
38
|
+
/** VehicleSetup (lib `spawnVehicle`'s `setup`): the owner client applies it once (ai-core). */
|
|
39
|
+
setup: "ai:setup",
|
|
40
|
+
/** 0-100, kept by a fuel resource. */
|
|
41
|
+
fuel: "fuel",
|
|
42
|
+
} as const;
|
|
43
|
+
|
|
44
|
+
/** ai-vehicles' server exports. */
|
|
45
|
+
export type AiVehiclesServerExports = {
|
|
46
|
+
CreateVehicle(
|
|
47
|
+
owner: VehicleOwner,
|
|
48
|
+
model: string,
|
|
49
|
+
garage: string | null,
|
|
50
|
+
props?: unknown,
|
|
51
|
+
): { id: number; plate: string } | null;
|
|
52
|
+
/** `shape` "framework": props in ox_lib / qb-core's shape with `fuelLevel` (scripts that apply looks themselves). */
|
|
53
|
+
GetVehicle(ref: number | string, shape?: "framework"): OwnedVehicle | null;
|
|
54
|
+
/** Vehicles of an owner who is online (characters) or any job / gang fleet. */
|
|
55
|
+
GetVehicles(owner: VehicleOwner, shape?: "framework"): OwnedVehicle[];
|
|
56
|
+
IsOwnedPlate(plate: string): boolean;
|
|
57
|
+
GetVehicleIdByEntity(entity: number): number | null;
|
|
58
|
+
/** Every owned vehicle in memory as `[plate, ownerType, ownerId]` (key systems mirror it, then follow `VEHICLES_EVENTS.owners`). */
|
|
59
|
+
GetPlateOwners(): Array<[plate: string, type: VehicleOwnerType, id: string]>;
|
|
60
|
+
/** A vehicle by plate, also of an owner who is not online (from the database). */
|
|
61
|
+
FindVehicle(
|
|
62
|
+
plate: string,
|
|
63
|
+
done: (vehicle: OwnedVehicle | null) => void,
|
|
64
|
+
shape?: "framework",
|
|
65
|
+
): void;
|
|
66
|
+
/** An owner's vehicles, also of a character who is not online (from the database). */
|
|
67
|
+
GetVehiclesOf(
|
|
68
|
+
owner: VehicleOwner,
|
|
69
|
+
done: (vehicles: OwnedVehicle[]) => void,
|
|
70
|
+
shape?: "framework",
|
|
71
|
+
): void;
|
|
72
|
+
/**
|
|
73
|
+
* Another plate for a vehicle in memory (custom plate, plate changer; its entity too): 1-8 letters / digits, never
|
|
74
|
+
* a generated `AI...` one; `done(false)` when it is taken or not valid.
|
|
75
|
+
*/
|
|
76
|
+
SetPlate(id: number, plate: string, done?: (ok: boolean) => void): void;
|
|
77
|
+
GetEntity(id: number): number | null;
|
|
78
|
+
/**
|
|
79
|
+
* Saves condition and look: fuel, damage, state, garage and `props` (colours, extras, dirt, ...). The stored tuning
|
|
80
|
+
* (`mods`, `neon`) stays: a client-read look never changes it (a mod menu cannot persist mods). Tuning: `SaveTuning`.
|
|
81
|
+
*/
|
|
82
|
+
SaveVehicle(
|
|
83
|
+
id: number,
|
|
84
|
+
change: {
|
|
85
|
+
props?: unknown;
|
|
86
|
+
fuel?: number;
|
|
87
|
+
engine?: number;
|
|
88
|
+
body?: number;
|
|
89
|
+
state?: VehicleState;
|
|
90
|
+
garage?: string | null;
|
|
91
|
+
},
|
|
92
|
+
): void;
|
|
93
|
+
/** Saves full props including the tuning (`mods`, `neon`). Only a tuning shop (ai-mechanic) calls it. */
|
|
94
|
+
SaveTuning(id: number, props: unknown): void;
|
|
95
|
+
StoreVehicle(id: number, garage: string | null, state?: VehicleState): void;
|
|
96
|
+
SetOwner(id: number, owner: VehicleOwner): void;
|
|
97
|
+
DeleteVehicle(id: number): void;
|
|
98
|
+
/**
|
|
99
|
+
* Creates the entity; `cb` gets its net id (null when it failed). `asker` is a player whose client answers the model
|
|
100
|
+
* type. `setup` (lib VehicleSetup, e.g. `{ colors }`) is kept with a vehicle that has no props yet and applied on every
|
|
101
|
+
* spawn until its first props save, so a bought colour survives a vehicle that was never parked.
|
|
102
|
+
*/
|
|
103
|
+
SpawnVehicle(
|
|
104
|
+
id: number,
|
|
105
|
+
at: { x: number; y: number; z: number; heading: number },
|
|
106
|
+
asker: number,
|
|
107
|
+
cb: (netId: number | null) => void,
|
|
108
|
+
purpose?: KeyPurpose,
|
|
109
|
+
setup?: unknown,
|
|
110
|
+
): void;
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
/** ai-vehicles' server local events. */
|
|
114
|
+
export const VEHICLES_EVENTS = {
|
|
115
|
+
/** (puts: [plate, ownerType, ownerId][], removes: plate[]) owners of vehicles in memory changed (one batch per tick). */
|
|
116
|
+
owners: "ai-vehicles:owners",
|
|
117
|
+
} as const;
|
package/src/vrp.ts
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ai-core's vRP layer (bridge/vrp in ai-core): the panel's permission mapping (`data/vrp.json`) as the Lua bridge
|
|
3
|
+
* reads it (export `GetVrpConfig`, local event `VRP.configEvent` with the same shape after a change).
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* One permission rule: grants `permission` (exact, or a prefix when it ends with `*`) to whoever matches any filled
|
|
8
|
+
* target. `grade` is the minimum job / gang grade; `onDuty` makes the job count only while on duty in it.
|
|
9
|
+
*/
|
|
10
|
+
export interface VrpPermissionRule {
|
|
11
|
+
permission: string;
|
|
12
|
+
job: string;
|
|
13
|
+
gang: string;
|
|
14
|
+
/** An extra vRP group the character holds (groups vRP scripts add that are no job or gang). */
|
|
15
|
+
group: string;
|
|
16
|
+
grade: number;
|
|
17
|
+
onDuty: boolean;
|
|
18
|
+
admin: boolean;
|
|
19
|
+
everyone: boolean;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** A vRP group name that means a job / gang grade or admin (vRPex style ranks such as "Coronel"). */
|
|
23
|
+
export interface VrpGroupAlias {
|
|
24
|
+
job: string;
|
|
25
|
+
gang: string;
|
|
26
|
+
grade: number;
|
|
27
|
+
admin: boolean;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface VrpConfig {
|
|
31
|
+
/**
|
|
32
|
+
* Built-in rules used when no rule of `permissions` names the permission: `<job>.*` = member of that job (on duty
|
|
33
|
+
* with `jobOnDuty`), `admin.*` = admin (`ai.admin`), `player.*` = everyone.
|
|
34
|
+
*/
|
|
35
|
+
defaults: {
|
|
36
|
+
jobPrefix: boolean;
|
|
37
|
+
jobOnDuty: boolean;
|
|
38
|
+
adminPrefix: boolean;
|
|
39
|
+
playerPrefix: boolean;
|
|
40
|
+
};
|
|
41
|
+
permissions: VrpPermissionRule[];
|
|
42
|
+
/** vRP group name -> what it means in ai-core. */
|
|
43
|
+
groups: Record<string, VrpGroupAlias>;
|
|
44
|
+
/** vRP item id (`edible|tacos`, `wbody|WEAPON_PISTOL`) -> inventory item name. */
|
|
45
|
+
items: Record<string, string>;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export const VRP = {
|
|
49
|
+
/** Server local: (config: VrpConfig) the panel changed the vRP mapping. */
|
|
50
|
+
configEvent: "ai-core:vrp:config",
|
|
51
|
+
} as const;
|
package/src/world.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/** The weather types of the qb-weathersync contract (ai-core's world layer passes them on). */
|
|
2
|
+
export const WEATHERS = [
|
|
3
|
+
"EXTRASUNNY",
|
|
4
|
+
"CLEAR",
|
|
5
|
+
"NEUTRAL",
|
|
6
|
+
"SMOG",
|
|
7
|
+
"FOGGY",
|
|
8
|
+
"OVERCAST",
|
|
9
|
+
"CLOUDS",
|
|
10
|
+
"CLEARING",
|
|
11
|
+
"RAIN",
|
|
12
|
+
"THUNDER",
|
|
13
|
+
"SNOW",
|
|
14
|
+
"BLIZZARD",
|
|
15
|
+
"SNOWLIGHT",
|
|
16
|
+
"XMAS",
|
|
17
|
+
"HALLOWEEN",
|
|
18
|
+
] as const;
|
|
19
|
+
|
|
20
|
+
export type Weather = (typeof WEATHERS)[number];
|
|
21
|
+
|
|
22
|
+
const WEATHER_SET: ReadonlySet<string> = new Set(WEATHERS);
|
|
23
|
+
|
|
24
|
+
/** A known weather type (exact upper-case name). */
|
|
25
|
+
export const isWeather = (value: unknown): value is Weather =>
|
|
26
|
+
typeof value === "string" && WEATHER_SET.has(value);
|
package/README.md
DELETED