@aifivem/lib 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 +34 -4
- package/src/client/action.ts +38 -0
- package/src/client/adminWorld.ts +95 -0
- package/src/client/appearance.ts +29 -0
- package/src/client/areaFollower.ts +41 -0
- package/src/client/blip.ts +79 -0
- package/src/client/cache.ts +66 -0
- package/src/client/callback.ts +70 -0
- package/src/client/controls.ts +73 -0
- package/src/client/entities.ts +83 -0
- package/src/client/entity.ts +26 -0
- package/src/client/fuel.ts +18 -0
- package/src/client/gestures.ts +18 -0
- package/src/client/headshot.ts +26 -0
- package/src/client/hud.ts +24 -0
- package/src/client/index.ts +131 -0
- package/src/client/inventory.ts +117 -0
- package/src/client/keyHints.ts +13 -0
- package/src/client/keybind.ts +163 -0
- package/src/client/localPed.ts +169 -0
- package/src/client/location.ts +54 -0
- package/src/client/mdt.ts +10 -0
- package/src/client/medical.ts +28 -0
- package/src/client/membership.ts +41 -0
- package/src/client/menu/dialogs.ts +77 -0
- package/src/client/menu/minigames.ts +79 -0
- package/src/client/menu/requests.ts +65 -0
- package/src/client/modelScan/def.ts +29 -0
- package/src/client/modelScan/objectIndex.ts +41 -0
- package/src/client/modelScan/scan.ts +69 -0
- package/src/client/modelScan/scanner.ts +164 -0
- package/src/client/netEvent.ts +40 -0
- package/src/client/notify.ts +14 -0
- package/src/client/nuiScreen.ts +87 -0
- package/src/client/player/anim.ts +98 -0
- package/src/client/player/fade.ts +17 -0
- package/src/client/player/player.ts +80 -0
- package/src/client/player/teleport.ts +87 -0
- package/src/client/playerData.ts +83 -0
- package/src/client/players.ts +44 -0
- package/src/client/points/interact.ts +144 -0
- package/src/client/points/modelHost.ts +117 -0
- package/src/client/points/modelPoint.ts +181 -0
- package/src/client/points/point.ts +159 -0
- package/src/client/points/points.ts +170 -0
- package/src/client/points/targets/adapter.ts +40 -0
- package/src/client/points/targets/interactTarget.ts +45 -0
- package/src/client/points/targets/optionShape.ts +22 -0
- package/src/client/points/targets/oxTarget.ts +42 -0
- package/src/client/points/targets/qbTarget.ts +71 -0
- package/src/client/points/targets/targets.ts +20 -0
- package/src/client/preview.ts +51 -0
- package/src/client/progress.ts +132 -0
- package/src/client/prompt.ts +26 -0
- package/src/client/prop.ts +79 -0
- package/src/client/radial.ts +16 -0
- package/src/client/raycast.ts +48 -0
- package/src/client/scriptCamera.ts +167 -0
- package/src/client/seatbelt.ts +18 -0
- package/src/client/shot.ts +29 -0
- package/src/client/streaming.ts +91 -0
- package/src/client/tickLoop.ts +18 -0
- package/src/client/vehicleKeys.ts +14 -0
- package/src/client/vehicleProps.ts +107 -0
- package/src/client/vehicles.ts +46 -0
- package/src/client/waypoint.ts +10 -0
- package/src/client/world.ts +10 -0
- package/src/client/zoneEngine.ts +174 -0
- package/src/client/zones.ts +161 -0
- package/src/fivem/byResource.ts +146 -0
- package/src/fivem/callbackNames.ts +12 -0
- package/src/fivem/exports.ts +70 -0
- package/src/fivem/index.ts +13 -0
- package/src/fivem/locale.ts +57 -0
- package/src/fivem/playerData.ts +13 -0
- package/src/fivem/scheduler/every.ts +101 -0
- package/src/fivem/scheduler/group.ts +97 -0
- package/src/fivem/scheduler/scheduler.ts +77 -0
- package/src/fivem/state/entityState.ts +75 -0
- package/src/fivem/state/globalState.ts +80 -0
- package/src/fivem/state/mirror.ts +47 -0
- package/src/fivem/state/playerState.ts +60 -0
- package/src/server/admin/descriptions.ts +57 -0
- package/src/server/admin/edit.ts +127 -0
- package/src/server/admin/jsonSchema.ts +156 -0
- package/src/server/admin/panel.ts +167 -0
- package/src/server/admin/panelFiles.ts +128 -0
- package/src/server/admin/patch.ts +46 -0
- package/src/server/admin/validate.ts +147 -0
- package/src/server/appearance.ts +28 -0
- package/src/server/areaStream/areaStream.ts +141 -0
- package/src/server/areaStream/followers.ts +154 -0
- package/src/server/areaStream/grid.ts +74 -0
- package/src/server/areaStream/options.ts +16 -0
- package/src/server/banking.ts +15 -0
- package/src/server/bans.ts +47 -0
- package/src/server/billing.ts +20 -0
- package/src/server/buckets.ts +12 -0
- package/src/server/callback.ts +112 -0
- package/src/server/characters.ts +129 -0
- package/src/server/command/addCommand.ts +83 -0
- package/src/server/command/command.ts +116 -0
- package/src/server/command/commandSet.ts +74 -0
- package/src/server/dataFile.ts +81 -0
- package/src/server/database.ts +117 -0
- package/src/server/definitions.ts +65 -0
- package/src/server/dispatch.ts +13 -0
- package/src/server/doors.ts +15 -0
- package/src/server/ems.ts +15 -0
- package/src/server/fuel.ts +15 -0
- package/src/server/garages.ts +34 -0
- package/src/server/gate.ts +148 -0
- package/src/server/index.ts +165 -0
- package/src/server/inventory.ts +106 -0
- package/src/server/jobs.ts +42 -0
- package/src/server/log.ts +21 -0
- package/src/server/mdt.ts +12 -0
- package/src/server/medical.ts +16 -0
- package/src/server/minigameFor.ts +65 -0
- package/src/server/money.ts +70 -0
- package/src/server/netEntity.ts +19 -0
- package/src/server/netEvent.ts +58 -0
- package/src/server/notify.ts +17 -0
- package/src/server/online/mirror.ts +176 -0
- package/src/server/online/online.ts +190 -0
- package/src/server/pending.ts +70 -0
- package/src/server/phone.ts +22 -0
- package/src/server/players.ts +197 -0
- package/src/server/position.ts +31 -0
- package/src/server/primeTime.ts +7 -0
- package/src/server/prison.ts +15 -0
- package/src/server/progressFor.ts +62 -0
- package/src/server/proximity.ts +98 -0
- package/src/server/rateLimit.ts +53 -0
- package/src/server/state.ts +45 -0
- package/src/server/stress.ts +25 -0
- package/src/server/vehicle/nearby.ts +66 -0
- package/src/server/vehicle/plate.ts +14 -0
- package/src/server/vehicle/spawn.ts +125 -0
- package/src/server/vehicle/vehicleType.ts +50 -0
- package/src/server/vehicleKeys.ts +23 -0
- package/src/server/watchers.ts +46 -0
- package/src/server/world.ts +16 -0
- package/src/shared/access.ts +94 -0
- package/src/shared/action.ts +28 -0
- package/src/shared/blipStyle.ts +26 -0
- package/src/shared/clock.ts +22 -0
- package/src/shared/format.ts +36 -0
- package/src/shared/grid.ts +20 -0
- package/src/shared/index.ts +179 -0
- package/src/shared/lang.ts +39 -0
- package/src/shared/placePed.ts +96 -0
- package/src/shared/random.ts +11 -0
- package/src/shared/read.ts +60 -0
- package/src/shared/records.ts +148 -0
- package/src/shared/spec.ts +20 -0
- package/src/shared/strict.ts +70 -0
- package/src/shared/vec.ts +48 -0
- package/src/shared/vehicleProps.ts +138 -0
- package/src/shared/wait.ts +27 -0
- package/src/shared/zone.ts +144 -0
- package/README.md +0 -3
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import { onStyleChange, onTargetChange, style } from "./interact";
|
|
2
|
+
import { Blips } from "../blip";
|
|
3
|
+
import { LocalPed } from "../localPed";
|
|
4
|
+
import {
|
|
5
|
+
ModelPoint,
|
|
6
|
+
type ModelPointOptions,
|
|
7
|
+
type VehiclePointOptions,
|
|
8
|
+
} from "./modelPoint";
|
|
9
|
+
import { onPromptPressed } from "../prompt";
|
|
10
|
+
import { Point, type PointOptions } from "./point";
|
|
11
|
+
import { Zones } from "../zones";
|
|
12
|
+
|
|
13
|
+
const groups = new Set<Points>();
|
|
14
|
+
const byPrompt = new Map<string, { press(): void }>();
|
|
15
|
+
let nextGroup = 0;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Interaction points of a script (counters, shop doors, NPCs): one object per point instead of zones + prompts +
|
|
19
|
+
* blips + peds by hand. Each point shows as ai-core's prompt (interaction key) or as a target option, as the owner
|
|
20
|
+
* picks in ai-core's panel (Interaction); the same `onPressed` runs either way. Rebuild with `clear()` + `add()` when
|
|
21
|
+
* the panel changes the points; call `refresh()` when what `canShow` reads changes (job, duty, vehicle).
|
|
22
|
+
*/
|
|
23
|
+
export class Points {
|
|
24
|
+
private readonly zones = new Zones();
|
|
25
|
+
private readonly blips = new Blips();
|
|
26
|
+
private readonly points = new Map<string, Point>();
|
|
27
|
+
private readonly modelPoints = new Map<string, ModelPoint>();
|
|
28
|
+
private readonly prefix = `pt${++nextGroup}:`;
|
|
29
|
+
|
|
30
|
+
constructor() {
|
|
31
|
+
groups.add(this);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** Adds (or replaces) a point. */
|
|
35
|
+
add(id: string, options: PointOptions): void {
|
|
36
|
+
this.remove(id);
|
|
37
|
+
const point = new Point(this.prefix + id, options);
|
|
38
|
+
this.points.set(id, point);
|
|
39
|
+
byPrompt.set(point.promptId, point);
|
|
40
|
+
if (options.ped) {
|
|
41
|
+
const ped = options.ped;
|
|
42
|
+
point.ped = new LocalPed({
|
|
43
|
+
...ped,
|
|
44
|
+
coords: ped.coords ?? { ...options.coords, heading: 0 },
|
|
45
|
+
onSpawn: () => point.attach(style()),
|
|
46
|
+
onDespawn: () => point.detach(),
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
if (options.blip)
|
|
50
|
+
this.blips.add(id, {
|
|
51
|
+
...options.blip,
|
|
52
|
+
coords: options.blip.coords ?? options.coords,
|
|
53
|
+
});
|
|
54
|
+
this.zones.add(id, {
|
|
55
|
+
shape:
|
|
56
|
+
options.height !== undefined
|
|
57
|
+
? {
|
|
58
|
+
type: "cylinder",
|
|
59
|
+
center: options.coords,
|
|
60
|
+
radius: options.radius ?? 2,
|
|
61
|
+
height: options.height,
|
|
62
|
+
}
|
|
63
|
+
: {
|
|
64
|
+
type: "sphere",
|
|
65
|
+
center: options.coords,
|
|
66
|
+
radius: options.radius ?? 2,
|
|
67
|
+
},
|
|
68
|
+
interval: options.interval,
|
|
69
|
+
onEnter: () => {
|
|
70
|
+
point.inside = true;
|
|
71
|
+
point.sync(style());
|
|
72
|
+
options.onEnter?.();
|
|
73
|
+
},
|
|
74
|
+
onExit: () => {
|
|
75
|
+
point.inside = false;
|
|
76
|
+
point.sync(style());
|
|
77
|
+
options.onExit?.();
|
|
78
|
+
},
|
|
79
|
+
});
|
|
80
|
+
point.attach(style());
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** Adds (or replaces) a point on every world object of some models (ATMs, vending machines). */
|
|
84
|
+
addModel(id: string, options: ModelPointOptions): void {
|
|
85
|
+
this.remove(id);
|
|
86
|
+
const point = new ModelPoint(this.prefix + id, options);
|
|
87
|
+
this.modelPoints.set(id, point);
|
|
88
|
+
byPrompt.set(point.promptId, point);
|
|
89
|
+
point.attach(style());
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Adds (or replaces) a point on every vehicle (trunk, hood, push): a global vehicle option in target mode, a prompt
|
|
94
|
+
* at the nearest networked vehicle within `radius` otherwise. `canShow` and `onPressed` get the vehicle.
|
|
95
|
+
*/
|
|
96
|
+
addVehicle(id: string, options: VehiclePointOptions): void {
|
|
97
|
+
this.addModel(id, { ...options, models: [], vehicles: true });
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
remove(id: string): void {
|
|
101
|
+
const model = this.modelPoints.get(id);
|
|
102
|
+
if (model) {
|
|
103
|
+
model.detach();
|
|
104
|
+
byPrompt.delete(model.promptId);
|
|
105
|
+
this.modelPoints.delete(id);
|
|
106
|
+
}
|
|
107
|
+
const point = this.points.get(id);
|
|
108
|
+
if (!point) return;
|
|
109
|
+
this.zones.remove(id);
|
|
110
|
+
point.detach();
|
|
111
|
+
point.sync("target");
|
|
112
|
+
point.ped?.remove();
|
|
113
|
+
this.blips.remove(id);
|
|
114
|
+
byPrompt.delete(point.promptId);
|
|
115
|
+
this.points.delete(id);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
clear(): void {
|
|
119
|
+
for (const id of [...this.points.keys(), ...this.modelPoints.keys()])
|
|
120
|
+
this.remove(id);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Checks `canShow` and a function `label` again (prompt mode; targets ask `canShow` when opened and get a changed
|
|
125
|
+
* label re-registered). Call it from a lib state class's `onChange` (the new value is readable there).
|
|
126
|
+
*/
|
|
127
|
+
refresh(id?: string): void {
|
|
128
|
+
const mode = style();
|
|
129
|
+
const one = id !== undefined ? this.points.get(id) : undefined;
|
|
130
|
+
for (const [mid, model] of this.modelPoints)
|
|
131
|
+
if (id === undefined || id === mid) model.refresh(mode);
|
|
132
|
+
for (const point of one
|
|
133
|
+
? [one]
|
|
134
|
+
: id === undefined
|
|
135
|
+
? this.points.values()
|
|
136
|
+
: []) {
|
|
137
|
+
point.sync(mode);
|
|
138
|
+
if (
|
|
139
|
+
point.style(mode) === "target" &&
|
|
140
|
+
typeof point.options.label === "function" &&
|
|
141
|
+
point.targetLabel !== point.text()
|
|
142
|
+
) {
|
|
143
|
+
point.detach();
|
|
144
|
+
point.attach(mode);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
isInside(id: string): boolean {
|
|
150
|
+
return this.points.get(id)?.inside ?? false;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/** Puts every point on the current interaction style (style switch, target resource restart). */
|
|
154
|
+
restyle(): void {
|
|
155
|
+
const mode = style();
|
|
156
|
+
for (const point of this.points.values()) {
|
|
157
|
+
point.detach();
|
|
158
|
+
point.attach(mode);
|
|
159
|
+
point.sync(mode);
|
|
160
|
+
}
|
|
161
|
+
for (const model of this.modelPoints.values()) model.restyle(mode);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
onPromptPressed((id) => byPrompt.get(id)?.press());
|
|
166
|
+
const restyleAll = () => {
|
|
167
|
+
for (const group of groups) group.restyle();
|
|
168
|
+
};
|
|
169
|
+
onStyleChange(restyleAll);
|
|
170
|
+
onTargetChange(restyleAll);
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { Vec3 } from "../../../shared/vec";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The target scripts lib `Points` put their options on, one adapter each, in the order they win when several run
|
|
5
|
+
* (`docs/compat/target.md`). The calls run in the resource that owns the points: every target ties an option's
|
|
6
|
+
* functions to the calling resource and drops them when it stops, so they never go through ai-core.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/** One target option in the lib's terms; each adapter turns it into its script's shape. */
|
|
10
|
+
export interface TargetOption {
|
|
11
|
+
/** Unique across resources (`<resource>:<prompt id>`): some targets remove by it from one shared list. */
|
|
12
|
+
name: string;
|
|
13
|
+
label: string;
|
|
14
|
+
icon?: string;
|
|
15
|
+
/** How close the player must be, in metres. */
|
|
16
|
+
distance: number;
|
|
17
|
+
canInteract(entity: number): boolean;
|
|
18
|
+
onSelect(entity: number): void;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** The calls `Points` make on a target script; any of them throws "No such export" while that script loads. */
|
|
22
|
+
export interface TargetAdapter {
|
|
23
|
+
/** False when it cannot take an option at a bare point from JavaScript (it needs a Lua vector3): such points stay prompts. */
|
|
24
|
+
readonly coords: boolean;
|
|
25
|
+
/** An option on a spot `radius` metres wide at `coords`; returns the handle `removeZone` takes. */
|
|
26
|
+
addSphere(coords: Vec3, radius: number, option: TargetOption): unknown;
|
|
27
|
+
removeZone(handle: unknown, option: TargetOption): void;
|
|
28
|
+
addLocalEntity(entity: number, option: TargetOption): void;
|
|
29
|
+
removeLocalEntity(entity: number, option: TargetOption): void;
|
|
30
|
+
addModels(models: Array<string | number>, option: TargetOption): void;
|
|
31
|
+
removeModels(models: Array<string | number>, option: TargetOption): void;
|
|
32
|
+
addGlobalVehicle(option: TargetOption): void;
|
|
33
|
+
removeGlobalVehicle(option: TargetOption): void;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface Target {
|
|
37
|
+
/** The resource whose started state picks this target. */
|
|
38
|
+
resource: string;
|
|
39
|
+
adapter: TargetAdapter;
|
|
40
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { callExport } from "../../../fivem/exports";
|
|
2
|
+
import type { TargetAdapter, TargetOption } from "./adapter";
|
|
3
|
+
import { entityOf } from "./optionShape";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* interact (darktrovx, `client/interactions.lua`): world bubbles with options, removed by id. A point at bare
|
|
7
|
+
* coordinates needs a Lua vector3, which JavaScript cannot send: those points stay prompts (the Lua lib places them).
|
|
8
|
+
*/
|
|
9
|
+
export const interact = ((): TargetAdapter => {
|
|
10
|
+
const call = (fn: string, ...args: unknown[]) =>
|
|
11
|
+
callExport("interact", fn, ...args);
|
|
12
|
+
const hashOf = (model: string | number) =>
|
|
13
|
+
typeof model === "number" ? model : GetHashKey(model);
|
|
14
|
+
const data = (o: TargetOption) => ({
|
|
15
|
+
id: o.name,
|
|
16
|
+
interactDst: o.distance,
|
|
17
|
+
options: [
|
|
18
|
+
{
|
|
19
|
+
label: o.label,
|
|
20
|
+
action: (entity: unknown) => o.onSelect(entityOf(entity)),
|
|
21
|
+
canInteract: (entity: unknown) => o.canInteract(entityOf(entity)),
|
|
22
|
+
},
|
|
23
|
+
],
|
|
24
|
+
});
|
|
25
|
+
return {
|
|
26
|
+
coords: false,
|
|
27
|
+
addSphere: () => null,
|
|
28
|
+
removeZone: () => undefined,
|
|
29
|
+
addLocalEntity: (entity, o) =>
|
|
30
|
+
void call("AddLocalEntityInteraction", { ...data(o), entity }),
|
|
31
|
+
removeLocalEntity: (entity, o) =>
|
|
32
|
+
void call("RemoveLocalEntityInteraction", entity, o.name),
|
|
33
|
+
addModels: (models, o) => {
|
|
34
|
+
for (const model of models)
|
|
35
|
+
call("AddModelInteraction", { ...data(o), model: hashOf(model) });
|
|
36
|
+
},
|
|
37
|
+
removeModels: (models, o) => {
|
|
38
|
+
for (const model of models)
|
|
39
|
+
call("RemoveModelInteraction", hashOf(model), o.name);
|
|
40
|
+
},
|
|
41
|
+
addGlobalVehicle: (o) => void call("AddGlobalVehicleInteraction", data(o)),
|
|
42
|
+
removeGlobalVehicle: (o) =>
|
|
43
|
+
void call("RemoveGlobalVehicleInteraction", o.name),
|
|
44
|
+
};
|
|
45
|
+
})();
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { TargetOption } from "./adapter";
|
|
2
|
+
|
|
3
|
+
export const entityOf = (value: unknown): number =>
|
|
4
|
+
typeof value === "number"
|
|
5
|
+
? value
|
|
6
|
+
: typeof value === "object" && value !== null
|
|
7
|
+
? entityOf(Reflect.get(value, "entity"))
|
|
8
|
+
: 0;
|
|
9
|
+
|
|
10
|
+
/** A Font Awesome class: `store` becomes `fa-solid fa-store`, a full class stays. */
|
|
11
|
+
export const faClass = (icon: string | undefined): string | undefined =>
|
|
12
|
+
icon === undefined || icon.includes("fa-") ? icon : `fa-solid fa-${icon}`;
|
|
13
|
+
|
|
14
|
+
/** The ox_target option shape (sleepless_interact takes the same). */
|
|
15
|
+
export const oxOption = (o: TargetOption) => ({
|
|
16
|
+
name: o.name,
|
|
17
|
+
label: o.label,
|
|
18
|
+
icon: faClass(o.icon),
|
|
19
|
+
distance: o.distance,
|
|
20
|
+
canInteract: (entity: unknown) => o.canInteract(entityOf(entity)),
|
|
21
|
+
onSelect: (data: unknown) => o.onSelect(entityOf(data)),
|
|
22
|
+
});
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { callExport } from "../../../fivem/exports";
|
|
2
|
+
import type { TargetAdapter } from "./adapter";
|
|
3
|
+
import { oxOption } from "./optionShape";
|
|
4
|
+
|
|
5
|
+
/** The ox_target API, answered under `name` (ox_target, ai-target, tgiann-target and tgiann-radialmenu-target). */
|
|
6
|
+
export function oxApi(name: string): TargetAdapter {
|
|
7
|
+
const call = (fn: string, ...args: unknown[]) =>
|
|
8
|
+
callExport(name, fn, ...args);
|
|
9
|
+
return {
|
|
10
|
+
coords: true,
|
|
11
|
+
addSphere: (coords, radius, o) =>
|
|
12
|
+
call("addSphereZone", { coords, radius, options: [oxOption(o)] }),
|
|
13
|
+
removeZone: (id) => void call("removeZone", id),
|
|
14
|
+
addLocalEntity: (entity, o) =>
|
|
15
|
+
void call("addLocalEntity", entity, [oxOption(o)]),
|
|
16
|
+
removeLocalEntity: (entity, o) =>
|
|
17
|
+
void call("removeLocalEntity", entity, o.name),
|
|
18
|
+
addModels: (models, o) => void call("addModel", models, [oxOption(o)]),
|
|
19
|
+
removeModels: (models, o) => void call("removeModel", models, o.name),
|
|
20
|
+
addGlobalVehicle: (o) => void call("addGlobalVehicle", [oxOption(o)]),
|
|
21
|
+
removeGlobalVehicle: (o) => void call("removeGlobalVehicle", o.name),
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** sleepless_interact 2.x own API (`client/api.lua`): options at coordinates instead of zones, the ox option shape. */
|
|
26
|
+
export const sleeplessInteract = ((): TargetAdapter => {
|
|
27
|
+
const call = (fn: string, ...args: unknown[]) =>
|
|
28
|
+
callExport("sleepless_interact", fn, ...args);
|
|
29
|
+
return {
|
|
30
|
+
coords: true,
|
|
31
|
+
addSphere: (coords, _radius, o) => call("addCoords", coords, [oxOption(o)]),
|
|
32
|
+
removeZone: (id, o) => void call("removeCoords", id, o.name),
|
|
33
|
+
addLocalEntity: (entity, o) =>
|
|
34
|
+
void call("addLocalEntity", entity, [oxOption(o)]),
|
|
35
|
+
removeLocalEntity: (entity, o) =>
|
|
36
|
+
void call("removeLocalEntity", entity, o.name),
|
|
37
|
+
addModels: (models, o) => void call("addModel", models, [oxOption(o)]),
|
|
38
|
+
removeModels: (models, o) => void call("removeModel", models, o.name),
|
|
39
|
+
addGlobalVehicle: (o) => void call("addGlobalVehicle", [oxOption(o)]),
|
|
40
|
+
removeGlobalVehicle: (o) => void call("removeGlobalVehicle", o.name),
|
|
41
|
+
};
|
|
42
|
+
})();
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { onStop } from "../../../fivem/byResource";
|
|
2
|
+
import { callExport } from "../../../fivem/exports";
|
|
3
|
+
import type { TargetAdapter, TargetOption } from "./adapter";
|
|
4
|
+
import { entityOf, faClass } from "./optionShape";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* qb-target 5.x (`registration.lua`): options keyed by their label, zones by a global name. It keeps a stopped
|
|
8
|
+
* resource's options (with dead function references), so this resource takes its own off when it stops.
|
|
9
|
+
*/
|
|
10
|
+
export const qbTarget = ((): TargetAdapter => {
|
|
11
|
+
const call = (fn: string, ...args: unknown[]) =>
|
|
12
|
+
callExport("qb-target", fn, ...args);
|
|
13
|
+
const live = new Map<string, () => void>();
|
|
14
|
+
onStop(() => {
|
|
15
|
+
for (const remove of live.values())
|
|
16
|
+
try {
|
|
17
|
+
remove();
|
|
18
|
+
} catch {
|
|
19
|
+
// qb-target stopped first: nothing left to take off.
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
const keep = (key: string, remove: () => void) => live.set(key, remove);
|
|
23
|
+
const drop = (key: string) => {
|
|
24
|
+
live.get(key)?.();
|
|
25
|
+
live.delete(key);
|
|
26
|
+
};
|
|
27
|
+
const params = (o: TargetOption) => ({
|
|
28
|
+
distance: o.distance,
|
|
29
|
+
options: [
|
|
30
|
+
{
|
|
31
|
+
label: o.label,
|
|
32
|
+
icon: faClass(o.icon),
|
|
33
|
+
action: (entity: unknown) => o.onSelect(entityOf(entity)),
|
|
34
|
+
canInteract: (entity: unknown) => o.canInteract(entityOf(entity)),
|
|
35
|
+
},
|
|
36
|
+
],
|
|
37
|
+
});
|
|
38
|
+
return {
|
|
39
|
+
coords: true,
|
|
40
|
+
addSphere: (coords, radius, o) => {
|
|
41
|
+
call(
|
|
42
|
+
"AddCircleZone",
|
|
43
|
+
o.name,
|
|
44
|
+
coords,
|
|
45
|
+
radius,
|
|
46
|
+
{ name: o.name, useZ: true, debugPoly: false },
|
|
47
|
+
params(o),
|
|
48
|
+
);
|
|
49
|
+
keep(`z:${o.name}`, () => call("RemoveZone", o.name));
|
|
50
|
+
return o.name;
|
|
51
|
+
},
|
|
52
|
+
removeZone: (_name, o) => drop(`z:${o.name}`),
|
|
53
|
+
addLocalEntity: (entity, o) => {
|
|
54
|
+
call("AddTargetEntity", entity, params(o));
|
|
55
|
+
keep(`e:${entity}:${o.name}`, () =>
|
|
56
|
+
call("RemoveTargetEntity", entity, o.label),
|
|
57
|
+
);
|
|
58
|
+
},
|
|
59
|
+
removeLocalEntity: (entity, o) => drop(`e:${entity}:${o.name}`),
|
|
60
|
+
addModels: (models, o) => {
|
|
61
|
+
call("AddTargetModel", models, params(o));
|
|
62
|
+
keep(`m:${o.name}`, () => call("RemoveTargetModel", models, o.label));
|
|
63
|
+
},
|
|
64
|
+
removeModels: (_models, o) => drop(`m:${o.name}`),
|
|
65
|
+
addGlobalVehicle: (o) => {
|
|
66
|
+
call("AddGlobalVehicle", params(o));
|
|
67
|
+
keep(`v:${o.name}`, () => call("RemoveGlobalVehicle", o.label));
|
|
68
|
+
},
|
|
69
|
+
removeGlobalVehicle: (o) => drop(`v:${o.name}`),
|
|
70
|
+
};
|
|
71
|
+
})();
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { Target } from "./adapter";
|
|
2
|
+
import { oxApi, sleeplessInteract } from "./oxTarget";
|
|
3
|
+
import { qbTarget } from "./qbTarget";
|
|
4
|
+
import { interact } from "./interactTarget";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Win order: ai-target, then TGIANN, then the others. Scripts that `provide` ox_target or qb-target come before those
|
|
8
|
+
* names, because a provided name reads started too; interact goes last (it often runs next to a target as a
|
|
9
|
+
* dependency of other scripts).
|
|
10
|
+
*/
|
|
11
|
+
export const TARGETS: readonly Target[] = [
|
|
12
|
+
{ resource: "ai-target", adapter: oxApi("ai-target") },
|
|
13
|
+
// Answers the ox_target API under `tgiann-target` and `ox_target`, not under its own name.
|
|
14
|
+
{ resource: "tgiann-radialmenu-target", adapter: oxApi("tgiann-target") },
|
|
15
|
+
{ resource: "tgiann-target", adapter: oxApi("tgiann-target") },
|
|
16
|
+
{ resource: "sleepless_interact", adapter: sleeplessInteract },
|
|
17
|
+
{ resource: "ox_target", adapter: oxApi("ox_target") },
|
|
18
|
+
{ resource: "qb-target", adapter: qbTarget },
|
|
19
|
+
{ resource: "interact", adapter: interact },
|
|
20
|
+
];
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { onStop } from "../fivem/byResource";
|
|
2
|
+
import { requestModel } from "./streaming";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* A local preview vehicle (showrooms): `show` puts a model at a point, frozen, invincible, locked and clean; the
|
|
6
|
+
* latest call wins (an older one still loading its model does nothing). Deleted on `clear()` and when the resource
|
|
7
|
+
* stops. Nothing networked.
|
|
8
|
+
*/
|
|
9
|
+
export class PreviewVehicle {
|
|
10
|
+
/** The vehicle shown now, 0 when none. */
|
|
11
|
+
vehicle = 0;
|
|
12
|
+
private token = 0;
|
|
13
|
+
|
|
14
|
+
constructor() {
|
|
15
|
+
onStop(() => this.clear());
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** Shows `model` at `at` (`setup` dresses it: colours, plate, props); resolves the vehicle, or 0 when replaced. */
|
|
19
|
+
async show(
|
|
20
|
+
model: string | number,
|
|
21
|
+
at: { x: number; y: number; z: number; heading: number },
|
|
22
|
+
setup?: (vehicle: number) => void,
|
|
23
|
+
): Promise<number> {
|
|
24
|
+
const token = ++this.token;
|
|
25
|
+
const hash = await requestModel(model).catch(() => 0);
|
|
26
|
+
if (!hash || token !== this.token) return 0;
|
|
27
|
+
this.remove();
|
|
28
|
+
const vehicle = CreateVehicle(hash, at.x, at.y, at.z, at.heading, false, false);
|
|
29
|
+
SetModelAsNoLongerNeeded(hash);
|
|
30
|
+
SetVehicleOnGroundProperly(vehicle);
|
|
31
|
+
FreezeEntityPosition(vehicle, true);
|
|
32
|
+
SetEntityInvincible(vehicle, true);
|
|
33
|
+
SetVehicleDoorsLocked(vehicle, 2);
|
|
34
|
+
SetVehicleDirtLevel(vehicle, 0);
|
|
35
|
+
setup?.(vehicle);
|
|
36
|
+
this.vehicle = vehicle;
|
|
37
|
+
return vehicle;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Removes the preview and cancels a show still loading. */
|
|
41
|
+
clear(): void {
|
|
42
|
+
this.token++;
|
|
43
|
+
this.remove();
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
private remove(): void {
|
|
47
|
+
if (this.vehicle && DoesEntityExist(this.vehicle))
|
|
48
|
+
DeleteEntity(this.vehicle);
|
|
49
|
+
this.vehicle = 0;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { medical } from "./medical";
|
|
2
|
+
import { LIB_UI } from "@aifivem/shared";
|
|
3
|
+
import { resourceExport } from "../fivem/exports";
|
|
4
|
+
import { every } from "../fivem/scheduler/every";
|
|
5
|
+
import { cache } from "./cache";
|
|
6
|
+
import { controls } from "./controls";
|
|
7
|
+
import { sleep } from "../shared/wait";
|
|
8
|
+
import type { Vec3 } from "../shared/vec";
|
|
9
|
+
import { requestAnimDict } from "./streaming";
|
|
10
|
+
|
|
11
|
+
const ui = resourceExport(LIB_UI.resource);
|
|
12
|
+
|
|
13
|
+
/** Controls each `disable` flag blocks while a progress runs. */
|
|
14
|
+
const DISABLED = {
|
|
15
|
+
move: [30, 31, 36, 21, 44],
|
|
16
|
+
car: [63, 64, 71, 72, 75],
|
|
17
|
+
mouse: [1, 2, 106],
|
|
18
|
+
combat: [24, 25, 37, 47, 58, 140, 141, 142, 143, 257, 263, 264],
|
|
19
|
+
} as const;
|
|
20
|
+
|
|
21
|
+
export interface ProgressOptions {
|
|
22
|
+
label: string;
|
|
23
|
+
/** Milliseconds. */
|
|
24
|
+
duration: number;
|
|
25
|
+
anim?: { dict: string; clip: string; flag?: number };
|
|
26
|
+
/** A scenario played in place (`WORLD_HUMAN_HAMMERING`) when there is no `anim`. */
|
|
27
|
+
scenario?: string;
|
|
28
|
+
/** Getting into a vehicle cancels it unless true. */
|
|
29
|
+
allowVehicle?: boolean;
|
|
30
|
+
/** The player may cancel it with ai-lib's cancel key (default false). */
|
|
31
|
+
canCancel?: boolean;
|
|
32
|
+
/** Keeps running when the player dies (default false: death cancels). */
|
|
33
|
+
whileDead?: boolean;
|
|
34
|
+
/** Holds the player in place while it runs. */
|
|
35
|
+
freeze?: boolean;
|
|
36
|
+
/** Controls blocked while it runs: walking, driving, looking around, fighting. */
|
|
37
|
+
disable?: {
|
|
38
|
+
move?: boolean;
|
|
39
|
+
car?: boolean;
|
|
40
|
+
mouse?: boolean;
|
|
41
|
+
combat?: boolean;
|
|
42
|
+
};
|
|
43
|
+
/** The player turns to this point before the bar starts (a pump, a counter, a vehicle). */
|
|
44
|
+
face?: Vec3;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** How long the ped gets to turn towards `face`. */
|
|
48
|
+
const FACE_MS = 600;
|
|
49
|
+
|
|
50
|
+
/** The running progress of this resource (one at a time). */
|
|
51
|
+
let running: { canCancel: boolean; cancelled: boolean } | null = null;
|
|
52
|
+
|
|
53
|
+
on(LIB_UI.cancelProgressEvent, () => {
|
|
54
|
+
if (running?.canCancel) running.cancelled = true;
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
/** Cancels this resource's running progress (whether or not the player may). */
|
|
58
|
+
export function cancelProgress(): void {
|
|
59
|
+
if (running) running.cancelled = true;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export function isProgressRunning(): boolean {
|
|
63
|
+
return running !== null;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function disabledControls(disable: ProgressOptions["disable"]): number[] {
|
|
67
|
+
const list: number[] = [];
|
|
68
|
+
if (!disable) return list;
|
|
69
|
+
for (const key of ["move", "car", "mouse", "combat"] as const)
|
|
70
|
+
if (disable[key]) list.push(...DISABLED[key]);
|
|
71
|
+
return list;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Runs a timed action with ai-lib's progress bar and an optional animation or scenario; resolves true when it ran
|
|
76
|
+
* out, false when cancelled (death, a vehicle, the cancel key, `cancelProgress`) or while another one of this
|
|
77
|
+
* resource runs. Checks ten times a second; blocked controls go through the lib's one per-frame `controls` job.
|
|
78
|
+
*/
|
|
79
|
+
export async function progress(options: ProgressOptions): Promise<boolean> {
|
|
80
|
+
if (running) return false;
|
|
81
|
+
const own = { canCancel: options.canCancel === true, cancelled: false };
|
|
82
|
+
running = own;
|
|
83
|
+
const ped = cache.ped;
|
|
84
|
+
const { anim, scenario, face } = options;
|
|
85
|
+
if (face && cache.vehicle === false) {
|
|
86
|
+
TaskTurnPedToFaceCoord(ped, face.x, face.y, face.z, FACE_MS);
|
|
87
|
+
await sleep(FACE_MS);
|
|
88
|
+
}
|
|
89
|
+
if (anim) {
|
|
90
|
+
await requestAnimDict(anim.dict);
|
|
91
|
+
TaskPlayAnim(
|
|
92
|
+
ped,
|
|
93
|
+
anim.dict,
|
|
94
|
+
anim.clip,
|
|
95
|
+
3,
|
|
96
|
+
3,
|
|
97
|
+
options.duration,
|
|
98
|
+
anim.flag ?? 49,
|
|
99
|
+
0,
|
|
100
|
+
false,
|
|
101
|
+
false,
|
|
102
|
+
false,
|
|
103
|
+
);
|
|
104
|
+
} else if (scenario) TaskStartScenarioInPlace(ped, scenario, 0, true);
|
|
105
|
+
if (options.freeze) FreezeEntityPosition(ped, true);
|
|
106
|
+
const blocked = disabledControls(options.disable);
|
|
107
|
+
if (blocked.length) controls.disable("progress", blocked);
|
|
108
|
+
ui.ShowProgress(options.label, options.duration);
|
|
109
|
+
const end = GetGameTimer() + options.duration;
|
|
110
|
+
const done = await new Promise<boolean>((resolve) => {
|
|
111
|
+
const job = every(
|
|
112
|
+
100,
|
|
113
|
+
() => {
|
|
114
|
+
const cancelled =
|
|
115
|
+
own.cancelled ||
|
|
116
|
+
(!options.whileDead && medical.isDead()) ||
|
|
117
|
+
(!options.allowVehicle && cache.vehicle !== false);
|
|
118
|
+
if (!cancelled && GetGameTimer() < end) return;
|
|
119
|
+
job.stop();
|
|
120
|
+
resolve(!cancelled);
|
|
121
|
+
},
|
|
122
|
+
{ name: "progress" },
|
|
123
|
+
);
|
|
124
|
+
});
|
|
125
|
+
if (anim) StopAnimTask(ped, anim.dict, anim.clip, 1);
|
|
126
|
+
else if (scenario) ClearPedTasks(ped);
|
|
127
|
+
if (options.freeze) FreezeEntityPosition(ped, false);
|
|
128
|
+
if (blocked.length) controls.enable("progress");
|
|
129
|
+
ui.HideProgress();
|
|
130
|
+
running = null;
|
|
131
|
+
return done;
|
|
132
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { LIB_UI, type PromptAnchor } from "@aifivem/shared";
|
|
2
|
+
import { resourceExport } from "../fivem/exports";
|
|
3
|
+
|
|
4
|
+
const ui = resourceExport(LIB_UI.resource);
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* ai-lib's prompt (the "press E" box on the right): this resource shows and hides its own prompts by id; the
|
|
8
|
+
* interaction key is one rebindable keybind in ai-lib, so nothing polls keys per frame. Show a prompt on a zone's
|
|
9
|
+
* enter, hide it on exit, act in `onPromptPressed`. With `at` the prompt floats over that world point instead
|
|
10
|
+
* (a door), the same key acting on it.
|
|
11
|
+
*/
|
|
12
|
+
export function showPrompt(id: string, text: string, at?: PromptAnchor): void {
|
|
13
|
+
ui.ShowPrompt(id, text, at);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function hidePrompt(id: string): void {
|
|
17
|
+
ui.HidePrompt(id);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** The player pressed the interaction key while this resource's prompt `id` was the one on top. */
|
|
21
|
+
export function onPromptPressed(handler: (id: string) => void): void {
|
|
22
|
+
const resource = GetCurrentResourceName();
|
|
23
|
+
on(LIB_UI.promptPressedEvent, (owner: unknown, id: unknown) => {
|
|
24
|
+
if (owner === resource && typeof id === "string") handler(id);
|
|
25
|
+
});
|
|
26
|
+
}
|