@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.
Files changed (52) hide show
  1. package/package.json +23 -4
  2. package/src/action.ts +6 -0
  3. package/src/admin/dataSpec.ts +63 -0
  4. package/src/admin/events.ts +45 -0
  5. package/src/admin/lookups.ts +29 -0
  6. package/src/admin/panel.ts +105 -0
  7. package/src/admin/schema.ts +58 -0
  8. package/src/admin/widgets.ts +123 -0
  9. package/src/appearance.ts +115 -0
  10. package/src/banking.ts +58 -0
  11. package/src/bans.ts +91 -0
  12. package/src/billing.ts +112 -0
  13. package/src/characters.ts +71 -0
  14. package/src/commands.ts +80 -0
  15. package/src/core.ts +125 -0
  16. package/src/deaths.ts +44 -0
  17. package/src/definitions.ts +26 -0
  18. package/src/dispatch.ts +103 -0
  19. package/src/doorlock.ts +29 -0
  20. package/src/ems.ts +50 -0
  21. package/src/exports/aiInventory.ts +96 -0
  22. package/src/exports/citizen.ts +45 -0
  23. package/src/exports/coreCharacters.ts +167 -0
  24. package/src/exports/coreClient.ts +79 -0
  25. package/src/exports/coreGroups.ts +29 -0
  26. package/src/exports/coreLayers.ts +45 -0
  27. package/src/exports/coreMoney.ts +97 -0
  28. package/src/exports/coreServer.ts +91 -0
  29. package/src/exports/coreServices.ts +60 -0
  30. package/src/exports/resources.ts +107 -0
  31. package/src/fuel.ts +48 -0
  32. package/src/garages.ts +101 -0
  33. package/src/index.ts +49 -0
  34. package/src/inventory/adapters.ts +86 -0
  35. package/src/inventory/exports.ts +92 -0
  36. package/src/inventory/items.ts +92 -0
  37. package/src/logs.ts +45 -0
  38. package/src/mdt.ts +78 -0
  39. package/src/medical.ts +18 -0
  40. package/src/menu.ts +94 -0
  41. package/src/minigame.ts +45 -0
  42. package/src/multichar.ts +44 -0
  43. package/src/phone.ts +39 -0
  44. package/src/player.ts +159 -0
  45. package/src/radial.ts +44 -0
  46. package/src/ui.ts +92 -0
  47. package/src/validation.ts +82 -0
  48. package/src/vehicleKeys.ts +78 -0
  49. package/src/vehicles.ts +117 -0
  50. package/src/vrp.ts +51 -0
  51. package/src/world.ts +26 -0
  52. package/README.md +0 -3
@@ -0,0 +1,91 @@
1
+ import type { BankingServerExports } from "../banking";
2
+ import type { BillingServerExports } from "../billing";
3
+ import type { CharacterServerExports } from "./coreCharacters";
4
+ import type { DispatchServerExports } from "../dispatch";
5
+ import type { DoorlockServerExports } from "../doorlock";
6
+ import type { EmsServerExports } from "../ems";
7
+ import type { FuelServerExports } from "../fuel";
8
+ import type { GaragesServerExports } from "../garages";
9
+ import type { InventoryServerExports } from "../inventory/exports";
10
+ import type { MdtServerExports } from "../mdt";
11
+ import type { MulticharServerExports } from "../multichar";
12
+ import type { PhoneServerExports } from "../phone";
13
+ import type { AiPlayerData, CharacterInfo } from "../player";
14
+ import type { VehicleKeysServerExports } from "../vehicleKeys";
15
+ import type { VrpConfig } from "../vrp";
16
+ import type { CoreGroupServerExports } from "./coreGroups";
17
+ import type { CoreLayerServerExports } from "./coreLayers";
18
+ import type { CoreMoneyServerExports } from "./coreMoney";
19
+ import type { CoreServiceServerExports } from "./coreServices";
20
+
21
+ /**
22
+ * ai-core's server exports: synchronous, small values. Callers mirror what they need and follow ai-core's local
23
+ * events (`CORE.*Event`) instead of calling these in hot paths. A type alias, not an interface: it must fit
24
+ * CitizenExports' index signature.
25
+ */
26
+ export type AiCoreServerExports = {
27
+ GetPlayerData(src: number): AiPlayerData | null;
28
+ GetCharacter(src: number): CharacterInfo | null;
29
+ GetSourceByCharId(charId: number): number | null;
30
+ GetSourceByCitizenId(citizenid: string): number | null;
31
+ GetLoadedSources(): number[];
32
+ GetFivemId(src: number): string | null;
33
+ /** The account id (`ai_core_users.id`) of a connected player, also on the character screen. */
34
+ GetUserId(src: number): number | null;
35
+ /** A character by id, loaded or not, with its account id; `done` gets null for an unknown or deleted one. */
36
+ GetCharacterInfo(
37
+ charId: number,
38
+ done: (info: (CharacterInfo & { userId: number }) | null) => void,
39
+ ): void;
40
+
41
+ // vRP layer (ai-core's bridge/vrp calls these; values are hex text so any bytes survive).
42
+ /** A vRP data value (`kind` c / u / s / g, owner id as text) as hex, `""` when unset; at once when cached. */
43
+ VrpGetData(
44
+ kind: string,
45
+ owner: string,
46
+ key: string,
47
+ done: (hex: string) => void,
48
+ ): void;
49
+ /** Stores a vRP data value (hex); written within a second. */
50
+ VrpSetData(kind: string, owner: string, key: string, hex: string): boolean;
51
+ /** vRP's DB API on ai-core's pool: `done(error | null, ...)` with rows + affected, affected, or the scalar. */
52
+ VrpQuery(
53
+ sql: string,
54
+ params: unknown,
55
+ mode: "query" | "execute" | "scalar",
56
+ done: (error: string | null, ...answer: unknown[]) => void,
57
+ ): void;
58
+ /** The panel's vRP permission mapping (`data/vrp.json`). */
59
+ GetVrpConfig(): VrpConfig;
60
+ /** Records a permission string a script asked for (the panel lists them); true when it was new. */
61
+ VrpPermissionAsked(permission: string): boolean;
62
+ SwitchCharacter(src: number): boolean;
63
+
64
+ GetMeta(src: number, key: string): unknown;
65
+ SetMeta(src: number, key: string, value: unknown): boolean;
66
+
67
+ /**
68
+ * Moves a stored (not loaded) character's spawn point once no load or unload save holds it; false when the
69
+ * character is loaded or the arguments are wrong (true = accepted, the write follows).
70
+ */
71
+ SetOfflinePosition(
72
+ charId: number,
73
+ position: { x: number; y: number; z: number; heading?: number },
74
+ ): boolean;
75
+ } & CoreMoneyServerExports &
76
+ CoreGroupServerExports &
77
+ CoreServiceServerExports &
78
+ CoreLayerServerExports &
79
+ InventoryServerExports &
80
+ VehicleKeysServerExports &
81
+ PhoneServerExports &
82
+ DispatchServerExports &
83
+ BillingServerExports &
84
+ BankingServerExports &
85
+ MdtServerExports &
86
+ EmsServerExports &
87
+ FuelServerExports &
88
+ DoorlockServerExports &
89
+ GaragesServerExports &
90
+ CharacterServerExports &
91
+ MulticharServerExports;
@@ -0,0 +1,60 @@
1
+ import type { AdminDelta } from "../admin/panel";
2
+ import type { CommandInfo } from "../commands";
3
+ import type { LogChannel, LogOptions } from "../logs";
4
+ import type { Branding } from "../player";
5
+
6
+ /** ai-core's services for other scripts: branding, logs, the admin panel, connection checks, buckets (part of `AiCoreServerExports`). */
7
+ export type CoreServiceServerExports = {
8
+ /** The server's brand (name, subtitle, taglines, background) from the panel's General settings. */
9
+ GetBranding(): Branding;
10
+
11
+ /** Sends a log of the calling resource to every provider turned on (Discord, Fivemanage, FiveM Stats, console). */
12
+ Log(channel: string, message: string, options?: LogOptions): void;
13
+ /** Describes the calling resource's log channels (datasets, on/off); call once at start. */
14
+ LogChannels(channels: Record<string, LogChannel>): void;
15
+
16
+ /** A resource with an admin panel announces itself (the lib's AdminPanel does it at start). */
17
+ RegisterAdminPanel(resource: string): void;
18
+ /** A panel resource changed a record: ai-core forwards it to the admins with the panel open. */
19
+ AdminPanelChanged(delta: AdminDelta): void;
20
+ /** The lib's `addCommand` announces a resource's commands for the panel's Commands tab (dropped when it stops). */
21
+ RegisterCommands(resource: string, commands: CommandInfo[]): void;
22
+
23
+ /** Values of a lookup list (items of the active inventory, jobs, gangs, accounts) for the admin panel's validation. */
24
+ GetLookupValues(source: import("../admin/lookups").LookupSource): string[];
25
+ /** Lists another script's own settings screen on the dashboard (opened by `command` or embedded `url`). */
26
+ RegisterExternalPanel(panel: {
27
+ id?: string;
28
+ label: string;
29
+ icon?: string;
30
+ description?: string;
31
+ command?: string;
32
+ url?: string;
33
+ }): void;
34
+ /** Adds a check every connecting player passes: return a refusal text, or null to let the player through. */
35
+ AddConnectionCheck(
36
+ id: string,
37
+ check: (
38
+ source: number,
39
+ identifiers: Record<string, string>,
40
+ ) => string | null | undefined,
41
+ ): void;
42
+ /** Declares that `keep` (default: the calling resource) makes the `remove` resources unneeded (console warning, refused joins while both run). */
43
+ RegisterReplacement(remove: string | string[], keep?: string): void;
44
+ /** Scripts installed next to the one that replaces them; `running` = both started. */
45
+ GetConflicts(): {
46
+ keep: string;
47
+ remove: string;
48
+ running: boolean;
49
+ from: string;
50
+ }[];
51
+ /** The players in a player's OneSync scope (~424 m), kept from ai-core's one set of scope handlers (lib `playersNear`). */
52
+ GetPlayersInScope(source: number): number[];
53
+ /** Scripts with a newer GitHub release than the running version (ai-core's update check). */
54
+ GetUpdates(): import("../admin/panel").UpdateInfo[];
55
+
56
+ /** A free routing bucket for the calling resource (no population, strict lockdown); freed when it stops. */
57
+ AcquireBucket(tag: string): number;
58
+ /** Gives a bucket back (only the resource that took it can); move its players out first. */
59
+ ReleaseBucket(id: number): boolean;
60
+ };
@@ -0,0 +1,107 @@
1
+ import type { JobOutfit } from "../appearance";
2
+ import type { DispatchAlert } from "../dispatch";
3
+ import type { RadialItem } from "../radial";
4
+
5
+ /** ai-target's client exports that ai-core uses. */
6
+ export type AiTargetClientExports = {
7
+ /** The interaction key was pressed: runs the focused target option; false when no target is in focus. */
8
+ HandleInteract(): boolean;
9
+ /** ox_target shape: options on every entity of these models; `onSelect` runs in the calling resource. */
10
+ addModel(
11
+ models: Array<string | number>,
12
+ options: Array<{
13
+ name: string;
14
+ label: string;
15
+ icon?: string;
16
+ distance?: number;
17
+ onSelect?: (data: unknown) => void;
18
+ }>,
19
+ ): void;
20
+ removeModel(models: Array<string | number>, names?: string[]): void;
21
+ };
22
+
23
+ /** ai-appearance's client exports (ai-core's appearance adapter uses them; scripts use lib `appearance`). */
24
+ export type AiAppearanceClientExports = {
25
+ /** Puts an ai-appearance look (its `Appearance` JSON) on a ped of the look's model; false when the look is invalid or the model differs. */
26
+ ApplyAppearance(ped: number, appearance: unknown): boolean;
27
+ /** The look the local player wears (its `Appearance`), null for any other ped. */
28
+ GetPedAppearance(ped: number): unknown;
29
+ /** Puts a job outfit on the local player until `ReloadSkin` (never saved). */
30
+ WearOutfit(outfit: JobOutfit): void;
31
+ /** Puts the saved look back on the local player. */
32
+ ReloadSkin(): void;
33
+ };
34
+
35
+ /**
36
+ * ai-radialmenu's own client exports (ai-core's radial layer calls them; scripts use lib `radial`). Items are removed
37
+ * when the adding resource stops; `onSelect` is the older name of `onPressed`.
38
+ */
39
+ export type AiRadialClientExports = {
40
+ AddItem(item: RadialItem & { onSelect?: () => void }): void;
41
+ RemoveItem(id: string, parent?: string): void;
42
+ /** Reads every `canShow` of an open wheel again. */
43
+ Refresh(): void;
44
+ };
45
+
46
+ /** ai-vehiclekeys' server exports: a vehicle is an entity or a plate. */
47
+ export type AiVehicleKeysServerExports = {
48
+ HasKeys(source: number, vehicle: number | string): boolean;
49
+ GiveKeys(source: number, vehicle: number | string): void;
50
+ RemoveKeys(source: number, vehicle: number | string): void;
51
+ };
52
+
53
+ /** ai-death's server exports. */
54
+ export type AiDeathServerExports = {
55
+ /** Gets a downed player up where they lie; false when they are not down. */
56
+ Revive(source: number): boolean;
57
+ IsDead(source: number): boolean;
58
+ /** Full health for a player who is not down. */
59
+ Heal(source: number): void;
60
+ };
61
+
62
+ /** ai-policealert's server exports. */
63
+ export type AiPoliceAlertServerExports = {
64
+ /** ai-core's dispatch layer hands an alert to the built-in alert cards (scripts call lib `dispatch`). */
65
+ DispatchAlert(alert: DispatchAlert): void;
66
+ };
67
+
68
+ /** ai-doorlock's server exports (doors by panel id). */
69
+ export type AiDoorlockServerExports = {
70
+ SetDoorState(id: string, locked: boolean): void;
71
+ IsLocked(id: string): boolean;
72
+ };
73
+
74
+ /** ai-smallresources' client exports; the seat belt changes arrive as the local event `SEATBELT_EVENT`. */
75
+ export type AiSmallResourcesClientExports = {
76
+ /** Whether the local player wears a seat belt; null while seat belts are off or not in a vehicle with one. */
77
+ GetSeatbelt(): boolean | null;
78
+ };
79
+
80
+ /** ai-hud's client exports (ai-core opens its settings; ai-admin's minimap toggle). */
81
+ export type AiHudClientExports = {
82
+ OpenSettings(): void;
83
+ SetMinimapAlways(on: boolean): void;
84
+ GetMinimapAlways(): boolean;
85
+ };
86
+
87
+ /** ai-hud's server exports (ai-core's stress layer adds stress through `AddNeed`). */
88
+ export type AiHudServerExports = {
89
+ /** Adds `delta` to a loaded player's need (0-100, clamped). */
90
+ AddNeed(
91
+ source: number,
92
+ need: "hunger" | "thirst" | "stress",
93
+ delta: number,
94
+ ): void;
95
+ /** Sets a loaded player's need to `value` (0-100, clamped). */
96
+ SetNeed(
97
+ source: number,
98
+ need: "hunger" | "thirst" | "stress",
99
+ value: number,
100
+ ): void;
101
+ };
102
+
103
+ /** ai-vehicleshop's server exports. */
104
+ export type AiVehicleshopServerExports = {
105
+ /** A model's catalog price, null when the catalog has no such model. */
106
+ GetCatalogPrice(model: string): number | null;
107
+ };
package/src/fuel.ts ADDED
@@ -0,0 +1,48 @@
1
+ /**
2
+ * ai-core's fuel layer: a vehicle's fuel (0-100) through whichever fuel script runs (ai-fuel, ox_fuel, LegacyFuel...).
3
+ * `docs/compat/fuel.md`.
4
+ */
5
+
6
+ /** GlobalState key: the resource name of the fuel script behind the fuel layer (unset while none runs). */
7
+ export const FUEL_STATE_KEY = "ai:fuel";
8
+ /**
9
+ * Vehicle state bag: a level the server set for a fuel script that keeps fuel on the clients, waiting for the entity's
10
+ * owner client to put it into that script (cleared when a client reports the level back).
11
+ */
12
+ export const FUEL_PENDING_BAG = "ai:fuelSet";
13
+ /**
14
+ * Client -> server: (netId, level) the level a client-side fuel script holds for a vehicle near the player: the
15
+ * driver's at every whole percent, the owner's right after it applied `FUEL_PENDING_BAG`.
16
+ */
17
+ export const FUEL_REPORT_EVENT = "ai-core:fuelReport";
18
+
19
+ /** One fuel script on ai-core's server (`resource/server/fuel/`). */
20
+ export interface FuelAdapter {
21
+ resource: string;
22
+ version?: string;
23
+ /** Meant to run next to ai-fuel (never true for a fuel script: two burn the same tank). */
24
+ besideOurs?: boolean;
25
+ /** The script keeps fuel on the clients: ai-core mirrors it into the `fuel` bag from client reports. */
26
+ mirrored?: boolean;
27
+ /** 0-100, null when the vehicle has no level yet. */
28
+ get(vehicle: number): number | null;
29
+ set(vehicle: number, level: number): void;
30
+ }
31
+
32
+ /** The client half of a fuel script that keeps fuel on the clients (`resource/client/fuel/`). */
33
+ export interface FuelClientAdapter {
34
+ resource: string;
35
+ /** 0-100 as the script holds it for a vehicle this client knows; null when it cannot tell. */
36
+ get(vehicle: number): number | null;
37
+ set(vehicle: number, level: number): void;
38
+ }
39
+
40
+ /** ai-core's fuel exports (lib `fuel`): a vehicle is a server entity handle. */
41
+ export type FuelServerExports = {
42
+ /** The fuel script the fuel layer forwards to, or null. */
43
+ GetFuelSystem(): string | null;
44
+ /** 0-100, null for a vehicle without a level (or no vehicle). */
45
+ GetVehicleFuel(vehicle: number): number | null;
46
+ /** Sets the level (clamped to 0-100); false for a wrong vehicle or level. */
47
+ SetVehicleFuel(vehicle: number, level: number): boolean;
48
+ };
package/src/garages.ts ADDED
@@ -0,0 +1,101 @@
1
+ /**
2
+ * ai-core's garage layer: impound, store, open a garage menu and list a player's garaged vehicles through whichever
3
+ * garage script runs (ai-garages, tgiann-realparking, jg-advancedgarages...). Each script answers only what it really
4
+ * exposes. `docs/compat/garages.md`.
5
+ */
6
+
7
+ /** GlobalState key: the resource name of the garage script behind the garage layer (unset while none runs). */
8
+ export const GARAGES_STATE_KEY = "ai:garages";
9
+ /** Server -> client: ("open" | "store" | "impound", netId | null, garage | null) for garage scripts with a client API. */
10
+ export const GARAGES_CLIENT_EVENT = "ai-core:client:garages";
11
+
12
+ /** One of a player's vehicles kept by a garage script. */
13
+ export interface GaragedVehicle {
14
+ plate: string;
15
+ /** Spawn name when the script knows it. */
16
+ model: string | null;
17
+ /** The script's garage id; null when it has none (impound, a script without garage ids). */
18
+ garage: string | null;
19
+ impounded: boolean;
20
+ }
21
+
22
+ /** One garage script on ai-core's server (`resource/server/garages/`): every action is optional. */
23
+ export interface GarageAdapter {
24
+ resource: string;
25
+ version?: string;
26
+ /** Meant to run next to ai-garages (a parking or valet script that does not replace it). */
27
+ besideOurs?: boolean;
28
+ /**
29
+ * Sends a vehicle in the world to the impound, or opens the script's impound form for `by` (scripts with a client
30
+ * form only); true when the script took it over.
31
+ */
32
+ impound?(vehicle: number, plate: string, by: number | null): boolean;
33
+ /** Puts a vehicle in the world into a garage (`garage` null = the script's own pick); true when it took it. */
34
+ store?(
35
+ vehicle: number,
36
+ plate: string,
37
+ garage: string | null,
38
+ by: number | null,
39
+ ): boolean;
40
+ /** Opens the script's garage menu for a player; false when it cannot. */
41
+ open?(source: number, garage: string | null): boolean;
42
+ /** A player's vehicles in garages or the impound; null when the script cannot tell. */
43
+ stored?(source: number): Promise<GaragedVehicle[] | null>;
44
+ }
45
+
46
+ /** The client half of a garage script with a client API (`resource/client/garages/`). */
47
+ export interface GarageClientAdapter {
48
+ resource: string;
49
+ open?(garage: string | null): void;
50
+ store?(vehicle: number, garage: string | null): void;
51
+ impound?(vehicle: number): void;
52
+ }
53
+
54
+ /** ai-core's garage exports (lib `garages`): a vehicle is a server entity handle. */
55
+ export type GaragesServerExports = {
56
+ /** The garage script the layer forwards to, or null. */
57
+ GetGarageSystem(): string | null;
58
+ /** Impounds a vehicle (`by`: the player acting, for scripts with an impound form); false when nothing took it. */
59
+ ImpoundVehicle(vehicle: number, by?: number): boolean;
60
+ /** Stores a vehicle in a garage (null = the script's pick); false when nothing took it. */
61
+ StoreVehicleInGarage(
62
+ vehicle: number,
63
+ garage?: string | null,
64
+ by?: number,
65
+ ): boolean;
66
+ /** Opens the garage menu of the active script for a player; false when it has none. */
67
+ OpenGarage(source: number, garage?: string | null): boolean;
68
+ /** A player's garaged vehicles; `done` gets them, or null. A callback: no promise crosses a resource boundary. */
69
+ GetGaragedVehicles(
70
+ source: number,
71
+ done: (vehicles: GaragedVehicle[] | null) => void,
72
+ ): void;
73
+ };
74
+
75
+ /** ai-garages' own server exports (ai-core's garage adapter uses them; scripts use lib `garages`). */
76
+ export type AiGaragesServerExports = {
77
+ /** An owned vehicle goes to the impound (its entity removed); false when ai-vehicles does not own it. */
78
+ ImpoundVehicle(vehicle: number): boolean;
79
+ /** An owned vehicle goes into one of the panel's garages with its condition; false for a wrong garage or vehicle. */
80
+ StoreVehicle(vehicle: number, garage: string): boolean;
81
+ /** The player's character vehicles in a garage or the impound. */
82
+ GetStoredVehicles(source: number): GaragedVehicle[];
83
+ };
84
+
85
+ /** A garaged vehicle list from another resource, null when the shape is wrong. */
86
+ export function toGaragedVehicles(raw: unknown): GaragedVehicle[] | null {
87
+ if (!Array.isArray(raw)) return null;
88
+ const list: GaragedVehicle[] = [];
89
+ for (const v of raw) {
90
+ if (typeof v !== "object" || v === null) continue;
91
+ const r = v as Record<string, unknown>;
92
+ if (typeof r.plate !== "string") continue;
93
+ list.push({
94
+ plate: r.plate,
95
+ model: typeof r.model === "string" ? r.model : null,
96
+ garage: typeof r.garage === "string" ? r.garage : null,
97
+ impounded: r.impounded === true,
98
+ });
99
+ }
100
+ return list;
101
+ }
package/src/index.ts ADDED
@@ -0,0 +1,49 @@
1
+ export * from "./core";
2
+ export * from "./validation";
3
+ export type * from "./player";
4
+ export type * from "./logs";
5
+ export type * from "./definitions";
6
+ export type * from "./medical";
7
+ export type * from "./exports/coreServer";
8
+ export type * from "./exports/coreMoney";
9
+ export type * from "./exports/coreGroups";
10
+ export type * from "./exports/coreServices";
11
+ export type * from "./exports/coreLayers";
12
+ export * from "./exports/coreCharacters";
13
+ export type * from "./exports/coreClient";
14
+ export type * from "./exports/aiInventory";
15
+ export type * from "./exports/resources";
16
+ export type * from "./exports/citizen";
17
+ export * from "./inventory/items";
18
+ export * from "./inventory/adapters";
19
+ export * from "./inventory/exports";
20
+ export * from "./vehicleKeys";
21
+ export * from "./phone";
22
+ export * from "./dispatch";
23
+ export * from "./billing";
24
+ export type * from "./banking";
25
+ export * from "./mdt";
26
+ export * from "./ems";
27
+ export * from "./fuel";
28
+ export * from "./doorlock";
29
+ export * from "./garages";
30
+ export * from "./admin/lookups";
31
+ export * from "./admin/dataSpec";
32
+ export * from "./admin/widgets";
33
+ export * from "./admin/schema";
34
+ export * from "./admin/panel";
35
+ export * from "./admin/events";
36
+ export * from "./vehicles";
37
+ export * from "./menu";
38
+ export * from "./commands";
39
+ export * from "./radial";
40
+ export type * from "./action";
41
+ export * from "./world";
42
+ export * from "./appearance";
43
+ export * from "./minigame";
44
+ export * from "./ui";
45
+ export * from "./vrp";
46
+ export * from "./characters";
47
+ export * from "./bans";
48
+ export type * from "./multichar";
49
+ export type * from "./deaths";
@@ -0,0 +1,86 @@
1
+ import type {
2
+ HeldWeapon,
3
+ InventoryRef,
4
+ InventoryStack,
5
+ ItemDefinition,
6
+ ItemMetadata,
7
+ ShopDefinition,
8
+ StashDefinition,
9
+ } from "./items";
10
+ import type { CarryItem } from "./exports";
11
+
12
+ /** One inventory resource behind the layer (server side). Adapters translate calls and nothing else. */
13
+ export interface InventoryAdapter {
14
+ /** The inventory's resource name (detection, version check, panel choice). */
15
+ readonly resource: string;
16
+ /** The third-party inventory version the adapter is written against; another installed version logs a warning. None for ai-inventory. */
17
+ readonly version?: string;
18
+ addItem(
19
+ inv: InventoryRef,
20
+ item: string,
21
+ count: number,
22
+ metadata: ItemMetadata | undefined,
23
+ slot: number | undefined,
24
+ ): boolean;
25
+ removeItem(
26
+ inv: InventoryRef,
27
+ item: string,
28
+ count: number,
29
+ metadata: ItemMetadata | undefined,
30
+ slot: number | undefined,
31
+ ): boolean;
32
+ getItemCount(
33
+ inv: InventoryRef,
34
+ item: string,
35
+ metadata: ItemMetadata | undefined,
36
+ ): number;
37
+ canCarryItem(
38
+ inv: InventoryRef,
39
+ item: string,
40
+ count: number,
41
+ metadata: ItemMetadata | undefined,
42
+ ): boolean;
43
+ /** Whether all the items fit together; without it the layer checks each item on its own. */
44
+ canCarryItems?(inv: InventoryRef, items: CarryItem[]): boolean;
45
+ getItems(inv: InventoryRef): InventoryStack[];
46
+ clearInventory(inv: InventoryRef): void;
47
+ registerStash(stash: StashDefinition): void;
48
+ /** Opens a stash or another player's inventory on the player's screen, without range checks. */
49
+ openInventory(source: number, inv: InventoryRef): boolean;
50
+ getItemDefinition(name: string): ItemDefinition | null;
51
+ getItemDefinitions(): Record<string, ItemDefinition>;
52
+ /** A player's carried weight and limit, when the inventory tells them. */
53
+ getWeight?(source: number): { weight: number; maxWeight: number } | null;
54
+ /** Replaces the metadata of the stack at `slot`; false when the slot is empty or the inventory has no way. */
55
+ setMetadata(inv: InventoryRef, slot: number, metadata: ItemMetadata): boolean;
56
+ /** Sets a player's weight limit (grams) until the inventory reloads it; false when the inventory has no way. */
57
+ setMaxWeight(source: number, grams: number): boolean;
58
+ /**
59
+ * Inventories with their own usable item list get every handler here. The others call the framework's use
60
+ * functions (`ESX.UseItem`, QB `CanUseItem`), which ai-core's bridge answers from the layer.
61
+ */
62
+ registerUsableItem?(
63
+ name: string,
64
+ handler: (source: number, item: unknown) => unknown,
65
+ ): void;
66
+ /** Registers (or replaces) a script shop; absent when the inventory has no shops. */
67
+ registerShop?(shop: ShopDefinition): void;
68
+ /** Opens a registered shop on the player's screen, without range checks; false when it could not. */
69
+ openShop?(source: number, name: string): boolean;
70
+ }
71
+
72
+ /** One inventory resource behind the layer (client side). */
73
+ export interface InventoryClientAdapter {
74
+ readonly resource: string;
75
+ /** Opens the player's own inventory screen. */
76
+ openInventory(): void;
77
+ hasItem(item: string, count: number): boolean;
78
+ /** How many of an item the player holds, from the inventory's own client state; null when it has no such export. */
79
+ itemCount(item: string): number | null;
80
+ /** The held weapon item, or null (unarmed, or the inventory has no such export). */
81
+ currentWeapon(): HeldWeapon | null;
82
+ /** Every stack the player holds, from the inventory's own client state; null when it has no such export. */
83
+ items(): InventoryStack[] | null;
84
+ /** Calls `listener` when the player's items may have changed (the layer reads `items` and sends what changed). */
85
+ onChange?(listener: () => void): void;
86
+ }
@@ -0,0 +1,92 @@
1
+ import type {
2
+ HeldWeapon,
3
+ InventoryRef,
4
+ InventoryStack,
5
+ ItemDefinition,
6
+ ItemMetadata,
7
+ ShopProduct,
8
+ UsableItemHandler,
9
+ } from "./items";
10
+
11
+ /** One item of a combined carry check (`CanCarryItems`). */
12
+ export type CarryItem = { name: string; count: number; metadata?: ItemMetadata };
13
+
14
+ /** ai-core's server inventory exports; the active inventory answers them (false / 0 / empty while none runs). */
15
+ export type InventoryServerExports = {
16
+ AddItem(
17
+ inv: InventoryRef,
18
+ item: string,
19
+ count?: number,
20
+ metadata?: ItemMetadata,
21
+ slot?: number,
22
+ ): boolean;
23
+ RemoveItem(
24
+ inv: InventoryRef,
25
+ item: string,
26
+ count?: number,
27
+ metadata?: ItemMetadata,
28
+ slot?: number,
29
+ ): boolean;
30
+ GetItemCount(
31
+ inv: InventoryRef,
32
+ item: string,
33
+ metadata?: ItemMetadata,
34
+ ): number;
35
+ HasItem(inv: InventoryRef, item: string, count?: number): boolean;
36
+ CanCarryItem(
37
+ inv: InventoryRef,
38
+ item: string,
39
+ count?: number,
40
+ metadata?: ItemMetadata,
41
+ ): boolean;
42
+ /** Whether all the items fit together (weight and space shared, like one trade or reward). */
43
+ CanCarryItems(inv: InventoryRef, items: CarryItem[]): boolean;
44
+ GetItems(inv: InventoryRef): InventoryStack[];
45
+ ClearInventory(inv: InventoryRef): void;
46
+ /** Kept by ai-core and registered again with every inventory that becomes active. */
47
+ RegisterStash(
48
+ name: string,
49
+ label: string,
50
+ slots: number,
51
+ maxWeight: number,
52
+ jobs?: string[],
53
+ ): void;
54
+ OpenInventory(source: number, inv: InventoryRef): boolean;
55
+ /** Kept by ai-core: works for inventories that start later, survives an inventory restart. */
56
+ RegisterUsableItem(name: string, handler: UsableItemHandler): void;
57
+ GetItemDefinition(name: string): ItemDefinition | null;
58
+ GetItemDefinitions(): Record<string, ItemDefinition>;
59
+ /** A player's carried weight and limit (grams); null when the active inventory does not tell them. */
60
+ GetInventoryWeight(
61
+ source: number,
62
+ ): { weight: number; maxWeight: number } | null;
63
+ /** Kept by ai-core and registered again with every inventory that becomes active (`items`: `{ name, price }`). */
64
+ RegisterShop(name: string, label: string, items: ShopProduct[]): void;
65
+ /** Opens a registered shop on the player's screen (check access and range first); false when it could not. */
66
+ OpenShop(source: number, name: string): boolean;
67
+ /** Runs the handler registered for an item (ai-core's bridge calls it from `ESX.UseItem` / QB `CanUseItem`). */
68
+ UseItem(source: number, name: string, item?: unknown): unknown;
69
+ IsUsableItem(name: string): boolean;
70
+ /** Names of every item a handler is registered for (`RegisterUsableItem`). */
71
+ GetUsableItems(): string[];
72
+ /** Replaces the metadata of the stack at `slot` (weapon ammo, components, tint...); false when it could not. */
73
+ SetItemMetadata(inv: InventoryRef, slot: number, metadata: ItemMetadata): boolean;
74
+ /** Sets a player's weight limit in grams until the inventory reloads it; false when the inventory has no way. */
75
+ SetMaxWeight(source: number, grams: number): boolean;
76
+ };
77
+
78
+ /** ai-core's client inventory exports. */
79
+ export type InventoryClientExports = {
80
+ /** Opens the player's own inventory screen. */
81
+ OpenInventory(): void;
82
+ HasItem(item: string, count?: number): boolean;
83
+ /** The held weapon item through the active inventory, or null. */
84
+ GetCurrentWeapon(): HeldWeapon | null;
85
+ /** How many of an item the local player holds; null when the active inventory has no client count. */
86
+ GetItemCount(item: string): number | null;
87
+ /** Every stack the local player holds; null when the active inventory has no client list (ask the server). */
88
+ GetItems(): InventoryStack[] | null;
89
+ /** Every item definition of the active inventory (a copy of ai-core's client mirror). */
90
+ GetItemDefinitions(): Record<string, ItemDefinition>;
91
+ GetItemDefinition(name: string): ItemDefinition | null;
92
+ };