@armoury/fivem-roleplay-gamemode-common 1.0.71 → 1.0.73
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/cjs/shared/index.js +1 -0
- package/dist/cjs/shared/services/index.js +18 -0
- package/dist/cjs/shared/services/vehicles/vehicle.service.js +144 -0
- package/dist/esm/shared/index.js +1 -0
- package/dist/esm/shared/services/index.js +2 -0
- package/dist/esm/shared/services/vehicles/vehicle.service.js +141 -0
- package/dist/types/shared/index.d.ts +1 -0
- package/dist/types/shared/services/index.d.ts +2 -0
- package/dist/types/shared/services/vehicles/vehicle.service.d.ts +9 -0
- package/package.json +3 -3
package/dist/cjs/shared/index.js
CHANGED
|
@@ -15,4 +15,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./models"), exports);
|
|
18
|
+
__exportStar(require("./services"), exports);
|
|
18
19
|
__exportStar(require("./stub"), exports);
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
/** Vehicle */
|
|
18
|
+
__exportStar(require("./vehicles/vehicle.service"), exports);
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.Vehicles = void 0;
|
|
13
|
+
const injection_js_1 = require("injection-js");
|
|
14
|
+
// TODO: "Attached stashes" functionality should be available for any type of entity, not only vehicles
|
|
15
|
+
let Vehicles = class Vehicles {
|
|
16
|
+
constructor() {
|
|
17
|
+
// TODO: Move this to armoury framework
|
|
18
|
+
if (!IsDuplicityVersion()) {
|
|
19
|
+
AddStateBagChangeHandler(IDENTIFIER_VEHICLE_TRUNK_OPEN, null, (bagName, key, value, reserved, replicated) => {
|
|
20
|
+
const vehicle = GetEntityFromStateBagName(bagName);
|
|
21
|
+
if (!vehicle || !DoesEntityExist(vehicle)) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
if (GetEntityType(vehicle) !== 2) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
if (value === 1) {
|
|
28
|
+
console.log('REMOVEME! Trunk is now open.');
|
|
29
|
+
SetVehicleDoorOpen(vehicle, 5, false, false);
|
|
30
|
+
}
|
|
31
|
+
else if (value === 0) {
|
|
32
|
+
console.log('REMOVEME! Trunk is now shut.');
|
|
33
|
+
SetVehicleDoorShut(vehicle, 5, false);
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
static setTrunkOpen(entityId, open) {
|
|
39
|
+
if (!IsDuplicityVersion()) {
|
|
40
|
+
throw new Error('Can\'t do this inside a client script.');
|
|
41
|
+
}
|
|
42
|
+
if (!Number.isSafeInteger(entityId)) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
const state = Entity(entityId).state;
|
|
46
|
+
if (!state) {
|
|
47
|
+
throw new Error('Invalid entity.');
|
|
48
|
+
}
|
|
49
|
+
state.set(IDENTIFIER_VEHICLE_TRUNK_OPEN, +open, true);
|
|
50
|
+
}
|
|
51
|
+
static getOwningPersistableId(entityId) {
|
|
52
|
+
if (!Number.isSafeInteger(entityId)) {
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
if (!Entity(entityId).state) {
|
|
56
|
+
throw new Error('Invalid entity.');
|
|
57
|
+
}
|
|
58
|
+
const owningPersistableId = Entity(entityId).state[IDENTIFIER_PERSISTABLE_OWNINGID];
|
|
59
|
+
if (owningPersistableId == null || !Number.isSafeInteger(owningPersistableId)) {
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
return Number(owningPersistableId);
|
|
63
|
+
}
|
|
64
|
+
static setOwningPersistableId(entityId, owningPersistableId) {
|
|
65
|
+
if (!IsDuplicityVersion()) {
|
|
66
|
+
throw new Error('Can\'t do this inside a client script.');
|
|
67
|
+
}
|
|
68
|
+
if (!Entity(entityId).state) {
|
|
69
|
+
throw new Error('Invalid entity.');
|
|
70
|
+
}
|
|
71
|
+
Entity(entityId).state.set(IDENTIFIER_PERSISTABLE_OWNINGID, owningPersistableId, true);
|
|
72
|
+
}
|
|
73
|
+
static attachStash(entityId, stashId, type) {
|
|
74
|
+
if (!IsDuplicityVersion()) {
|
|
75
|
+
throw new Error('Can\'t do this inside a client script.');
|
|
76
|
+
}
|
|
77
|
+
if (!Entity(entityId).state) {
|
|
78
|
+
throw new Error('Invalid entity.');
|
|
79
|
+
}
|
|
80
|
+
let count = Entity(entityId).state[IDENTIFIER_ATTACHED_STASHES_COUNT];
|
|
81
|
+
if (count != null && !Number.isSafeInteger(count)) {
|
|
82
|
+
throw new Error('Corrupted attached stash count data.');
|
|
83
|
+
}
|
|
84
|
+
count ?? (count = 0);
|
|
85
|
+
const data = this.getStashData(entityId, count);
|
|
86
|
+
if (data) {
|
|
87
|
+
throw new Error('Attempted to attach stash data to existing state.');
|
|
88
|
+
}
|
|
89
|
+
Entity(entityId).state.set(IDENTIFIER_ATTACHED_STASH_BYINDEX(count), stashId, true);
|
|
90
|
+
Entity(entityId).state.set(IDENTIFIER_ATTACHED_STASH_TYPE(count), type, true);
|
|
91
|
+
Entity(entityId).state.set(IDENTIFIER_ATTACHED_STASHES_COUNT, count + 1, true);
|
|
92
|
+
return true;
|
|
93
|
+
}
|
|
94
|
+
static getAttachedStashIdsByType(entityId, type) {
|
|
95
|
+
if (!Entity(entityId).state) {
|
|
96
|
+
throw new Error('Invalid entity.');
|
|
97
|
+
}
|
|
98
|
+
const count = Entity(entityId).state[IDENTIFIER_ATTACHED_STASHES_COUNT] ?? 0;
|
|
99
|
+
if (!count) {
|
|
100
|
+
return null;
|
|
101
|
+
}
|
|
102
|
+
const stashIds = [];
|
|
103
|
+
for (let i = 0; i < count; i++) {
|
|
104
|
+
const data = this.getStashData(entityId, i);
|
|
105
|
+
if (!data) {
|
|
106
|
+
continue;
|
|
107
|
+
}
|
|
108
|
+
if (data.type == type) {
|
|
109
|
+
stashIds.push(Number(data.stashId));
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return stashIds;
|
|
113
|
+
}
|
|
114
|
+
static getStashData(entityId, index) {
|
|
115
|
+
if (!Entity(entityId).state) {
|
|
116
|
+
throw new Error('Invalid entity.');
|
|
117
|
+
}
|
|
118
|
+
const stashId = Entity(entityId).state[IDENTIFIER_ATTACHED_STASH_BYINDEX(index)];
|
|
119
|
+
if (stashId == null || !Number.isSafeInteger(stashId)) {
|
|
120
|
+
return null;
|
|
121
|
+
}
|
|
122
|
+
const type = Entity(entityId).state[IDENTIFIER_ATTACHED_STASH_TYPE(index)];
|
|
123
|
+
if (type == null) {
|
|
124
|
+
return null;
|
|
125
|
+
}
|
|
126
|
+
return { stashId: Number(stashId), type };
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
exports.Vehicles = Vehicles;
|
|
130
|
+
exports.Vehicles = Vehicles = __decorate([
|
|
131
|
+
(0, injection_js_1.Injectable)(),
|
|
132
|
+
__metadata("design:paramtypes", [])
|
|
133
|
+
], Vehicles);
|
|
134
|
+
/** Entities */
|
|
135
|
+
const PERSISTABLE_PREFIX = 'armoury:entity:owning-persistable';
|
|
136
|
+
const IDENTIFIER_PERSISTABLE_OWNINGID = PERSISTABLE_PREFIX + ':owningId';
|
|
137
|
+
/** Trunk (TODO: Move applicable to main framework)*/
|
|
138
|
+
const VEHICLE_TRUNK_PREFIX = 'armoury:vehicle:trunk';
|
|
139
|
+
const IDENTIFIER_VEHICLE_TRUNK_OPEN = VEHICLE_TRUNK_PREFIX + ':open';
|
|
140
|
+
/** Attached Stashes */
|
|
141
|
+
const ATTACHED_STASHES_PREFIX = 'armoury:entity:attached-stashes';
|
|
142
|
+
const IDENTIFIER_ATTACHED_STASHES_COUNT = ATTACHED_STASHES_PREFIX + ':count';
|
|
143
|
+
const IDENTIFIER_ATTACHED_STASH_BYINDEX = (index) => `${ATTACHED_STASHES_PREFIX}:[${index}]`;
|
|
144
|
+
const IDENTIFIER_ATTACHED_STASH_TYPE = (index) => `${IDENTIFIER_ATTACHED_STASH_BYINDEX(index)}:type`;
|
package/dist/esm/shared/index.js
CHANGED
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
10
|
+
import { Injectable } from 'injection-js';
|
|
11
|
+
// TODO: "Attached stashes" functionality should be available for any type of entity, not only vehicles
|
|
12
|
+
let Vehicles = class Vehicles {
|
|
13
|
+
constructor() {
|
|
14
|
+
// TODO: Move this to armoury framework
|
|
15
|
+
if (!IsDuplicityVersion()) {
|
|
16
|
+
AddStateBagChangeHandler(IDENTIFIER_VEHICLE_TRUNK_OPEN, null, (bagName, key, value, reserved, replicated) => {
|
|
17
|
+
const vehicle = GetEntityFromStateBagName(bagName);
|
|
18
|
+
if (!vehicle || !DoesEntityExist(vehicle)) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
if (GetEntityType(vehicle) !== 2) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
if (value === 1) {
|
|
25
|
+
console.log('REMOVEME! Trunk is now open.');
|
|
26
|
+
SetVehicleDoorOpen(vehicle, 5, false, false);
|
|
27
|
+
}
|
|
28
|
+
else if (value === 0) {
|
|
29
|
+
console.log('REMOVEME! Trunk is now shut.');
|
|
30
|
+
SetVehicleDoorShut(vehicle, 5, false);
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
static setTrunkOpen(entityId, open) {
|
|
36
|
+
if (!IsDuplicityVersion()) {
|
|
37
|
+
throw new Error('Can\'t do this inside a client script.');
|
|
38
|
+
}
|
|
39
|
+
if (!Number.isSafeInteger(entityId)) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
const state = Entity(entityId).state;
|
|
43
|
+
if (!state) {
|
|
44
|
+
throw new Error('Invalid entity.');
|
|
45
|
+
}
|
|
46
|
+
state.set(IDENTIFIER_VEHICLE_TRUNK_OPEN, +open, true);
|
|
47
|
+
}
|
|
48
|
+
static getOwningPersistableId(entityId) {
|
|
49
|
+
if (!Number.isSafeInteger(entityId)) {
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
if (!Entity(entityId).state) {
|
|
53
|
+
throw new Error('Invalid entity.');
|
|
54
|
+
}
|
|
55
|
+
const owningPersistableId = Entity(entityId).state[IDENTIFIER_PERSISTABLE_OWNINGID];
|
|
56
|
+
if (owningPersistableId == null || !Number.isSafeInteger(owningPersistableId)) {
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
return Number(owningPersistableId);
|
|
60
|
+
}
|
|
61
|
+
static setOwningPersistableId(entityId, owningPersistableId) {
|
|
62
|
+
if (!IsDuplicityVersion()) {
|
|
63
|
+
throw new Error('Can\'t do this inside a client script.');
|
|
64
|
+
}
|
|
65
|
+
if (!Entity(entityId).state) {
|
|
66
|
+
throw new Error('Invalid entity.');
|
|
67
|
+
}
|
|
68
|
+
Entity(entityId).state.set(IDENTIFIER_PERSISTABLE_OWNINGID, owningPersistableId, true);
|
|
69
|
+
}
|
|
70
|
+
static attachStash(entityId, stashId, type) {
|
|
71
|
+
if (!IsDuplicityVersion()) {
|
|
72
|
+
throw new Error('Can\'t do this inside a client script.');
|
|
73
|
+
}
|
|
74
|
+
if (!Entity(entityId).state) {
|
|
75
|
+
throw new Error('Invalid entity.');
|
|
76
|
+
}
|
|
77
|
+
let count = Entity(entityId).state[IDENTIFIER_ATTACHED_STASHES_COUNT];
|
|
78
|
+
if (count != null && !Number.isSafeInteger(count)) {
|
|
79
|
+
throw new Error('Corrupted attached stash count data.');
|
|
80
|
+
}
|
|
81
|
+
count ?? (count = 0);
|
|
82
|
+
const data = this.getStashData(entityId, count);
|
|
83
|
+
if (data) {
|
|
84
|
+
throw new Error('Attempted to attach stash data to existing state.');
|
|
85
|
+
}
|
|
86
|
+
Entity(entityId).state.set(IDENTIFIER_ATTACHED_STASH_BYINDEX(count), stashId, true);
|
|
87
|
+
Entity(entityId).state.set(IDENTIFIER_ATTACHED_STASH_TYPE(count), type, true);
|
|
88
|
+
Entity(entityId).state.set(IDENTIFIER_ATTACHED_STASHES_COUNT, count + 1, true);
|
|
89
|
+
return true;
|
|
90
|
+
}
|
|
91
|
+
static getAttachedStashIdsByType(entityId, type) {
|
|
92
|
+
if (!Entity(entityId).state) {
|
|
93
|
+
throw new Error('Invalid entity.');
|
|
94
|
+
}
|
|
95
|
+
const count = Entity(entityId).state[IDENTIFIER_ATTACHED_STASHES_COUNT] ?? 0;
|
|
96
|
+
if (!count) {
|
|
97
|
+
return null;
|
|
98
|
+
}
|
|
99
|
+
const stashIds = [];
|
|
100
|
+
for (let i = 0; i < count; i++) {
|
|
101
|
+
const data = this.getStashData(entityId, i);
|
|
102
|
+
if (!data) {
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
if (data.type == type) {
|
|
106
|
+
stashIds.push(Number(data.stashId));
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return stashIds;
|
|
110
|
+
}
|
|
111
|
+
static getStashData(entityId, index) {
|
|
112
|
+
if (!Entity(entityId).state) {
|
|
113
|
+
throw new Error('Invalid entity.');
|
|
114
|
+
}
|
|
115
|
+
const stashId = Entity(entityId).state[IDENTIFIER_ATTACHED_STASH_BYINDEX(index)];
|
|
116
|
+
if (stashId == null || !Number.isSafeInteger(stashId)) {
|
|
117
|
+
return null;
|
|
118
|
+
}
|
|
119
|
+
const type = Entity(entityId).state[IDENTIFIER_ATTACHED_STASH_TYPE(index)];
|
|
120
|
+
if (type == null) {
|
|
121
|
+
return null;
|
|
122
|
+
}
|
|
123
|
+
return { stashId: Number(stashId), type };
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
Vehicles = __decorate([
|
|
127
|
+
Injectable(),
|
|
128
|
+
__metadata("design:paramtypes", [])
|
|
129
|
+
], Vehicles);
|
|
130
|
+
export { Vehicles };
|
|
131
|
+
/** Entities */
|
|
132
|
+
const PERSISTABLE_PREFIX = 'armoury:entity:owning-persistable';
|
|
133
|
+
const IDENTIFIER_PERSISTABLE_OWNINGID = PERSISTABLE_PREFIX + ':owningId';
|
|
134
|
+
/** Trunk (TODO: Move applicable to main framework)*/
|
|
135
|
+
const VEHICLE_TRUNK_PREFIX = 'armoury:vehicle:trunk';
|
|
136
|
+
const IDENTIFIER_VEHICLE_TRUNK_OPEN = VEHICLE_TRUNK_PREFIX + ':open';
|
|
137
|
+
/** Attached Stashes */
|
|
138
|
+
const ATTACHED_STASHES_PREFIX = 'armoury:entity:attached-stashes';
|
|
139
|
+
const IDENTIFIER_ATTACHED_STASHES_COUNT = ATTACHED_STASHES_PREFIX + ':count';
|
|
140
|
+
const IDENTIFIER_ATTACHED_STASH_BYINDEX = (index) => `${ATTACHED_STASHES_PREFIX}:[${index}]`;
|
|
141
|
+
const IDENTIFIER_ATTACHED_STASH_TYPE = (index) => `${IDENTIFIER_ATTACHED_STASH_BYINDEX(index)}:type`;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare class Vehicles {
|
|
2
|
+
constructor();
|
|
3
|
+
static setTrunkOpen(entityId: number, open: boolean): void;
|
|
4
|
+
static getOwningPersistableId(entityId: number): number | null;
|
|
5
|
+
static setOwningPersistableId(entityId: number, owningPersistableId: number): void;
|
|
6
|
+
static attachStash(entityId: number, stashId: number, type: string): boolean;
|
|
7
|
+
static getAttachedStashIdsByType(entityId: number, type: string): number[] | null;
|
|
8
|
+
private static getStashData;
|
|
9
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@armoury/fivem-roleplay-gamemode-common",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.73",
|
|
4
4
|
"description": "Shared APIs for the Armoury FiveM roleplay gamemode",
|
|
5
5
|
"main": "dist/cjs/shared/index.js",
|
|
6
6
|
"module": "dist/esm/shared/index.js",
|
|
@@ -18,8 +18,8 @@
|
|
|
18
18
|
},
|
|
19
19
|
"scripts": {
|
|
20
20
|
"build": "npm run build:cjs && npm run build:esm && npm run build:types",
|
|
21
|
-
"build:cjs": "
|
|
22
|
-
"build:esm": "
|
|
21
|
+
"build:cjs": "node ../../tools/build.js tsconfig.cjs.json",
|
|
22
|
+
"build:esm": "node ../../tools/build.js tsconfig.esm.json",
|
|
23
23
|
"build:types": "tsc -p tsconfig.types.json"
|
|
24
24
|
},
|
|
25
25
|
"publishConfig": {
|