pma-locals 1.0.1 → 1.0.3
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/README.md +34 -12
- package/dist/index.d.ts +26 -0
- package/dist/index.js +104 -6
- package/package.json +7 -6
- package/dist/client.js +0 -2903
- package/dist/server.js +0 -0
- package/dist/shared/config.d.ts +0 -10
- package/dist/types/index.d.ts +0 -10
package/README.md
CHANGED
|
@@ -1,55 +1,77 @@
|
|
|
1
1
|
# pma-locals
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Modern TypeScript library for managing RedM ped spawning and animations.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
8
|
npm install pma-locals
|
|
9
|
+
# or
|
|
10
|
+
pnpm add pma-locals
|
|
9
11
|
```
|
|
10
12
|
|
|
11
13
|
## Usage
|
|
12
14
|
|
|
13
15
|
```typescript
|
|
14
|
-
import { registerPed } from "pma-locals";
|
|
15
|
-
import { Vector3 } from "@nativewrappers/redm";
|
|
16
|
+
import { registerPed, processSpawning } from "pma-locals";
|
|
17
|
+
import { Vector3, Delay } from "@nativewrappers/redm";
|
|
16
18
|
|
|
17
19
|
// Register a ped with animation
|
|
18
20
|
registerPed(
|
|
19
21
|
0x12345678, // model hash
|
|
20
22
|
new Vector3(-297.74, 791.1, 118.4), // spawn coords
|
|
21
23
|
180.0, // heading
|
|
22
|
-
50.0, // spawn distance
|
|
24
|
+
50.0, // spawn distance (optional, default: 100.0)
|
|
23
25
|
{
|
|
24
26
|
dict: "amb_wander@world_human_smoke@male@male_a@idle_a",
|
|
25
27
|
anim: "idle_a",
|
|
26
28
|
}, // optional animation
|
|
27
29
|
undefined // optional prop data
|
|
28
30
|
);
|
|
31
|
+
|
|
32
|
+
// In your game loop
|
|
33
|
+
setTick(async () => {
|
|
34
|
+
const playerPed = PlayerPedId();
|
|
35
|
+
if (!playerPed) return;
|
|
36
|
+
|
|
37
|
+
const coords = GetEntityCoords(playerPed, true, true);
|
|
38
|
+
const playerPos = new Vector3(coords[0], coords[1], coords[2]);
|
|
39
|
+
|
|
40
|
+
await processSpawning(playerPos);
|
|
41
|
+
await Delay(500);
|
|
42
|
+
});
|
|
29
43
|
```
|
|
30
44
|
|
|
31
45
|
## API
|
|
32
46
|
|
|
33
47
|
### `registerPed(modelName, coords, heading, spawnDistance?, animation?, propData?)`
|
|
34
48
|
|
|
35
|
-
|
|
49
|
+
Register a ped to spawn when players approach.
|
|
36
50
|
|
|
37
51
|
**Parameters:**
|
|
38
52
|
|
|
39
|
-
- `modelName` (number):
|
|
53
|
+
- `modelName` (number): Model hash
|
|
40
54
|
- `coords` (Vector3): Spawn coordinates
|
|
41
55
|
- `heading` (number): Ped heading direction
|
|
42
|
-
- `spawnDistance` (number
|
|
43
|
-
- `animation` (Animation
|
|
44
|
-
- `propData` (Props
|
|
56
|
+
- `spawnDistance` (number): Distance threshold (default: 100.0)
|
|
57
|
+
- `animation` (Animation): Optional animation data
|
|
58
|
+
- `propData` (Props): Optional prop attachment
|
|
45
59
|
|
|
46
|
-
### `processSpawning(playerPos)`
|
|
60
|
+
### `processSpawning(playerPos: Vector3)`
|
|
47
61
|
|
|
48
|
-
|
|
62
|
+
Update ped spawning based on player position. Call this in your game loop.
|
|
49
63
|
|
|
50
64
|
### `cleanupPeds()`
|
|
51
65
|
|
|
52
|
-
|
|
66
|
+
Delete all spawned peds (useful for resource cleanup).
|
|
67
|
+
|
|
68
|
+
## Types
|
|
69
|
+
|
|
70
|
+
Full TypeScript support with exported types:
|
|
71
|
+
|
|
72
|
+
- `PedConfig`
|
|
73
|
+
- `Animation`
|
|
74
|
+
- `Props`
|
|
53
75
|
|
|
54
76
|
## License
|
|
55
77
|
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Vector3 } from '@nativewrappers/redm';
|
|
2
|
+
|
|
3
|
+
interface Animation {
|
|
4
|
+
dict: string;
|
|
5
|
+
anim: string;
|
|
6
|
+
}
|
|
7
|
+
interface Props {
|
|
8
|
+
model: string;
|
|
9
|
+
boneId: number;
|
|
10
|
+
offset: number[];
|
|
11
|
+
rotation: number[];
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
interface PedConfig {
|
|
15
|
+
modelName: string;
|
|
16
|
+
coords: Vector3;
|
|
17
|
+
heading: number;
|
|
18
|
+
spawnDistance: number;
|
|
19
|
+
animation?: Animation;
|
|
20
|
+
propData?: Props;
|
|
21
|
+
}
|
|
22
|
+
declare function registerPed(modelName: string, coords: Vector3, heading: number, spawnDistance?: number, animation?: Animation, propData?: Props): void;
|
|
23
|
+
declare function processSpawning(playerPos: Vector3): Promise<void>;
|
|
24
|
+
declare function cleanupPeds(): void;
|
|
25
|
+
|
|
26
|
+
export { type Animation, type PedConfig, type Props, cleanupPeds, processSpawning, registerPed };
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,104 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import { createPed, Model, AnimationFlags, 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, animation, propData) {
|
|
7
|
+
pedConfigs.push({
|
|
8
|
+
modelName,
|
|
9
|
+
coords,
|
|
10
|
+
heading,
|
|
11
|
+
spawnDistance,
|
|
12
|
+
animation,
|
|
13
|
+
propData
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
function getConfigKey(config) {
|
|
17
|
+
return `${config.coords.x}_${config.coords.y}_${config.coords.z}`;
|
|
18
|
+
}
|
|
19
|
+
function isPlayerNearCoords(playerPos, targetPos, distance) {
|
|
20
|
+
const dx = playerPos.x - targetPos.x;
|
|
21
|
+
const dy = playerPos.y - targetPos.y;
|
|
22
|
+
const dz = playerPos.z - targetPos.z;
|
|
23
|
+
return Math.sqrt(dx * dx + dy * dy + dz * dz) <= distance;
|
|
24
|
+
}
|
|
25
|
+
async function processSpawning(playerPos) {
|
|
26
|
+
for (const config of pedConfigs) {
|
|
27
|
+
const key = getConfigKey(config);
|
|
28
|
+
const isNear = isPlayerNearCoords(playerPos, config.coords, config.spawnDistance);
|
|
29
|
+
const isSpawned = activePeds.has(key);
|
|
30
|
+
if (isNear && !isSpawned) {
|
|
31
|
+
await spawnPed(config, key);
|
|
32
|
+
} else if (!isNear && isSpawned) {
|
|
33
|
+
despawnPed(key);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
async function spawnPed(config, key) {
|
|
38
|
+
const ped = await createPed(new Model(config.modelName), config.coords, 0, false, true);
|
|
39
|
+
if (!ped) return;
|
|
40
|
+
SetRandomOutfitVariation(ped.Handle, true);
|
|
41
|
+
if (config.heading) {
|
|
42
|
+
ped.Heading = config.heading;
|
|
43
|
+
}
|
|
44
|
+
if (config.animation) {
|
|
45
|
+
await ped.Tasks.playAnimation(
|
|
46
|
+
config.animation.dict,
|
|
47
|
+
config.animation.anim,
|
|
48
|
+
8,
|
|
49
|
+
8,
|
|
50
|
+
-1,
|
|
51
|
+
1,
|
|
52
|
+
AnimationFlags.Looping,
|
|
53
|
+
IkControlFlags.UpperBody
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
let prop = null;
|
|
57
|
+
if (config.propData) {
|
|
58
|
+
prop = await createProp(new Model(config.propData.model), ped.Position, 0, true, true);
|
|
59
|
+
if (prop) {
|
|
60
|
+
AttachEntityToEntity(
|
|
61
|
+
prop.Handle,
|
|
62
|
+
ped.Handle,
|
|
63
|
+
config.propData.boneId,
|
|
64
|
+
config.propData.offset[0],
|
|
65
|
+
config.propData.offset[1],
|
|
66
|
+
config.propData.offset[2],
|
|
67
|
+
config.propData.rotation[0],
|
|
68
|
+
config.propData.rotation[1],
|
|
69
|
+
config.propData.rotation[2],
|
|
70
|
+
true,
|
|
71
|
+
false,
|
|
72
|
+
false,
|
|
73
|
+
true,
|
|
74
|
+
1,
|
|
75
|
+
true
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
activePeds.set(key, { ped, config, prop });
|
|
80
|
+
}
|
|
81
|
+
function despawnPed(key) {
|
|
82
|
+
const activePed = activePeds.get(key);
|
|
83
|
+
if (!activePed) return;
|
|
84
|
+
if (activePed.prop) {
|
|
85
|
+
activePed.prop.delete();
|
|
86
|
+
}
|
|
87
|
+
if (activePed.ped) {
|
|
88
|
+
activePed.ped.delete();
|
|
89
|
+
}
|
|
90
|
+
activePeds.delete(key);
|
|
91
|
+
}
|
|
92
|
+
function cleanupPeds() {
|
|
93
|
+
for (const [key, activePed] of activePeds) {
|
|
94
|
+
if (activePed.prop) {
|
|
95
|
+
activePed.prop.delete();
|
|
96
|
+
}
|
|
97
|
+
if (activePed.ped) {
|
|
98
|
+
activePed.ped.delete();
|
|
99
|
+
}
|
|
100
|
+
activePeds.delete(key);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export { cleanupPeds, processSpawning, registerPed };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pma-locals",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "RedM ped spawning and management library with TypeScript support",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -24,20 +24,21 @@
|
|
|
24
24
|
],
|
|
25
25
|
"author": "",
|
|
26
26
|
"license": "ISC",
|
|
27
|
-
"
|
|
28
|
-
"@nativewrappers/redm": "^0.0.141"
|
|
29
|
-
"@nativewrappers/server": "^0.0.141",
|
|
30
|
-
"esbuild": "^0.27.2"
|
|
27
|
+
"peerDependencies": {
|
|
28
|
+
"@nativewrappers/redm": "^0.0.141"
|
|
31
29
|
},
|
|
32
30
|
"devDependencies": {
|
|
33
31
|
"@citizenfx/client": "2.0.23683-1",
|
|
34
32
|
"@citizenfx/server": "2.0.23683-1",
|
|
33
|
+
"@nativewrappers/redm": "^0.0.141",
|
|
35
34
|
"@types/node": "^25.0.3",
|
|
35
|
+
"esbuild": "^0.27.2",
|
|
36
|
+
"tsup": "^8.5.1",
|
|
36
37
|
"typescript": "^5.9.3"
|
|
37
38
|
},
|
|
38
39
|
"scripts": {
|
|
39
40
|
"watch": "node ./scripts/dev.js",
|
|
40
41
|
"build": "node ./scripts/prod.js",
|
|
41
|
-
"build:package": "
|
|
42
|
+
"build:package": "tsup"
|
|
42
43
|
}
|
|
43
44
|
}
|