pma-locals 1.0.10 → 1.0.12

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 CHANGED
@@ -1,4 +1,4 @@
1
- import { AnimationFlags, Vector3 } from "@nativewrappers/redm";
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: Vector3;
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: Vector3, heading: number, spawnDistance?: number, collisions?: boolean, animation?: Animation, propData?: Props): void;
27
- declare function processSpawning(playerPos: Vector3): Promise<void>;
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.x}_${config.coords.y}_${config.coords.z}`;
16
+ return `${config.coords[0]}_${config.coords[1]}_${config.coords[2]}`;
19
17
  }
20
18
  function isPlayerNearCoords(playerPos, targetPos, distance) {
21
- const dx = playerPos.x - targetPos.x;
22
- const dy = playerPos.y - targetPos.y;
23
- const dz = playerPos.z - targetPos.z;
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 ped = await createPed(new Model(config.modelName), config.coords, 0, false, true);
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.Handle, true);
39
- ped.IsPositionFrozen = true;
40
- SetEntityInvincible(ped.Handle, true);
41
- if (config.collisions) SetEntityCollision(ped.Handle, false, false);
42
- SetBlockingOfNonTemporaryEvents(ped.Handle, true);
43
- if (config.heading) ped.Heading = config.heading;
44
- if (config.animation) await ped.Tasks.playAnimation(config.animation.dict, config.animation.anim, 8, 8, -1, 1, config.animation.flag, IkControlFlags.BlockNonAnimSceneLooks);
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 = await createProp(new Model(config.propData.model), ped.Position, 0, false, true);
48
- if (prop) AttachEntityToEntity(prop.Handle, ped.Handle, config.propData.boneId, config.propData.offset[0], config.propData.offset[1], config.propData.offset[2], config.propData.rotation[0], config.propData.rotation[1], config.propData.rotation[2], true, false, false, true, 1, true);
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.delete();
60
- if (activePed.ped) activePed.ped.delete();
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.delete();
66
- if (activePed.ped) activePed.ped.delete();
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,14 +1,14 @@
1
1
  {
2
2
  "name": "pma-locals",
3
- "version": "1.0.10",
4
- "description": "RedM ped spawning and management library with TypeScript support",
5
- "main": "./dist/index.js",
6
- "types": "./dist/index.d.ts",
3
+ "version": "1.0.12",
4
+ "description": "RedM/Fivem ped spawning and management library with TypeScript support",
5
+ "main": "./dist/index.mjs",
6
+ "types": "./dist/index.d.mts",
7
7
  "type": "module",
8
8
  "exports": {
9
9
  ".": {
10
- "types": "./dist/index.d.ts",
11
- "import": "./dist/index.js"
10
+ "types": "./dist/index.d.mts",
11
+ "import": "./dist/index.mjs"
12
12
  }
13
13
  },
14
14
  "files": [