pma-locals 1.0.7 → 1.0.9
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 +61 -27
- package/dist/index.d.ts +2 -1
- package/dist/index.js +6 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,19 +1,13 @@
|
|
|
1
|
-
# pma-locals
|
|
2
|
-
|
|
3
|
-
Modern TypeScript library for managing RedM ped spawning and animations.
|
|
4
|
-
|
|
5
|
-
## Installation
|
|
6
|
-
|
|
7
1
|
```bash
|
|
8
2
|
npm install pma-locals
|
|
9
3
|
# or
|
|
10
4
|
pnpm add pma-locals
|
|
11
5
|
```
|
|
12
6
|
|
|
13
|
-
##
|
|
7
|
+
## Quick Start
|
|
14
8
|
|
|
15
9
|
```typescript
|
|
16
|
-
import { registerPed, processSpawning } from "pma-locals";
|
|
10
|
+
import { registerPed, processSpawning, cleanupPeds } from "pma-locals";
|
|
17
11
|
import { Vector3, Delay } from "@nativewrappers/redm";
|
|
18
12
|
|
|
19
13
|
// Register a ped with animation
|
|
@@ -22,6 +16,7 @@ registerPed(
|
|
|
22
16
|
new Vector3(-297.74, 791.1, 118.4), // spawn coords
|
|
23
17
|
180.0, // heading
|
|
24
18
|
50.0, // spawn distance (optional, default: 100.0)
|
|
19
|
+
true, // disable collisions
|
|
25
20
|
{
|
|
26
21
|
dict: "amb_wander@world_human_smoke@male@male_a@idle_a",
|
|
27
22
|
anim: "idle_a",
|
|
@@ -31,47 +26,86 @@ registerPed(
|
|
|
31
26
|
|
|
32
27
|
// In your game loop
|
|
33
28
|
setTick(async () => {
|
|
34
|
-
const playerPed =
|
|
35
|
-
if (!playerPed) return;
|
|
29
|
+
const playerPed = Game.PlayerPed;
|
|
36
30
|
|
|
37
|
-
|
|
38
|
-
const playerPos = new Vector3(coords[0], coords[1], coords[2]);
|
|
39
|
-
|
|
40
|
-
await processSpawning(playerPos);
|
|
31
|
+
await processSpawning(playerPed.Position);
|
|
41
32
|
await Delay(500);
|
|
42
33
|
});
|
|
34
|
+
|
|
35
|
+
// Cleanup on resource stop
|
|
36
|
+
on("onResourceStop", (resourceName: string) => {
|
|
37
|
+
if (resourceName === GetCurrentResourceName()) {
|
|
38
|
+
cleanupPeds();
|
|
39
|
+
}
|
|
40
|
+
});
|
|
43
41
|
```
|
|
44
42
|
|
|
45
|
-
## API
|
|
43
|
+
## API Reference
|
|
46
44
|
|
|
47
45
|
### `registerPed(modelName, coords, heading, spawnDistance?, animation?, propData?)`
|
|
48
46
|
|
|
49
|
-
Register a ped to spawn when players
|
|
47
|
+
Register a ped to spawn when players are within range.
|
|
50
48
|
|
|
51
49
|
**Parameters:**
|
|
52
50
|
|
|
53
51
|
- `modelName` (number): Model hash
|
|
54
52
|
- `coords` (Vector3): Spawn coordinates
|
|
55
|
-
- `heading` (number): Ped heading direction
|
|
56
|
-
- `spawnDistance
|
|
57
|
-
- `
|
|
58
|
-
- `
|
|
53
|
+
- `heading` (number): Ped heading direction (0-360)
|
|
54
|
+
- `spawnDistance?` (number): Distance threshold (default: 100.0)
|
|
55
|
+
- `collisions?` (boolean): Optional collision handler
|
|
56
|
+
- `animation?` (Animation): Optional animation config
|
|
57
|
+
- `dict` (string): Animation dictionary
|
|
58
|
+
- `anim` (string): Animation name
|
|
59
|
+
- `propData?` (Props): Optional prop attachment
|
|
60
|
+
- `model` (string): Prop model hash
|
|
61
|
+
- `boneId` (number): Bone to attach to
|
|
62
|
+
- `offset` (number[]): Position offset [x, y, z]
|
|
63
|
+
- `rotation` (number[]): Rotation [x, y, z]
|
|
59
64
|
|
|
60
65
|
### `processSpawning(playerPos: Vector3)`
|
|
61
66
|
|
|
62
|
-
|
|
67
|
+
Process ped spawning/despawning based on player position. Call this regularly in your game loop (e.g., every 500ms).
|
|
63
68
|
|
|
64
69
|
### `cleanupPeds()`
|
|
65
70
|
|
|
66
|
-
Delete all spawned peds
|
|
71
|
+
Delete all spawned peds. Use this when your resource stops to clean up entities.
|
|
72
|
+
|
|
73
|
+
## TypeScript Support
|
|
74
|
+
|
|
75
|
+
Full type definitions are included. Import types as needed:
|
|
67
76
|
|
|
68
|
-
|
|
77
|
+
```typescript
|
|
78
|
+
import type { PedConfig, Animation, Props } from "pma-locals";
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
**Exported Types:**
|
|
82
|
+
|
|
83
|
+
- `PedConfig` - Complete ped configuration
|
|
84
|
+
- `Animation` - Animation data structure
|
|
85
|
+
- `Props` - Prop attachment configuration
|
|
86
|
+
|
|
87
|
+
## Development
|
|
88
|
+
|
|
89
|
+
```bash
|
|
90
|
+
# Install dependencies
|
|
91
|
+
pnpm install
|
|
92
|
+
|
|
93
|
+
# Build package (creates dist/ with .js and .d.ts files)
|
|
94
|
+
pnpm build:package
|
|
95
|
+
|
|
96
|
+
# RedM development mode (watch)
|
|
97
|
+
pnpm watch
|
|
98
|
+
|
|
99
|
+
# Publish to npm
|
|
100
|
+
npm version patch
|
|
101
|
+
pnpm publish
|
|
102
|
+
```
|
|
69
103
|
|
|
70
|
-
|
|
104
|
+
**Built with:**
|
|
71
105
|
|
|
72
|
-
-
|
|
73
|
-
-
|
|
74
|
-
-
|
|
106
|
+
- [tsup](https://tsup.egoist.dev/) - TypeScript bundler
|
|
107
|
+
- [esbuild](https://esbuild.github.io/) - Fast JavaScript bundler
|
|
108
|
+
- [@nativewrappers/redm](https://www.npmjs.com/package/@nativewrappers/redm) - RedM type definitions
|
|
75
109
|
|
|
76
110
|
## License
|
|
77
111
|
|
package/dist/index.d.ts
CHANGED
|
@@ -17,10 +17,11 @@ interface PedConfig {
|
|
|
17
17
|
coords: Vector3;
|
|
18
18
|
heading: number;
|
|
19
19
|
spawnDistance: number;
|
|
20
|
+
collisions?: boolean;
|
|
20
21
|
animation?: Animation;
|
|
21
22
|
propData?: Props;
|
|
22
23
|
}
|
|
23
|
-
declare function registerPed(modelName: string, coords: Vector3, heading: number, spawnDistance?: number, animation?: Animation, propData?: Props): void;
|
|
24
|
+
declare function registerPed(modelName: string, coords: Vector3, heading: number, spawnDistance?: number, collisions?: boolean, animation?: Animation, propData?: Props): void;
|
|
24
25
|
declare function processSpawning(playerPos: Vector3): Promise<void>;
|
|
25
26
|
declare function cleanupPeds(): void;
|
|
26
27
|
|
package/dist/index.js
CHANGED
|
@@ -3,12 +3,13 @@ import { createPed, Model, IkControlFlags, createProp } from '@nativewrappers/re
|
|
|
3
3
|
// client/ped-handler.ts
|
|
4
4
|
var pedConfigs = [];
|
|
5
5
|
var activePeds = /* @__PURE__ */ new Map();
|
|
6
|
-
function registerPed(modelName, coords, heading, spawnDistance = 100, animation, propData) {
|
|
6
|
+
function registerPed(modelName, coords, heading, spawnDistance = 100, collisions, animation, propData) {
|
|
7
7
|
pedConfigs.push({
|
|
8
8
|
modelName,
|
|
9
9
|
coords,
|
|
10
10
|
heading,
|
|
11
11
|
spawnDistance,
|
|
12
|
+
collisions,
|
|
12
13
|
animation,
|
|
13
14
|
propData
|
|
14
15
|
});
|
|
@@ -40,7 +41,9 @@ async function spawnPed(config, key) {
|
|
|
40
41
|
SetRandomOutfitVariation(ped.Handle, true);
|
|
41
42
|
ped.IsPositionFrozen = true;
|
|
42
43
|
SetEntityInvincible(ped.Handle, true);
|
|
43
|
-
|
|
44
|
+
if (config.collisions) {
|
|
45
|
+
SetEntityCollision(ped.Handle, false, false);
|
|
46
|
+
}
|
|
44
47
|
SetBlockingOfNonTemporaryEvents(ped.Handle, true);
|
|
45
48
|
if (config.heading) {
|
|
46
49
|
ped.Heading = config.heading;
|
|
@@ -59,7 +62,7 @@ async function spawnPed(config, key) {
|
|
|
59
62
|
}
|
|
60
63
|
let prop = null;
|
|
61
64
|
if (config.propData) {
|
|
62
|
-
prop = await createProp(new Model(config.propData.model), ped.Position, 0,
|
|
65
|
+
prop = await createProp(new Model(config.propData.model), ped.Position, 0, false, true);
|
|
63
66
|
if (prop) {
|
|
64
67
|
AttachEntityToEntity(
|
|
65
68
|
prop.Handle,
|