@pma-network/redm 0.0.14
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/PMA.d.ts +41 -0
- package/PMA.js +110 -0
- package/decors/PMADecors.d.ts +4 -0
- package/decors/PMADecors.js +41 -0
- package/index.d.ts +3 -0
- package/index.js +3 -0
- package/interactions.d.ts +43 -0
- package/interactions.js +30 -0
- package/package.json +18 -0
package/PMA.d.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { PlayerJob } from "@pma-network/redm-types/PMAPlayer";
|
|
2
|
+
export type OnJobChange = (pmaThis: PMAWrapper, job: PlayerJob) => void;
|
|
3
|
+
export type OnPlayerLoaded = (pmaThis: PMAWrapper) => void;
|
|
4
|
+
declare class PMAWrapper {
|
|
5
|
+
#private;
|
|
6
|
+
HasLoaded: Promise<boolean>;
|
|
7
|
+
constructor();
|
|
8
|
+
/**
|
|
9
|
+
* WARNING: this expects you to have waited for {@link HasLoaded} to be called before trying to call it!
|
|
10
|
+
*/
|
|
11
|
+
get Job(): PlayerJob;
|
|
12
|
+
/**
|
|
13
|
+
* WARNING: this expects you to have waited for {@link HasLoaded} to be called before trying to call it!
|
|
14
|
+
* @returns 1 if the players character is male, or 0 if the players character is female
|
|
15
|
+
*/
|
|
16
|
+
get Gender(): number;
|
|
17
|
+
/**
|
|
18
|
+
* WARNING: this expects you to have waited for {@link HasLoaded} to be called before trying to call it!
|
|
19
|
+
*/
|
|
20
|
+
get UniqueId(): number;
|
|
21
|
+
/**
|
|
22
|
+
* WARNING: this expects you to have waited for {@link HasLoaded} to be called before trying to call it!
|
|
23
|
+
*/
|
|
24
|
+
get CharacterName(): string;
|
|
25
|
+
/**
|
|
26
|
+
* WARNING: this expects you to have waited for {@link HasLoaded} to be called before trying to call it!
|
|
27
|
+
*/
|
|
28
|
+
get Height(): number;
|
|
29
|
+
/**
|
|
30
|
+
* Adds the callback to be ran whenever the player is loaded, or instantly if
|
|
31
|
+
* the players already loaded (i.e. on server restart)
|
|
32
|
+
*/
|
|
33
|
+
listen_for_player_loaded(cb: OnPlayerLoaded): void;
|
|
34
|
+
listen_for_player_unloaded(cb: OnPlayerLoaded): void;
|
|
35
|
+
listen_for_job_change(cb: OnJobChange): void;
|
|
36
|
+
private on_player_loaded;
|
|
37
|
+
private on_player_unloaded;
|
|
38
|
+
private on_set_job;
|
|
39
|
+
}
|
|
40
|
+
export declare const PMA: PMAWrapper;
|
|
41
|
+
export {};
|
package/PMA.js
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
import { OnEvent, OnNetEvent } from "@nativewrappers/common";
|
|
4
|
+
class PMAWrapper {
|
|
5
|
+
static {
|
|
6
|
+
__name(this, "PMAWrapper");
|
|
7
|
+
}
|
|
8
|
+
#job;
|
|
9
|
+
#gender;
|
|
10
|
+
#uid;
|
|
11
|
+
#char_name;
|
|
12
|
+
#height;
|
|
13
|
+
HasLoaded;
|
|
14
|
+
#has_loaded_resolve;
|
|
15
|
+
#job_change_cb = [];
|
|
16
|
+
#player_loaded_cb = [];
|
|
17
|
+
#player_unloaded_cb = [];
|
|
18
|
+
#_resolve() {
|
|
19
|
+
this.#has_loaded_resolve(true);
|
|
20
|
+
}
|
|
21
|
+
#setup_has_loaded() {
|
|
22
|
+
this.HasLoaded = new Promise((res) => {
|
|
23
|
+
this.#has_loaded_resolve = res;
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
constructor() {
|
|
27
|
+
this.#setup_has_loaded();
|
|
28
|
+
if (LocalPlayer.state.has_loaded) {
|
|
29
|
+
this.on_player_loaded();
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* WARNING: this expects you to have waited for {@link HasLoaded} to be called before trying to call it!
|
|
34
|
+
*/
|
|
35
|
+
get Job() {
|
|
36
|
+
return this.#job;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* WARNING: this expects you to have waited for {@link HasLoaded} to be called before trying to call it!
|
|
40
|
+
* @returns 1 if the players character is male, or 0 if the players character is female
|
|
41
|
+
*/
|
|
42
|
+
get Gender() {
|
|
43
|
+
return this.#gender;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* WARNING: this expects you to have waited for {@link HasLoaded} to be called before trying to call it!
|
|
47
|
+
*/
|
|
48
|
+
get UniqueId() {
|
|
49
|
+
return this.#uid;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* WARNING: this expects you to have waited for {@link HasLoaded} to be called before trying to call it!
|
|
53
|
+
*/
|
|
54
|
+
get CharacterName() {
|
|
55
|
+
return this.#char_name;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* WARNING: this expects you to have waited for {@link HasLoaded} to be called before trying to call it!
|
|
59
|
+
*/
|
|
60
|
+
get Height() {
|
|
61
|
+
return this.#height;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Adds the callback to be ran whenever the player is loaded, or instantly if
|
|
65
|
+
* the players already loaded (i.e. on server restart)
|
|
66
|
+
*/
|
|
67
|
+
listen_for_player_loaded(cb) {
|
|
68
|
+
this.#player_loaded_cb.push(cb);
|
|
69
|
+
}
|
|
70
|
+
listen_for_player_unloaded(cb) {
|
|
71
|
+
this.#player_unloaded_cb.push(cb);
|
|
72
|
+
}
|
|
73
|
+
listen_for_job_change(cb) {
|
|
74
|
+
this.#job_change_cb.push(cb);
|
|
75
|
+
}
|
|
76
|
+
@OnEvent("pma:playerLoaded")
|
|
77
|
+
on_player_loaded() {
|
|
78
|
+
const state = LocalPlayer.state;
|
|
79
|
+
this.#gender = state.gender;
|
|
80
|
+
this.#height = state.height;
|
|
81
|
+
this.#uid = state.uid;
|
|
82
|
+
this.#char_name = state.char_name;
|
|
83
|
+
this.on_set_job({
|
|
84
|
+
name: state.job_name,
|
|
85
|
+
rank: state.job_grade
|
|
86
|
+
});
|
|
87
|
+
this.#_resolve();
|
|
88
|
+
for (const cb of this.#player_loaded_cb) {
|
|
89
|
+
cb(this);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
@OnNetEvent("pma:playerUnloaded")
|
|
93
|
+
on_player_unloaded() {
|
|
94
|
+
for (const cb of this.#player_unloaded_cb) {
|
|
95
|
+
cb(this);
|
|
96
|
+
}
|
|
97
|
+
this.#setup_has_loaded();
|
|
98
|
+
}
|
|
99
|
+
@OnNetEvent("pma:setJob")
|
|
100
|
+
on_set_job(job) {
|
|
101
|
+
this.#job = job;
|
|
102
|
+
for (const cb of this.#job_change_cb) {
|
|
103
|
+
cb(this, job);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
const PMA = new PMAWrapper();
|
|
108
|
+
export {
|
|
109
|
+
PMA
|
|
110
|
+
};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { type OnJobChange, type OnPlayerLoaded as OnPlayerLoadedFramework } from "../PMA";
|
|
2
|
+
export declare function OnPlayerLoaded(): (originalMethod: OnPlayerLoadedFramework, context: ClassMethodDecoratorContext) => void;
|
|
3
|
+
export declare function OnPlayerUnloaded(): (originalMethod: OnPlayerLoadedFramework, context: ClassMethodDecoratorContext) => void;
|
|
4
|
+
export declare function OnPlayerJobChange(): (originalMethod: OnJobChange, context: ClassMethodDecoratorContext) => void;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
import { PMA } from "../PMA";
|
|
4
|
+
function OnPlayerLoaded() {
|
|
5
|
+
return /* @__PURE__ */ __name(function actualDecorator(originalMethod, context) {
|
|
6
|
+
if (context.private) {
|
|
7
|
+
throw new Error("OnPlayerLoaded does not work on private methods, please mark the method as public");
|
|
8
|
+
}
|
|
9
|
+
context.addInitializer(function() {
|
|
10
|
+
PMA.listen_for_player_loaded(originalMethod.bind(this));
|
|
11
|
+
});
|
|
12
|
+
}, "actualDecorator");
|
|
13
|
+
}
|
|
14
|
+
__name(OnPlayerLoaded, "OnPlayerLoaded");
|
|
15
|
+
function OnPlayerUnloaded() {
|
|
16
|
+
return /* @__PURE__ */ __name(function actualDecorator(originalMethod, context) {
|
|
17
|
+
if (context.private) {
|
|
18
|
+
throw new Error("OnPlayerUnloaded does not work on private methods, please mark the method as public");
|
|
19
|
+
}
|
|
20
|
+
context.addInitializer(function() {
|
|
21
|
+
PMA.listen_for_player_unloaded(originalMethod.bind(this));
|
|
22
|
+
});
|
|
23
|
+
}, "actualDecorator");
|
|
24
|
+
}
|
|
25
|
+
__name(OnPlayerUnloaded, "OnPlayerUnloaded");
|
|
26
|
+
function OnPlayerJobChange() {
|
|
27
|
+
return /* @__PURE__ */ __name(function actualDecorator(originalMethod, context) {
|
|
28
|
+
if (context.private) {
|
|
29
|
+
throw new Error("OnPlayerJobChange does not work on private methods, please mark the method as public");
|
|
30
|
+
}
|
|
31
|
+
context.addInitializer(function() {
|
|
32
|
+
PMA.listen_for_job_change(originalMethod.bind(this));
|
|
33
|
+
});
|
|
34
|
+
}, "actualDecorator");
|
|
35
|
+
}
|
|
36
|
+
__name(OnPlayerJobChange, "OnPlayerJobChange");
|
|
37
|
+
export {
|
|
38
|
+
OnPlayerJobChange,
|
|
39
|
+
OnPlayerLoaded,
|
|
40
|
+
OnPlayerUnloaded
|
|
41
|
+
};
|
package/index.d.ts
ADDED
package/index.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
export type Bitwise<_T> = number;
|
|
2
|
+
export type InteractionVec3 = [number, number, number];
|
|
3
|
+
export type InteractionType = "circle-interaction";
|
|
4
|
+
export type InteractionColor = [number, number, number];
|
|
5
|
+
export declare enum InteractionDisable {
|
|
6
|
+
None = 0,
|
|
7
|
+
InCombat = 1,
|
|
8
|
+
IsCuffed = 2,
|
|
9
|
+
IsInTrunk = 4,
|
|
10
|
+
IsInVehicle = 8,
|
|
11
|
+
IsOnPhone = 16
|
|
12
|
+
}
|
|
13
|
+
export interface Interaction {
|
|
14
|
+
hideInteraction?: boolean;
|
|
15
|
+
resource?: string;
|
|
16
|
+
interactionType: InteractionType;
|
|
17
|
+
preloadDistance?: number;
|
|
18
|
+
interactionDistance: number;
|
|
19
|
+
distance: number;
|
|
20
|
+
name?: string;
|
|
21
|
+
displayOffset?: InteractionVec3;
|
|
22
|
+
handle?: number;
|
|
23
|
+
model?: number;
|
|
24
|
+
position?: InteractionVec3[];
|
|
25
|
+
args?: any[];
|
|
26
|
+
showOffscreen: boolean;
|
|
27
|
+
disableOnNotInteractable?: boolean;
|
|
28
|
+
useHeavyLosCheck?: boolean;
|
|
29
|
+
nonInteractableColor?: InteractionColor;
|
|
30
|
+
interactionCooldownInMs?: number;
|
|
31
|
+
nextAllowedInteraction?: number;
|
|
32
|
+
colorOverride?: InteractionColor;
|
|
33
|
+
disableInteraction?: Bitwise<InteractionDisable>;
|
|
34
|
+
canInteract?: (ent?: number, ...args: any[]) => boolean;
|
|
35
|
+
onInteract?: (ent?: number, ...args: any[]) => void;
|
|
36
|
+
}
|
|
37
|
+
declare class InteractionManager {
|
|
38
|
+
addInteraction(interaction: Interaction): void;
|
|
39
|
+
removeInteraction(interactionName: string): void;
|
|
40
|
+
doesInteractionExist(interactionName: string): boolean;
|
|
41
|
+
}
|
|
42
|
+
export declare const INTERACTION_MANAGER: InteractionManager;
|
|
43
|
+
export {};
|
package/interactions.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
var InteractionDisable = /* @__PURE__ */ ((InteractionDisable2) => {
|
|
4
|
+
InteractionDisable2[InteractionDisable2["None"] = 0] = "None";
|
|
5
|
+
InteractionDisable2[InteractionDisable2["InCombat"] = 1] = "InCombat";
|
|
6
|
+
InteractionDisable2[InteractionDisable2["IsCuffed"] = 2] = "IsCuffed";
|
|
7
|
+
InteractionDisable2[InteractionDisable2["IsInTrunk"] = 4] = "IsInTrunk";
|
|
8
|
+
InteractionDisable2[InteractionDisable2["IsInVehicle"] = 8] = "IsInVehicle";
|
|
9
|
+
InteractionDisable2[InteractionDisable2["IsOnPhone"] = 16] = "IsOnPhone";
|
|
10
|
+
return InteractionDisable2;
|
|
11
|
+
})(InteractionDisable || {});
|
|
12
|
+
class InteractionManager {
|
|
13
|
+
static {
|
|
14
|
+
__name(this, "InteractionManager");
|
|
15
|
+
}
|
|
16
|
+
addInteraction(interaction) {
|
|
17
|
+
exports["pma-interactions"].addInteraction(interaction);
|
|
18
|
+
}
|
|
19
|
+
removeInteraction(interactionName) {
|
|
20
|
+
exports["pma-interactions"].removeInteraction(interactionName);
|
|
21
|
+
}
|
|
22
|
+
doesInteractionExist(interactionName) {
|
|
23
|
+
return exports["pma-interactions"].doesInteractionExistForName(interactionName);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
const INTERACTION_MANAGER = new InteractionManager();
|
|
27
|
+
export {
|
|
28
|
+
INTERACTION_MANAGER,
|
|
29
|
+
InteractionDisable
|
|
30
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@pma-network/redm",
|
|
3
|
+
"description": "Native wrappers and utilities for use with PMA RedM Client.",
|
|
4
|
+
"contributors": [
|
|
5
|
+
"Dillon Skaggs <AvarianKnight>"
|
|
6
|
+
],
|
|
7
|
+
"type": "module",
|
|
8
|
+
"version": "0.0.14",
|
|
9
|
+
"files": [
|
|
10
|
+
"./**/*.js",
|
|
11
|
+
"./**/*.d.ts"
|
|
12
|
+
],
|
|
13
|
+
"sideEffects": false,
|
|
14
|
+
"exports": {
|
|
15
|
+
".": "./index.js",
|
|
16
|
+
"./*": "./*"
|
|
17
|
+
}
|
|
18
|
+
}
|