pma-locals 1.0.10 → 1.0.11
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/dist/index.d.mts +4 -4
- package/dist/index.mjs +25 -20
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AnimationFlags
|
|
1
|
+
import { AnimationFlags } from "@nativewrappers/redm";
|
|
2
2
|
|
|
3
3
|
//#region types/index.d.ts
|
|
4
4
|
interface Animation {
|
|
@@ -16,15 +16,15 @@ interface Props {
|
|
|
16
16
|
//#region client/ped-handler.d.ts
|
|
17
17
|
interface PedConfig {
|
|
18
18
|
modelName: string;
|
|
19
|
-
coords:
|
|
19
|
+
coords: number[];
|
|
20
20
|
heading: number;
|
|
21
21
|
spawnDistance: number;
|
|
22
22
|
collisions?: boolean;
|
|
23
23
|
animation?: Animation;
|
|
24
24
|
propData?: Props;
|
|
25
25
|
}
|
|
26
|
-
declare function registerPed(modelName: string, coords:
|
|
27
|
-
declare function processSpawning(playerPos:
|
|
26
|
+
declare function registerPed(modelName: string, coords: number[], heading: number, spawnDistance?: number, collisions?: boolean, animation?: Animation, propData?: Props): void;
|
|
27
|
+
declare function processSpawning(playerPos: number[]): Promise<void>;
|
|
28
28
|
declare function cleanupPeds(): void;
|
|
29
29
|
//#endregion
|
|
30
30
|
export { type Animation, type PedConfig, type Props, cleanupPeds, processSpawning, registerPed };
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { IkControlFlags, Model, createPed, createProp } from "@nativewrappers/redm";
|
|
2
|
-
|
|
3
1
|
//#region client/ped-handler.ts
|
|
4
2
|
const pedConfigs = [];
|
|
5
3
|
const activePeds = /* @__PURE__ */ new Map();
|
|
@@ -15,12 +13,12 @@ function registerPed(modelName, coords, heading, spawnDistance = 100, collisions
|
|
|
15
13
|
});
|
|
16
14
|
}
|
|
17
15
|
function getConfigKey(config) {
|
|
18
|
-
return `${config.coords
|
|
16
|
+
return `${config.coords[0]}_${config.coords[1]}_${config.coords[2]}`;
|
|
19
17
|
}
|
|
20
18
|
function isPlayerNearCoords(playerPos, targetPos, distance) {
|
|
21
|
-
const dx = playerPos
|
|
22
|
-
const dy = playerPos
|
|
23
|
-
const dz = playerPos
|
|
19
|
+
const dx = playerPos[0] - targetPos[0];
|
|
20
|
+
const dy = playerPos[1] - targetPos[1];
|
|
21
|
+
const dz = playerPos[2] - targetPos[2];
|
|
24
22
|
return Math.sqrt(dx * dx + dy * dy + dz * dz) <= distance;
|
|
25
23
|
}
|
|
26
24
|
async function processSpawning(playerPos) {
|
|
@@ -33,19 +31,26 @@ async function processSpawning(playerPos) {
|
|
|
33
31
|
}
|
|
34
32
|
}
|
|
35
33
|
async function spawnPed(config, key) {
|
|
36
|
-
const
|
|
34
|
+
const { dict, anim } = config.animation || {
|
|
35
|
+
dict: "",
|
|
36
|
+
anim: ""
|
|
37
|
+
};
|
|
38
|
+
const { model, offset, rotation, boneId } = config.propData || {};
|
|
39
|
+
const ped = CreatePed(GetHashKey(config.modelName), config.coords[0], config.coords[1], config.coords[2], config.heading, false, true, false, false);
|
|
37
40
|
if (!ped) return;
|
|
38
|
-
SetRandomOutfitVariation(ped
|
|
39
|
-
ped
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
41
|
+
SetRandomOutfitVariation(ped, true);
|
|
42
|
+
SetEntityInvincible(ped, true);
|
|
43
|
+
if (config.collisions) SetEntityCollision(ped, false, false);
|
|
44
|
+
SetBlockingOfNonTemporaryEvents(ped, true);
|
|
45
|
+
if (config.animation) {
|
|
46
|
+
RequestAnimDict(dict);
|
|
47
|
+
while (!HasAnimDictLoaded(dict)) await new Promise((resolve) => setTimeout(resolve, 0));
|
|
48
|
+
TaskPlayAnim(ped, dict, anim, 1, -1, 1, 0, 0, false, false, false);
|
|
49
|
+
}
|
|
45
50
|
let prop = null;
|
|
46
51
|
if (config.propData) {
|
|
47
|
-
prop =
|
|
48
|
-
if (prop) AttachEntityToEntity(prop
|
|
52
|
+
prop = CreateObjectNoOffset(GetHashKey(config.propData.model), ped.Position[0], ped.Position[1], ped.Position[2], false, true, true);
|
|
53
|
+
if (prop && boneId && offset && rotation) AttachEntityToEntity(prop, ped, boneId, offset[0], offset[1], offset[2], rotation[0], rotation[1], rotation[2], true, false, false, true, 1, true);
|
|
49
54
|
}
|
|
50
55
|
activePeds.set(key, {
|
|
51
56
|
ped,
|
|
@@ -56,14 +61,14 @@ async function spawnPed(config, key) {
|
|
|
56
61
|
function despawnPed(key) {
|
|
57
62
|
const activePed = activePeds.get(key);
|
|
58
63
|
if (!activePed) return;
|
|
59
|
-
if (activePed.prop) activePed.prop
|
|
60
|
-
if (activePed.ped) activePed.ped
|
|
64
|
+
if (activePed.prop) DeleteEntity(activePed.prop);
|
|
65
|
+
if (activePed.ped) DeleteEntity(activePed.ped);
|
|
61
66
|
activePeds.delete(key);
|
|
62
67
|
}
|
|
63
68
|
function cleanupPeds() {
|
|
64
69
|
for (const [key, activePed] of activePeds) {
|
|
65
|
-
if (activePed.prop) activePed.prop
|
|
66
|
-
if (activePed.ped) activePed.ped
|
|
70
|
+
if (activePed.prop) DeleteEntity(activePed.prop);
|
|
71
|
+
if (activePed.ped) DeleteEntity(activePed.ped);
|
|
67
72
|
activePeds.delete(key);
|
|
68
73
|
}
|
|
69
74
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pma-locals",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "RedM ped spawning and management library with TypeScript support",
|
|
3
|
+
"version": "1.0.11",
|
|
4
|
+
"description": "RedM/Fivem ped spawning and management library with TypeScript support",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
7
7
|
"type": "module",
|