pma-locals 1.0.9 → 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.
@@ -0,0 +1,30 @@
1
+ import { AnimationFlags } from "@nativewrappers/redm";
2
+
3
+ //#region types/index.d.ts
4
+ interface Animation {
5
+ dict: string;
6
+ anim: string;
7
+ flag: AnimationFlags;
8
+ }
9
+ interface Props {
10
+ model: string;
11
+ boneId: number;
12
+ offset: number[];
13
+ rotation: number[];
14
+ }
15
+ //#endregion
16
+ //#region client/ped-handler.d.ts
17
+ interface PedConfig {
18
+ modelName: string;
19
+ coords: number[];
20
+ heading: number;
21
+ spawnDistance: number;
22
+ collisions?: boolean;
23
+ animation?: Animation;
24
+ propData?: Props;
25
+ }
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
+ declare function cleanupPeds(): void;
29
+ //#endregion
30
+ export { type Animation, type PedConfig, type Props, cleanupPeds, processSpawning, registerPed };
package/dist/index.mjs ADDED
@@ -0,0 +1,77 @@
1
+ //#region client/ped-handler.ts
2
+ const pedConfigs = [];
3
+ const activePeds = /* @__PURE__ */ new Map();
4
+ function registerPed(modelName, coords, heading, spawnDistance = 100, collisions, animation, propData) {
5
+ pedConfigs.push({
6
+ modelName,
7
+ coords,
8
+ heading,
9
+ spawnDistance,
10
+ collisions,
11
+ animation,
12
+ propData
13
+ });
14
+ }
15
+ function getConfigKey(config) {
16
+ return `${config.coords[0]}_${config.coords[1]}_${config.coords[2]}`;
17
+ }
18
+ function isPlayerNearCoords(playerPos, targetPos, distance) {
19
+ const dx = playerPos[0] - targetPos[0];
20
+ const dy = playerPos[1] - targetPos[1];
21
+ const dz = playerPos[2] - targetPos[2];
22
+ return Math.sqrt(dx * dx + dy * dy + dz * dz) <= distance;
23
+ }
24
+ async function processSpawning(playerPos) {
25
+ for (const config of pedConfigs) {
26
+ const key = getConfigKey(config);
27
+ const isNear = isPlayerNearCoords(playerPos, config.coords, config.spawnDistance);
28
+ const isSpawned = activePeds.has(key);
29
+ if (isNear && !isSpawned) await spawnPed(config, key);
30
+ else if (!isNear && isSpawned) despawnPed(key);
31
+ }
32
+ }
33
+ async function spawnPed(config, key) {
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);
40
+ if (!ped) return;
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
+ }
50
+ let prop = null;
51
+ if (config.propData) {
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);
54
+ }
55
+ activePeds.set(key, {
56
+ ped,
57
+ config,
58
+ prop
59
+ });
60
+ }
61
+ function despawnPed(key) {
62
+ const activePed = activePeds.get(key);
63
+ if (!activePed) return;
64
+ if (activePed.prop) DeleteEntity(activePed.prop);
65
+ if (activePed.ped) DeleteEntity(activePed.ped);
66
+ activePeds.delete(key);
67
+ }
68
+ function cleanupPeds() {
69
+ for (const [key, activePed] of activePeds) {
70
+ if (activePed.prop) DeleteEntity(activePed.prop);
71
+ if (activePed.ped) DeleteEntity(activePed.ped);
72
+ activePeds.delete(key);
73
+ }
74
+ }
75
+
76
+ //#endregion
77
+ export { cleanupPeds, processSpawning, registerPed };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "pma-locals",
3
- "version": "1.0.9",
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",
@@ -33,12 +33,12 @@
33
33
  "@nativewrappers/redm": "^0.0.141",
34
34
  "@types/node": "^25.0.3",
35
35
  "esbuild": "^0.27.2",
36
- "tsup": "^8.5.1",
36
+ "tsdown": "0.19.0-beta.3",
37
37
  "typescript": "^5.9.3"
38
38
  },
39
39
  "scripts": {
40
40
  "watch": "node ./scripts/dev.js",
41
41
  "build": "node ./scripts/prod.js",
42
- "build:package": "tsup"
42
+ "build:package": "tsdown"
43
43
  }
44
44
  }
package/dist/index.d.ts DELETED
@@ -1,28 +0,0 @@
1
- import { AnimationFlags, Vector3 } from '@nativewrappers/redm';
2
-
3
- interface Animation {
4
- dict: string;
5
- anim: string;
6
- flag: AnimationFlags;
7
- }
8
- interface Props {
9
- model: string;
10
- boneId: number;
11
- offset: number[];
12
- rotation: number[];
13
- }
14
-
15
- interface PedConfig {
16
- modelName: string;
17
- coords: Vector3;
18
- heading: number;
19
- spawnDistance: number;
20
- collisions?: boolean;
21
- animation?: Animation;
22
- propData?: Props;
23
- }
24
- declare function registerPed(modelName: string, coords: Vector3, heading: number, spawnDistance?: number, collisions?: boolean, animation?: Animation, propData?: Props): void;
25
- declare function processSpawning(playerPos: Vector3): Promise<void>;
26
- declare function cleanupPeds(): void;
27
-
28
- export { type Animation, type PedConfig, type Props, cleanupPeds, processSpawning, registerPed };
package/dist/index.js DELETED
@@ -1,111 +0,0 @@
1
- import { createPed, Model, IkControlFlags, createProp } from '@nativewrappers/redm';
2
-
3
- // client/ped-handler.ts
4
- var pedConfigs = [];
5
- var activePeds = /* @__PURE__ */ new Map();
6
- function registerPed(modelName, coords, heading, spawnDistance = 100, collisions, animation, propData) {
7
- pedConfigs.push({
8
- modelName,
9
- coords,
10
- heading,
11
- spawnDistance,
12
- collisions,
13
- animation,
14
- propData
15
- });
16
- }
17
- function getConfigKey(config) {
18
- return `${config.coords.x}_${config.coords.y}_${config.coords.z}`;
19
- }
20
- 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;
24
- return Math.sqrt(dx * dx + dy * dy + dz * dz) <= distance;
25
- }
26
- async function processSpawning(playerPos) {
27
- for (const config of pedConfigs) {
28
- const key = getConfigKey(config);
29
- const isNear = isPlayerNearCoords(playerPos, config.coords, config.spawnDistance);
30
- const isSpawned = activePeds.has(key);
31
- if (isNear && !isSpawned) {
32
- await spawnPed(config, key);
33
- } else if (!isNear && isSpawned) {
34
- despawnPed(key);
35
- }
36
- }
37
- }
38
- async function spawnPed(config, key) {
39
- const ped = await createPed(new Model(config.modelName), config.coords, 0, false, true);
40
- if (!ped) return;
41
- SetRandomOutfitVariation(ped.Handle, true);
42
- ped.IsPositionFrozen = true;
43
- SetEntityInvincible(ped.Handle, true);
44
- if (config.collisions) {
45
- SetEntityCollision(ped.Handle, false, false);
46
- }
47
- SetBlockingOfNonTemporaryEvents(ped.Handle, true);
48
- if (config.heading) {
49
- ped.Heading = config.heading;
50
- }
51
- if (config.animation) {
52
- await ped.Tasks.playAnimation(
53
- config.animation.dict,
54
- config.animation.anim,
55
- 8,
56
- 8,
57
- -1,
58
- 1,
59
- config.animation.flag,
60
- IkControlFlags.BlockNonAnimSceneLooks
61
- );
62
- }
63
- let prop = null;
64
- if (config.propData) {
65
- prop = await createProp(new Model(config.propData.model), ped.Position, 0, false, true);
66
- if (prop) {
67
- AttachEntityToEntity(
68
- prop.Handle,
69
- ped.Handle,
70
- config.propData.boneId,
71
- config.propData.offset[0],
72
- config.propData.offset[1],
73
- config.propData.offset[2],
74
- config.propData.rotation[0],
75
- config.propData.rotation[1],
76
- config.propData.rotation[2],
77
- true,
78
- false,
79
- false,
80
- true,
81
- 1,
82
- true
83
- );
84
- }
85
- }
86
- activePeds.set(key, { ped, config, prop });
87
- }
88
- function despawnPed(key) {
89
- const activePed = activePeds.get(key);
90
- if (!activePed) return;
91
- if (activePed.prop) {
92
- activePed.prop.delete();
93
- }
94
- if (activePed.ped) {
95
- activePed.ped.delete();
96
- }
97
- activePeds.delete(key);
98
- }
99
- function cleanupPeds() {
100
- for (const [key, activePed] of activePeds) {
101
- if (activePed.prop) {
102
- activePed.prop.delete();
103
- }
104
- if (activePed.ped) {
105
- activePed.ped.delete();
106
- }
107
- activePeds.delete(key);
108
- }
109
- }
110
-
111
- export { cleanupPeds, processSpawning, registerPed };