@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,79 @@
|
|
|
1
|
+
import { onStop } from "../fivem/byResource";
|
|
2
|
+
import { cache } from "./cache";
|
|
3
|
+
import { requestModel } from "./streaming";
|
|
4
|
+
|
|
5
|
+
interface Vec3 {
|
|
6
|
+
x: number;
|
|
7
|
+
y: number;
|
|
8
|
+
z: number;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface AttachPropOptions {
|
|
12
|
+
/** The ped that holds it (default the local ped). */
|
|
13
|
+
ped?: number;
|
|
14
|
+
/** Ped bone id (`57005` right hand), turned into the index with `GetPedBoneIndex`. */
|
|
15
|
+
bone: number;
|
|
16
|
+
offset?: Vec3;
|
|
17
|
+
rotation?: Vec3;
|
|
18
|
+
/** The prop collides (default false). */
|
|
19
|
+
collision?: boolean;
|
|
20
|
+
/** `AttachEntityToEntity`'s rotation order (default 2, R*'s). */
|
|
21
|
+
rotationOrder?: number;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** Props made by `attachProp` (with their model, so a reused handle is never deleted), removed when this resource stops. */
|
|
25
|
+
const props = new Map<number, number>();
|
|
26
|
+
let cleaning = false;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* A local prop held by a ped at a bone: resolves the entity, or 0 when the model does not load or the ped is gone.
|
|
30
|
+
* The caller deletes it (`DeleteEntity`); whatever is left goes when the resource stops.
|
|
31
|
+
*/
|
|
32
|
+
export async function attachProp(
|
|
33
|
+
model: string | number,
|
|
34
|
+
options: AttachPropOptions,
|
|
35
|
+
): Promise<number> {
|
|
36
|
+
const hash = await requestModel(model).catch(() => 0);
|
|
37
|
+
const ped = options.ped ?? cache.ped;
|
|
38
|
+
if (!hash) return 0;
|
|
39
|
+
if (!DoesEntityExist(ped)) {
|
|
40
|
+
SetModelAsNoLongerNeeded(hash);
|
|
41
|
+
return 0;
|
|
42
|
+
}
|
|
43
|
+
const [x = 0, y = 0, z = 0] = GetEntityCoords(ped, false);
|
|
44
|
+
const prop = CreateObject(hash, x, y, z, false, false, false);
|
|
45
|
+
SetModelAsNoLongerNeeded(hash);
|
|
46
|
+
const collision = options.collision ?? false;
|
|
47
|
+
if (!collision) SetEntityCollision(prop, false, false);
|
|
48
|
+
const o = options.offset ?? { x: 0, y: 0, z: 0 };
|
|
49
|
+
const r = options.rotation ?? { x: 0, y: 0, z: 0 };
|
|
50
|
+
AttachEntityToEntity(
|
|
51
|
+
prop,
|
|
52
|
+
ped,
|
|
53
|
+
GetPedBoneIndex(ped, options.bone),
|
|
54
|
+
o.x,
|
|
55
|
+
o.y,
|
|
56
|
+
o.z,
|
|
57
|
+
r.x,
|
|
58
|
+
r.y,
|
|
59
|
+
r.z,
|
|
60
|
+
true,
|
|
61
|
+
true,
|
|
62
|
+
collision,
|
|
63
|
+
false,
|
|
64
|
+
options.rotationOrder ?? 2,
|
|
65
|
+
true,
|
|
66
|
+
);
|
|
67
|
+
for (const [made, m] of props)
|
|
68
|
+
if (!DoesEntityExist(made) || GetEntityModel(made) !== m) props.delete(made);
|
|
69
|
+
props.set(prop, GetEntityModel(prop));
|
|
70
|
+
if (!cleaning) {
|
|
71
|
+
cleaning = true;
|
|
72
|
+
onStop(() => {
|
|
73
|
+
for (const [made, m] of props)
|
|
74
|
+
if (DoesEntityExist(made) && GetEntityModel(made) === m)
|
|
75
|
+
DeleteEntity(made);
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
return prop;
|
|
79
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { CORE, type RadialItem } from "@aifivem/shared";
|
|
2
|
+
import { resourceExport } from "../fivem/exports";
|
|
3
|
+
|
|
4
|
+
const core = resourceExport(CORE.resource);
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Items on whichever radial menu runs (ai-radialmenu, or another through ai-core's radial layer). ai-core keeps them
|
|
8
|
+
* across radial restarts and drops them when this resource stops: add once at start, no re-adding on a radial start.
|
|
9
|
+
*/
|
|
10
|
+
export const radial = {
|
|
11
|
+
/** Adds or replaces an item (`parent` puts it into a sub menu such as `RADIAL_VEHICLE`). */
|
|
12
|
+
add: (item: RadialItem): void => core.AddRadialItem(item),
|
|
13
|
+
remove: (id: string): void => core.RemoveRadialItem(id),
|
|
14
|
+
/** Reads every `canShow` of an open wheel again (after what they read changed). */
|
|
15
|
+
refresh: (): void => core.RefreshRadial(),
|
|
16
|
+
};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { Vec3 } from "../shared/vec";
|
|
2
|
+
import { cache } from "./cache";
|
|
3
|
+
|
|
4
|
+
/** What a line probe hit first: the point, the surface normal and the entity (0 = the map). */
|
|
5
|
+
export interface RayHit {
|
|
6
|
+
coords: Vec3;
|
|
7
|
+
normal: Vec3;
|
|
8
|
+
entity: number;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface RaycastOptions {
|
|
12
|
+
/** What the probe tests: 1 map, 2 vehicles, 4 peds, 8 ragdolls, 16 objects (default 1 | 2 | 16). */
|
|
13
|
+
flags?: number;
|
|
14
|
+
/** An entity the probe passes through (default the local ped). */
|
|
15
|
+
ignore?: number;
|
|
16
|
+
/** Probe option bits: 1 ignore glass, 2 ignore see-through, 4 ignore no-collision (default 7). */
|
|
17
|
+
options?: number;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* A line probe answered in the same frame (`StartExpensiveSynchronousShapeTestLosProbe`): what it hit first, or null.
|
|
22
|
+
* It blocks until the test is done, so keep it to one or two per frame.
|
|
23
|
+
*/
|
|
24
|
+
export function raycast(
|
|
25
|
+
from: Vec3,
|
|
26
|
+
to: Vec3,
|
|
27
|
+
{ flags = 1 | 2 | 16, ignore = cache.ped, options = 7 }: RaycastOptions = {},
|
|
28
|
+
): RayHit | null {
|
|
29
|
+
const [, hit, end, normal, entity] = GetShapeTestResult(
|
|
30
|
+
StartExpensiveSynchronousShapeTestLosProbe(
|
|
31
|
+
from.x,
|
|
32
|
+
from.y,
|
|
33
|
+
from.z,
|
|
34
|
+
to.x,
|
|
35
|
+
to.y,
|
|
36
|
+
to.z,
|
|
37
|
+
flags,
|
|
38
|
+
ignore,
|
|
39
|
+
options,
|
|
40
|
+
),
|
|
41
|
+
);
|
|
42
|
+
if (!hit) return null;
|
|
43
|
+
return {
|
|
44
|
+
coords: { x: end[0] ?? 0, y: end[1] ?? 0, z: end[2] ?? 0 },
|
|
45
|
+
normal: { x: normal[0] ?? 0, y: normal[1] ?? 0, z: normal[2] ?? 0 },
|
|
46
|
+
entity,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import type { Vec3 } from "../shared/vec";
|
|
2
|
+
import { TickLoop } from "./tickLoop";
|
|
3
|
+
|
|
4
|
+
/** Where a camera looks: a point it follows, or a fixed rotation (degrees); `fov` in degrees. */
|
|
5
|
+
export interface CameraView {
|
|
6
|
+
pointAt?: Vec3;
|
|
7
|
+
rotation?: Vec3;
|
|
8
|
+
fov?: number;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/** Depth of field: sharp between `near` and `far` metres, `strength` 0-1. */
|
|
12
|
+
export interface CameraBlur {
|
|
13
|
+
near: number;
|
|
14
|
+
far: number;
|
|
15
|
+
strength: number;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** Every camera this resource holds: given back to the game camera when the resource stops. */
|
|
19
|
+
const cameras = new Set<ScriptCamera>();
|
|
20
|
+
on("onClientResourceStop", (resource: string) => {
|
|
21
|
+
if (resource !== GetCurrentResourceName()) return;
|
|
22
|
+
for (const camera of cameras) camera.stop();
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* A scripted camera (a shop's showroom view, an editor, a scene, binoculars): `start` creates and renders it (easing
|
|
27
|
+
* in over `easeMs`), `move` / `pointAt` / `setFov` / `attach` change it, `glideTo` blends to a new shot, `shake` and
|
|
28
|
+
* `blur` add hand shake and depth of field, `stop` eases back to the game camera and destroys it. A camera still
|
|
29
|
+
* running when the resource stops is given back at once.
|
|
30
|
+
*/
|
|
31
|
+
export class ScriptCamera {
|
|
32
|
+
private handle = 0;
|
|
33
|
+
/** Cameras a `glideTo` blends away from; destroyed after the blend or on `stop`. */
|
|
34
|
+
private readonly retired = new Set<number>();
|
|
35
|
+
private shaking: { type: string; amplitude: number } | null = null;
|
|
36
|
+
private dof: CameraBlur | null = null;
|
|
37
|
+
private readonly hiDof = new TickLoop(() => SetUseHiDof());
|
|
38
|
+
|
|
39
|
+
/** `type`: the game camera name (`DEFAULT_SCRIPTED_FLY_CAMERA` for a hand-held view). */
|
|
40
|
+
constructor(private readonly type = "DEFAULT_SCRIPTED_CAMERA") {}
|
|
41
|
+
|
|
42
|
+
get active(): boolean {
|
|
43
|
+
return this.handle !== 0;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** The game handle (0 while stopped), for natives the class does not wrap. */
|
|
47
|
+
get cam(): number {
|
|
48
|
+
return this.handle;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
start(at: Vec3, view: CameraView = {}, easeMs = 0): void {
|
|
52
|
+
if (!this.handle) {
|
|
53
|
+
this.handle = CreateCam(this.type, true);
|
|
54
|
+
cameras.add(this);
|
|
55
|
+
}
|
|
56
|
+
this.move(at, view);
|
|
57
|
+
if (view.fov !== undefined) SetCamFov(this.handle, view.fov);
|
|
58
|
+
SetCamActive(this.handle, true);
|
|
59
|
+
RenderScriptCams(true, easeMs > 0, easeMs, true, true);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** Moves the camera, at once or gliding there over `ms` (the game interpolates). */
|
|
63
|
+
move(at: Vec3, view: CameraView = {}, ms = 0): void {
|
|
64
|
+
if (!this.handle) return;
|
|
65
|
+
if (ms > 0) {
|
|
66
|
+
const [rx = 0, ry = 0, rz = 0] = view.rotation
|
|
67
|
+
? [view.rotation.x, view.rotation.y, view.rotation.z]
|
|
68
|
+
: GetCamRot(this.handle, 2);
|
|
69
|
+
const fov = view.fov ?? GetCamFov(this.handle);
|
|
70
|
+
SetCamParams(this.handle, at.x, at.y, at.z, rx, ry, rz, fov, ms, 0, 0, 2);
|
|
71
|
+
} else SetCamCoord(this.handle, at.x, at.y, at.z);
|
|
72
|
+
if (view.pointAt) this.pointAt(view.pointAt);
|
|
73
|
+
else if (view.rotation && ms <= 0)
|
|
74
|
+
SetCamRot(
|
|
75
|
+
this.handle,
|
|
76
|
+
view.rotation.x,
|
|
77
|
+
view.rotation.y,
|
|
78
|
+
view.rotation.z,
|
|
79
|
+
2,
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Blends to a new shot over `ms`: a second camera at the new place takes over from this one (the old one is
|
|
85
|
+
* destroyed after the blend). Shake and blur carry over. Starts the camera when it is stopped.
|
|
86
|
+
*/
|
|
87
|
+
glideTo(at: Vec3, view: CameraView, ms: number): void {
|
|
88
|
+
if (!this.handle || ms <= 0) return this.start(at, view);
|
|
89
|
+
const old = this.handle;
|
|
90
|
+
const r = view.rotation;
|
|
91
|
+
this.handle = CreateCamWithParams(
|
|
92
|
+
this.type,
|
|
93
|
+
at.x,
|
|
94
|
+
at.y,
|
|
95
|
+
at.z,
|
|
96
|
+
r?.x ?? 0,
|
|
97
|
+
r?.y ?? 0,
|
|
98
|
+
r?.z ?? 0,
|
|
99
|
+
view.fov ?? GetCamFov(old),
|
|
100
|
+
false,
|
|
101
|
+
2,
|
|
102
|
+
);
|
|
103
|
+
if (view.pointAt) this.pointAt(view.pointAt);
|
|
104
|
+
if (this.shaking) this.shake(this.shaking.type, this.shaking.amplitude);
|
|
105
|
+
this.blur(this.dof);
|
|
106
|
+
SetCamActiveWithInterp(this.handle, old, ms, 1, 1);
|
|
107
|
+
this.retired.add(old);
|
|
108
|
+
setTimeout(() => {
|
|
109
|
+
if (this.retired.delete(old)) DestroyCam(old, false);
|
|
110
|
+
}, ms + 150);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/** Follows an entity at `offset` (entity space), turning with it when `relative`. */
|
|
114
|
+
attach(entity: number, offset: Vec3, relative = true): void {
|
|
115
|
+
if (this.handle)
|
|
116
|
+
AttachCamToEntity(
|
|
117
|
+
this.handle,
|
|
118
|
+
entity,
|
|
119
|
+
offset.x,
|
|
120
|
+
offset.y,
|
|
121
|
+
offset.z,
|
|
122
|
+
relative,
|
|
123
|
+
);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
pointAt(target: Vec3): void {
|
|
127
|
+
if (this.handle) PointCamAtCoord(this.handle, target.x, target.y, target.z);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
setFov(fov: number): void {
|
|
131
|
+
if (this.handle) SetCamFov(this.handle, fov);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/** The game's camera shake (`HAND_SHAKE`, `ROAD_VIBRATION_SHAKE`...); amplitude 0 stops it. */
|
|
135
|
+
shake(type: string, amplitude: number): void {
|
|
136
|
+
this.shaking = amplitude > 0 ? { type, amplitude } : null;
|
|
137
|
+
if (!this.handle) return;
|
|
138
|
+
if (amplitude > 0) ShakeCam(this.handle, type, amplitude);
|
|
139
|
+
else StopCamShaking(this.handle, true);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/** Depth of field, or null for none (needs a per-frame native, so it runs only while set). */
|
|
143
|
+
blur(dof: CameraBlur | null): void {
|
|
144
|
+
this.dof = dof;
|
|
145
|
+
this.hiDof.set(dof !== null && this.handle !== 0);
|
|
146
|
+
if (!this.handle) return;
|
|
147
|
+
SetCamUseShallowDofMode(this.handle, dof !== null);
|
|
148
|
+
if (!dof) return;
|
|
149
|
+
SetCamNearDof(this.handle, dof.near);
|
|
150
|
+
SetCamFarDof(this.handle, dof.far);
|
|
151
|
+
SetCamDofStrength(this.handle, dof.strength);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/** Back to the game camera (easing over `easeMs`) and the camera is destroyed. */
|
|
155
|
+
stop(easeMs = 0): void {
|
|
156
|
+
if (!this.handle) return;
|
|
157
|
+
RenderScriptCams(false, easeMs > 0, easeMs, true, true);
|
|
158
|
+
DestroyCam(this.handle, false);
|
|
159
|
+
for (const cam of this.retired) DestroyCam(cam, false);
|
|
160
|
+
this.retired.clear();
|
|
161
|
+
this.hiDof.set(false);
|
|
162
|
+
this.shaking = null;
|
|
163
|
+
this.dof = null;
|
|
164
|
+
this.handle = 0;
|
|
165
|
+
cameras.delete(this);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { CORE } from "@aifivem/shared";
|
|
2
|
+
import { resourceExport } from "../fivem/exports";
|
|
3
|
+
|
|
4
|
+
const core = resourceExport(CORE.resource);
|
|
5
|
+
|
|
6
|
+
/** The local player's seat belt through ai-core, whatever seat belt script runs (ai-smallresources, a HUD's own). */
|
|
7
|
+
export const seatbelt = {
|
|
8
|
+
/** Whether the belt is on; null when no seat belt script answers (on demand, not per frame). */
|
|
9
|
+
isOn: (): boolean | null => core.GetSeatbelt(),
|
|
10
|
+
/** `fn(worn)` when the belt changes, from scripts that tell changes (ai-smallresources, qbx_seatbelt). */
|
|
11
|
+
onChange(fn: (worn: boolean | null) => void): void {
|
|
12
|
+
on(CORE.clientSeatbeltEvent, (worn: unknown) =>
|
|
13
|
+
fn(typeof worn === "boolean" ? worn : null),
|
|
14
|
+
);
|
|
15
|
+
},
|
|
16
|
+
/** The seat belt script that answers, or null. */
|
|
17
|
+
provider: (): string | null => core.GetSeatbeltProvider(),
|
|
18
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { cache, onCache } from "./cache";
|
|
2
|
+
import { TickLoop } from "./tickLoop";
|
|
3
|
+
|
|
4
|
+
type ShotHandler = (weapon: number) => void;
|
|
5
|
+
const handlers = new Set<ShotHandler>();
|
|
6
|
+
|
|
7
|
+
/** `IsPedShooting` is true only in the frame of the shot, so it is read every frame, but only while a weapon is held. */
|
|
8
|
+
const frame = new TickLoop(() => {
|
|
9
|
+
const weapon = cache.weapon;
|
|
10
|
+
if (weapon === false || !IsPedShooting(cache.ped)) return;
|
|
11
|
+
for (const handler of handlers) handler(weapon);
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
const update = (): void =>
|
|
15
|
+
frame.set(handlers.size > 0 && cache.weapon !== false);
|
|
16
|
+
onCache("weapon", update);
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Runs `handler(weapon)` in the frame the local ped fires a shot (stress, shot alerts). One per-frame check for the
|
|
20
|
+
* resource, on only while a weapon is in hand. Keep the handler cheap (it runs inside the frame).
|
|
21
|
+
*/
|
|
22
|
+
export function onShot(handler: ShotHandler): () => void {
|
|
23
|
+
handlers.add(handler);
|
|
24
|
+
update();
|
|
25
|
+
return () => {
|
|
26
|
+
handlers.delete(handler);
|
|
27
|
+
update();
|
|
28
|
+
};
|
|
29
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { waitFor } from "../shared";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Loads a model and resolves with its hash. Rejects when the model does not exist or does not load in time.
|
|
5
|
+
* Call `SetModelAsNoLongerNeeded(hash)` once the entity is created.
|
|
6
|
+
*/
|
|
7
|
+
export async function requestModel(
|
|
8
|
+
model: string | number,
|
|
9
|
+
timeoutMs = 10_000,
|
|
10
|
+
): Promise<number> {
|
|
11
|
+
const hash = typeof model === "number" ? model : GetHashKey(model);
|
|
12
|
+
if (!IsModelInCdimage(hash)) throw new Error(`model ${model} does not exist`);
|
|
13
|
+
RequestModel(hash);
|
|
14
|
+
await waitFor(() => HasModelLoaded(hash) || undefined, timeoutMs);
|
|
15
|
+
return hash;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** Loads an animation dictionary. Call `RemoveAnimDict(dict)` when it is no longer played. */
|
|
19
|
+
export async function requestAnimDict(
|
|
20
|
+
dict: string,
|
|
21
|
+
timeoutMs = 10_000,
|
|
22
|
+
): Promise<string> {
|
|
23
|
+
if (!DoesAnimDictExist(dict))
|
|
24
|
+
throw new Error(`anim dict ${dict} does not exist`);
|
|
25
|
+
RequestAnimDict(dict);
|
|
26
|
+
await waitFor(() => HasAnimDictLoaded(dict) || undefined, timeoutMs);
|
|
27
|
+
return dict;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** Loads a particle asset. Call `RemoveNamedPtfxAsset(asset)` when done. */
|
|
31
|
+
export async function requestPtfxAsset(
|
|
32
|
+
asset: string,
|
|
33
|
+
timeoutMs = 10_000,
|
|
34
|
+
): Promise<string> {
|
|
35
|
+
RequestNamedPtfxAsset(asset);
|
|
36
|
+
await waitFor(() => HasNamedPtfxAssetLoaded(asset) || undefined, timeoutMs);
|
|
37
|
+
return asset;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Loads a movement clipset (crouch walk, injured walk). Call `RemoveAnimSet(set)` when it is no longer used. */
|
|
41
|
+
export async function requestAnimSet(
|
|
42
|
+
set: string,
|
|
43
|
+
timeoutMs = 10_000,
|
|
44
|
+
): Promise<string> {
|
|
45
|
+
RequestAnimSet(set);
|
|
46
|
+
await waitFor(() => HasAnimSetLoaded(set) || undefined, timeoutMs);
|
|
47
|
+
return set;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** Loads a streamed texture dictionary. Call `SetStreamedTextureDictAsNoLongerNeeded(dict)` when done. */
|
|
51
|
+
export async function requestTextureDict(
|
|
52
|
+
dict: string,
|
|
53
|
+
timeoutMs = 10_000,
|
|
54
|
+
): Promise<string> {
|
|
55
|
+
RequestStreamedTextureDict(dict, false);
|
|
56
|
+
await waitFor(
|
|
57
|
+
() => HasStreamedTextureDictLoaded(dict) || undefined,
|
|
58
|
+
timeoutMs,
|
|
59
|
+
);
|
|
60
|
+
return dict;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** Loads a weapon's model and assets and resolves with its hash. Call `RemoveWeaponAsset(hash)` when done. */
|
|
64
|
+
export async function requestWeaponAsset(
|
|
65
|
+
weapon: string | number,
|
|
66
|
+
timeoutMs = 10_000,
|
|
67
|
+
): Promise<number> {
|
|
68
|
+
const hash = typeof weapon === "number" ? weapon : GetHashKey(weapon);
|
|
69
|
+
RequestWeaponAsset(hash, 31, 0);
|
|
70
|
+
await waitFor(() => HasWeaponAssetLoaded(hash) || undefined, timeoutMs);
|
|
71
|
+
return hash;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Loads a scaleform movie and resolves its handle, or 0 when it does not load within `timeoutMs`.
|
|
76
|
+
* Call `SetScaleformMovieAsNoLongerNeeded(handle)` when done.
|
|
77
|
+
*/
|
|
78
|
+
export async function requestScaleformMovie(
|
|
79
|
+
name: string,
|
|
80
|
+
timeoutMs = 10_000,
|
|
81
|
+
): Promise<number> {
|
|
82
|
+
const handle = RequestScaleformMovie(name);
|
|
83
|
+
if (!handle) return 0;
|
|
84
|
+
const loaded = await waitFor(
|
|
85
|
+
() => HasScaleformMovieLoaded(handle) || undefined,
|
|
86
|
+
timeoutMs,
|
|
87
|
+
).catch(() => false);
|
|
88
|
+
if (loaded) return handle;
|
|
89
|
+
SetScaleformMovieAsNoLongerNeeded(handle);
|
|
90
|
+
return 0;
|
|
91
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { every, type Job } from "../fivem/scheduler/every";
|
|
2
|
+
|
|
3
|
+
/** A per-frame job (`every(0, fn)` on the resource's scheduler) switched on only while needed. */
|
|
4
|
+
export class TickLoop {
|
|
5
|
+
private readonly job: Job;
|
|
6
|
+
|
|
7
|
+
constructor(onFrame: () => void, name?: string) {
|
|
8
|
+
this.job = every(0, onFrame, { active: false, name });
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
get running(): boolean {
|
|
12
|
+
return this.job.running;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
set(active: boolean): void {
|
|
16
|
+
this.job.set(active);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { CORE } from "@aifivem/shared";
|
|
2
|
+
import { resourceExport } from "../fivem/exports";
|
|
3
|
+
|
|
4
|
+
const core = resourceExport(CORE.resource);
|
|
5
|
+
|
|
6
|
+
/** Vehicle keys of the local player through ai-core's client key layer. */
|
|
7
|
+
export const vehicleKeys = {
|
|
8
|
+
/**
|
|
9
|
+
* Whether the player holds a vehicle's keys (entity or plate), from ai-core's short-lived mirror of the server's
|
|
10
|
+
* answers: a vehicle the player never entered answers false once while ai-core asks the server.
|
|
11
|
+
*/
|
|
12
|
+
has: (vehicle: number | string): boolean =>
|
|
13
|
+
core.HasVehicleKeys(vehicle) === true,
|
|
14
|
+
};
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import type { VehicleProps, VehicleSetup } from "../shared/vehicleProps";
|
|
2
|
+
|
|
3
|
+
const MOD_TYPES = Array.from({ length: 50 }, (_, i) => i);
|
|
4
|
+
const TOGGLE_MODS = [17, 18, 19, 20, 21, 22];
|
|
5
|
+
|
|
6
|
+
/** Reads every property of a vehicle the local client can see. */
|
|
7
|
+
export function getVehicleProps(vehicle: number): VehicleProps {
|
|
8
|
+
const [primary, secondary] = GetVehicleColours(vehicle);
|
|
9
|
+
const [pearl, wheel] = GetVehicleExtraColours(vehicle);
|
|
10
|
+
const mods: Record<number, number> = {};
|
|
11
|
+
for (const type of MOD_TYPES) {
|
|
12
|
+
if (TOGGLE_MODS.includes(type))
|
|
13
|
+
mods[type] = IsToggleModOn(vehicle, type) ? 1 : 0;
|
|
14
|
+
else mods[type] = GetVehicleMod(vehicle, type);
|
|
15
|
+
}
|
|
16
|
+
const extras: Record<number, boolean> = {};
|
|
17
|
+
for (let id = 0; id <= 14; id++)
|
|
18
|
+
if (DoesExtraExist(vehicle, id))
|
|
19
|
+
extras[id] = IsVehicleExtraTurnedOn(vehicle, id);
|
|
20
|
+
const custom = (
|
|
21
|
+
get: (v: number) => [number, number, number],
|
|
22
|
+
has: boolean,
|
|
23
|
+
) => (has ? get(vehicle) : null);
|
|
24
|
+
return {
|
|
25
|
+
v: 1,
|
|
26
|
+
model: GetEntityModel(vehicle),
|
|
27
|
+
plate: GetVehicleNumberPlateText(vehicle).trim(),
|
|
28
|
+
plateIndex: GetVehicleNumberPlateTextIndex(vehicle),
|
|
29
|
+
colors: [primary ?? 0, secondary ?? 0],
|
|
30
|
+
extraColors: [pearl ?? 0, wheel ?? 0],
|
|
31
|
+
customPrimary: custom(
|
|
32
|
+
GetVehicleCustomPrimaryColour,
|
|
33
|
+
GetIsVehiclePrimaryColourCustom(vehicle),
|
|
34
|
+
),
|
|
35
|
+
customSecondary: custom(
|
|
36
|
+
GetVehicleCustomSecondaryColour,
|
|
37
|
+
GetIsVehicleSecondaryColourCustom(vehicle),
|
|
38
|
+
),
|
|
39
|
+
wheelType: GetVehicleWheelType(vehicle),
|
|
40
|
+
windowTint: GetVehicleWindowTint(vehicle),
|
|
41
|
+
livery: GetVehicleLivery(vehicle),
|
|
42
|
+
mods,
|
|
43
|
+
xenonColor: GetVehicleXenonLightsColor(vehicle),
|
|
44
|
+
neon: [0, 1, 2, 3].map((i) =>
|
|
45
|
+
IsVehicleNeonLightEnabled(vehicle, i),
|
|
46
|
+
) as VehicleProps["neon"],
|
|
47
|
+
neonColor: GetVehicleNeonLightsColour(vehicle),
|
|
48
|
+
tyreSmoke: GetVehicleTyreSmokeColor(vehicle),
|
|
49
|
+
extras,
|
|
50
|
+
dirt: GetVehicleDirtLevel(vehicle),
|
|
51
|
+
engineHealth: GetVehicleEngineHealth(vehicle),
|
|
52
|
+
bodyHealth: GetVehicleBodyHealth(vehicle),
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** Applies stored properties (only to a vehicle this client controls; others get them through the network). */
|
|
57
|
+
export function setVehicleProps(vehicle: number, props: VehicleProps): void {
|
|
58
|
+
SetVehicleModKit(vehicle, 0);
|
|
59
|
+
SetVehicleNumberPlateText(vehicle, props.plate);
|
|
60
|
+
SetVehicleNumberPlateTextIndex(vehicle, props.plateIndex);
|
|
61
|
+
SetVehicleColours(vehicle, props.colors[0], props.colors[1]);
|
|
62
|
+
SetVehicleExtraColours(vehicle, props.extraColors[0], props.extraColors[1]);
|
|
63
|
+
if (props.customPrimary)
|
|
64
|
+
SetVehicleCustomPrimaryColour(vehicle, ...props.customPrimary);
|
|
65
|
+
if (props.customSecondary)
|
|
66
|
+
SetVehicleCustomSecondaryColour(vehicle, ...props.customSecondary);
|
|
67
|
+
SetVehicleWheelType(vehicle, props.wheelType);
|
|
68
|
+
SetVehicleWindowTint(vehicle, props.windowTint);
|
|
69
|
+
for (const [type, index] of Object.entries(props.mods)) {
|
|
70
|
+
const t = Number(type);
|
|
71
|
+
if (TOGGLE_MODS.includes(t)) ToggleVehicleMod(vehicle, t, index === 1);
|
|
72
|
+
else SetVehicleMod(vehicle, t, index, false);
|
|
73
|
+
}
|
|
74
|
+
SetVehicleLivery(vehicle, props.livery);
|
|
75
|
+
SetVehicleXenonLightsColor(vehicle, props.xenonColor);
|
|
76
|
+
props.neon.forEach((on, i) => SetVehicleNeonLightEnabled(vehicle, i, on));
|
|
77
|
+
SetVehicleNeonLightsColour(vehicle, ...props.neonColor);
|
|
78
|
+
SetVehicleTyreSmokeColor(vehicle, ...props.tyreSmoke);
|
|
79
|
+
for (const [id, on] of Object.entries(props.extras))
|
|
80
|
+
SetVehicleExtra(vehicle, Number(id), !on);
|
|
81
|
+
SetVehicleDirtLevel(vehicle, props.dirt);
|
|
82
|
+
SetVehicleEngineHealth(vehicle, props.engineHealth);
|
|
83
|
+
SetVehicleBodyHealth(vehicle, props.bodyHealth);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** Engine, brakes, transmission, suspension, armour: the mods `maxed` sets to their top level. */
|
|
87
|
+
const PERFORMANCE_MODS = [11, 12, 13, 15, 16];
|
|
88
|
+
|
|
89
|
+
/** Applies a spawn setup (only to a vehicle this client controls). */
|
|
90
|
+
export function setVehicleSetup(vehicle: number, setup: VehicleSetup): void {
|
|
91
|
+
SetVehicleModKit(vehicle, 0);
|
|
92
|
+
if (setup.maxed) {
|
|
93
|
+
for (const mod of PERFORMANCE_MODS)
|
|
94
|
+
SetVehicleMod(vehicle, mod, GetNumVehicleMods(vehicle, mod) - 1, false);
|
|
95
|
+
ToggleVehicleMod(vehicle, 18, true);
|
|
96
|
+
ToggleVehicleMod(vehicle, 22, true);
|
|
97
|
+
}
|
|
98
|
+
if (setup.colors) SetVehicleColours(vehicle, ...setup.colors);
|
|
99
|
+
if (setup.primary) SetVehicleCustomPrimaryColour(vehicle, ...setup.primary);
|
|
100
|
+
if (setup.secondary)
|
|
101
|
+
SetVehicleCustomSecondaryColour(vehicle, ...setup.secondary);
|
|
102
|
+
if (setup.livery !== undefined) SetVehicleLivery(vehicle, setup.livery);
|
|
103
|
+
if (setup.windowTint !== undefined)
|
|
104
|
+
SetVehicleWindowTint(vehicle, setup.windowTint);
|
|
105
|
+
if (setup.dirt !== undefined) SetVehicleDirtLevel(vehicle, setup.dirt);
|
|
106
|
+
if (setup.engineOn) SetVehicleEngineOn(vehicle, true, true, false);
|
|
107
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { Vec3 } from "../shared/vec";
|
|
2
|
+
import { cache } from "./cache";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The closest vehicle within `metres` of the local player (the one the player sits in first, unless `notOwn`) or of
|
|
6
|
+
* `from` (a point: only distance counts, the player's own vehicle included unless `notOwn`); `networked` (default
|
|
7
|
+
* true) skips local-only vehicles (previews, props); `filter` skips vehicles it refuses (the closest one the player
|
|
8
|
+
* stands behind, not merely the closest). 0 when none. Its distance: `nearestEntity("vehicle", ...)`.
|
|
9
|
+
*/
|
|
10
|
+
export function nearestVehicle(
|
|
11
|
+
metres: number,
|
|
12
|
+
options: {
|
|
13
|
+
networked?: boolean;
|
|
14
|
+
notOwn?: boolean;
|
|
15
|
+
filter?: (vehicle: number) => boolean;
|
|
16
|
+
from?: Vec3;
|
|
17
|
+
} = {},
|
|
18
|
+
): number {
|
|
19
|
+
const { filter, from } = options;
|
|
20
|
+
// The own vehicle is preferred only when measuring from the player; it is skipped in the walk when it was offered.
|
|
21
|
+
const skipOwn = options.notOwn || !from;
|
|
22
|
+
if (cache.vehicle !== false && !options.notOwn && !from) {
|
|
23
|
+
if (!filter || filter(cache.vehicle)) return cache.vehicle;
|
|
24
|
+
}
|
|
25
|
+
let x: number;
|
|
26
|
+
let y: number;
|
|
27
|
+
let z: number;
|
|
28
|
+
if (from) ({ x, y, z } = from);
|
|
29
|
+
else [x = 0, y = 0, z = 0] = GetEntityCoords(cache.ped, false);
|
|
30
|
+
let best = 0;
|
|
31
|
+
let bestDistance = metres;
|
|
32
|
+
for (const vehicle of GetGamePool("CVehicle") as number[]) {
|
|
33
|
+
if (skipOwn && vehicle === cache.vehicle) continue;
|
|
34
|
+
if (options.networked !== false && !NetworkGetEntityIsNetworked(vehicle))
|
|
35
|
+
continue;
|
|
36
|
+
const [vx = 0, vy = 0, vz = 0] = GetEntityCoords(vehicle, false);
|
|
37
|
+
const d = Math.hypot(vx - x, vy - y, vz - z);
|
|
38
|
+
if (d < bestDistance && (!filter || filter(vehicle)))
|
|
39
|
+
[best, bestDistance] = [vehicle, d];
|
|
40
|
+
}
|
|
41
|
+
return best;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** The vehicle the local player drives (driver seat), false otherwise. */
|
|
45
|
+
export const drivenVehicle = (): number | false =>
|
|
46
|
+
cache.seat === -1 ? cache.vehicle : false;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** GTA's waypoint blip sprite. */
|
|
2
|
+
const WAYPOINT_SPRITE = 8;
|
|
3
|
+
|
|
4
|
+
/** The waypoint the player set on the map (x, y), or null. */
|
|
5
|
+
export function waypoint(): { x: number; y: number } | null {
|
|
6
|
+
const blip = GetFirstBlipInfoId(WAYPOINT_SPRITE);
|
|
7
|
+
if (!DoesBlipExist(blip)) return null;
|
|
8
|
+
const [x = 0, y = 0] = GetBlipInfoIdCoord(blip);
|
|
9
|
+
return { x, y };
|
|
10
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { CORE } from "@aifivem/shared";
|
|
2
|
+
import { resourceExport } from "../fivem/exports";
|
|
3
|
+
|
|
4
|
+
const core = resourceExport(CORE.resource);
|
|
5
|
+
|
|
6
|
+
/** The weather and time sync of whatever weather script runs, paused while a reason holds (an interior, a scene). */
|
|
7
|
+
export const world = {
|
|
8
|
+
pauseSync: (reason: string): void => core.PauseWorldSync(reason),
|
|
9
|
+
resumeSync: (reason: string): void => core.ResumeWorldSync(reason),
|
|
10
|
+
};
|