@nativewrappers/fivem 0.0.20 → 0.0.22
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/client/Camera.js +2 -2
- package/client/Events.js +3 -3
- package/common/utils/Vector.d.ts +246 -14
- package/common/utils/Vector.js +256 -12
- package/package.json +1 -1
- package/server/Events.js +3 -3
- package/server/entities/BaseEntity.d.ts +7 -1
- package/server/entities/BaseEntity.js +23 -2
- package/server/entities/Entity.d.ts +1 -0
- package/server/entities/Entity.js +3 -0
- package/server/entities/Ped.d.ts +10 -6
- package/server/entities/Ped.js +24 -8
- package/server/entities/Prop.d.ts +2 -1
- package/server/entities/Prop.js +11 -2
- package/server/entities/Vehicle.d.ts +2 -2
- package/server/entities/Vehicle.js +12 -7
package/client/Camera.js
CHANGED
|
@@ -35,10 +35,10 @@ export class Camera {
|
|
|
35
35
|
return this.ForwardVector;
|
|
36
36
|
}
|
|
37
37
|
set Direction(direction) {
|
|
38
|
-
const dir = direction.normalize;
|
|
38
|
+
const dir = direction.normalize();
|
|
39
39
|
const vec1 = new Vector3(dir.x, dir.y, 0);
|
|
40
40
|
const vec2 = new Vector3(dir.z, vec1.distanceSquared(vec1), 0);
|
|
41
|
-
const vec3 = vec2.normalize;
|
|
41
|
+
const vec3 = vec2.normalize();
|
|
42
42
|
this.Rotation = new Vector3(Math.atan2(vec3.x, vec3.y) * 57.295779513082323, this.Rotation.y, Math.atan2(dir.x, dir.y) * -57.295779513082323);
|
|
43
43
|
}
|
|
44
44
|
// public get UpVector() : Vector3 {
|
package/client/Events.js
CHANGED
|
@@ -11,15 +11,15 @@ const getClassFromArguments = (...args) => {
|
|
|
11
11
|
for (const arg of args) {
|
|
12
12
|
switch (arg.type) {
|
|
13
13
|
case ClassTypes.Vector2: {
|
|
14
|
-
newArgs.push(Vector2.
|
|
14
|
+
newArgs.push(Vector2.fromObject(arg));
|
|
15
15
|
continue;
|
|
16
16
|
}
|
|
17
17
|
case ClassTypes.Vector3: {
|
|
18
|
-
newArgs.push(Vector3.
|
|
18
|
+
newArgs.push(Vector3.fromObject(arg));
|
|
19
19
|
continue;
|
|
20
20
|
}
|
|
21
21
|
case ClassTypes.Vector4: {
|
|
22
|
-
newArgs.push(Vector4.
|
|
22
|
+
newArgs.push(Vector4.fromObject(arg));
|
|
23
23
|
continue;
|
|
24
24
|
}
|
|
25
25
|
case ClassTypes.Ped: {
|
package/common/utils/Vector.d.ts
CHANGED
|
@@ -1,64 +1,212 @@
|
|
|
1
1
|
import type { MsgpackBuffer } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Represents a 2-dimensional vector.
|
|
4
|
+
*/
|
|
2
5
|
export interface Vec2 {
|
|
3
6
|
x: number;
|
|
4
7
|
y: number;
|
|
5
8
|
}
|
|
9
|
+
/**
|
|
10
|
+
* Represents a 3-dimensional vector.
|
|
11
|
+
*/
|
|
6
12
|
export interface Vec3 {
|
|
7
13
|
x: number;
|
|
8
14
|
y: number;
|
|
9
15
|
z: number;
|
|
10
16
|
}
|
|
17
|
+
/**
|
|
18
|
+
* Represents a 4-dimensional vector.
|
|
19
|
+
*/
|
|
11
20
|
export interface Vec4 {
|
|
12
21
|
x: number;
|
|
13
22
|
y: number;
|
|
14
23
|
z: number;
|
|
15
24
|
w: number;
|
|
16
25
|
}
|
|
26
|
+
/**
|
|
27
|
+
* An object with vector components.
|
|
28
|
+
*/
|
|
17
29
|
interface VectorObject {
|
|
18
30
|
x: number;
|
|
19
31
|
y: number;
|
|
20
32
|
z?: number;
|
|
21
33
|
w?: number;
|
|
22
34
|
}
|
|
23
|
-
|
|
35
|
+
/**
|
|
36
|
+
* Represents a vector of variable dimensions.
|
|
37
|
+
*/
|
|
38
|
+
type VectorN<L extends number, T = number> = L extends 2 ? [T, T] : L extends 3 ? [T, T, T] : L extends 4 ? [T, T, T, T] : never;
|
|
39
|
+
/**
|
|
40
|
+
* An array that can be converted to a vector.
|
|
41
|
+
*/
|
|
42
|
+
type VectorArray<T> = T extends Vec4 ? VectorN<4> : T extends Vec3 ? VectorN<3> : T extends Vec2 ? VectorN<2> : number[];
|
|
43
|
+
/**
|
|
44
|
+
* The constructor type of the Vector class.
|
|
45
|
+
*/
|
|
24
46
|
type VectorType = typeof Vector;
|
|
47
|
+
/**
|
|
48
|
+
* Represents an object or class that can be treated as a vector.
|
|
49
|
+
*/
|
|
25
50
|
type VectorLike = VectorObject | Vector;
|
|
51
|
+
/**
|
|
52
|
+
* Utility type to get the vector type of an object based on its component.
|
|
53
|
+
*/
|
|
54
|
+
type InferVector<T> = T extends Vec4 | VectorN<4> ? Vector4 : T extends Vec3 | VectorN<3> ? Vector3 : T extends Vec2 | VectorN<2> ? Vector2 : any;
|
|
55
|
+
/**
|
|
56
|
+
* A base vector class inherited by all vector classes.
|
|
57
|
+
*/
|
|
26
58
|
export declare class Vector {
|
|
27
59
|
size: number;
|
|
28
60
|
x: number;
|
|
29
61
|
y: number;
|
|
30
62
|
z?: number | undefined;
|
|
31
63
|
w?: number | undefined;
|
|
64
|
+
/**
|
|
65
|
+
* The type identifier for vectors.
|
|
66
|
+
*/
|
|
32
67
|
type: string;
|
|
33
|
-
static create(x: number, y?: number): Vector2;
|
|
34
|
-
static create(x: number, y?: number, z?: number): Vector3;
|
|
35
|
-
static create(x: number, y?: number, z?: number, w?: number): Vector4;
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
68
|
+
protected static create(x: number, y?: number): Vector2;
|
|
69
|
+
protected static create(x: number, y?: number, z?: number): Vector3;
|
|
70
|
+
protected static create(x: number, y?: number, z?: number, w?: number): Vector4;
|
|
71
|
+
/**
|
|
72
|
+
* Creates a new vector based on the provided vector-like object.
|
|
73
|
+
* @param obj The object representing the vector.
|
|
74
|
+
* @returns A new vector instance.
|
|
75
|
+
*/
|
|
76
|
+
protected static create<T extends VectorType, U extends VectorLike>(this: T, obj: U): InferVector<U>;
|
|
77
|
+
/**
|
|
78
|
+
* Creates a vector from binary data in a MsgpackBuffer.
|
|
79
|
+
* @param msgpackBuffer The buffer containing binary data.
|
|
80
|
+
* @returns A new vector instance.
|
|
81
|
+
*/
|
|
82
|
+
static fromBuffer<T extends VectorType>(this: T, { buffer }: MsgpackBuffer): InstanceType<T>;
|
|
83
|
+
/**
|
|
84
|
+
* Creates a deep copy of the provided vector.
|
|
85
|
+
* @param obj The vector to clone.
|
|
86
|
+
* @returns A new vector instance that is a copy of the provided vector.
|
|
87
|
+
*/
|
|
88
|
+
static clone<T extends VectorType, U extends VectorLike>(this: T, obj: U): InferVector<U>;
|
|
89
|
+
/**
|
|
90
|
+
* Performs an operation between a vector and either another vector or scalar value.
|
|
91
|
+
* @param a - The first vector.
|
|
92
|
+
* @param b - The second vector or scalar value.
|
|
93
|
+
* @param operator - The function defining the operation to perform.
|
|
94
|
+
* @returns A new vector resulting from the operation.
|
|
95
|
+
*/
|
|
39
96
|
private static operate;
|
|
97
|
+
/**
|
|
98
|
+
* Adds two vectors or a scalar value to a vector.
|
|
99
|
+
* @param a - The first vector or scalar value.
|
|
100
|
+
* @param b - The second vector or scalar value.
|
|
101
|
+
* @returns A new vector with incremented components.
|
|
102
|
+
*/
|
|
40
103
|
static add<T extends VectorType, U extends VectorLike>(this: T, a: U, b: VectorLike | number): U;
|
|
104
|
+
/**
|
|
105
|
+
* Adds a scalar value to the x-component of a vector.
|
|
106
|
+
* @param obj - The vector.
|
|
107
|
+
* @param x - The value to add to the x-component.
|
|
108
|
+
* @returns A new vector with the x-component incremented.
|
|
109
|
+
*/
|
|
110
|
+
static addX<T extends VectorType, U extends VectorLike>(this: T, obj: U, x: number): InferVector<U>;
|
|
111
|
+
/**
|
|
112
|
+
* Adds a scalar value to the y-component of a vector.
|
|
113
|
+
* @param obj - The vector.
|
|
114
|
+
* @param y - The value to add to the y-component.
|
|
115
|
+
* @returns A new vector with the y-component incremented.
|
|
116
|
+
*/
|
|
117
|
+
static addY<T extends VectorType, U extends VectorLike>(this: T, obj: U, y: number): InferVector<U>;
|
|
118
|
+
/**
|
|
119
|
+
* Adds a scalar value to the z-component of a vector.
|
|
120
|
+
* @param obj - The vector.
|
|
121
|
+
* @param z - The value to add to the z-component.
|
|
122
|
+
* @returns A new vector with the z-component incremented.
|
|
123
|
+
*/
|
|
124
|
+
static addZ<T extends VectorType, U extends VectorLike>(this: T, obj: U, z: number): InferVector<U>;
|
|
125
|
+
/**
|
|
126
|
+
* Adds a scalar value to the w-component of a vector.
|
|
127
|
+
* @param obj - The vector.
|
|
128
|
+
* @param w - The value to add to the w-component.
|
|
129
|
+
* @returns A new vector with the w-component incremented.
|
|
130
|
+
*/
|
|
131
|
+
static addW<T extends VectorType, U extends VectorLike>(this: T, obj: U, w: number): InferVector<U>;
|
|
132
|
+
/**
|
|
133
|
+
* Subtracts one vector from another or subtracts a scalar value from a vector.
|
|
134
|
+
* @param a - The vector.
|
|
135
|
+
* @param b - The second vector or scalar value.
|
|
136
|
+
* @returns A new vector with subtracted components.
|
|
137
|
+
*/
|
|
41
138
|
static subtract<T extends VectorType, U extends VectorLike>(this: T, a: U, b: VectorLike | number): U;
|
|
139
|
+
/**
|
|
140
|
+
* Multiplies two vectors by their components, or multiplies a vector by a scalar value.
|
|
141
|
+
* @param a - The vector.
|
|
142
|
+
* @param b - The second vector or scalar value.
|
|
143
|
+
* @returns A new vector with multiplied components.
|
|
144
|
+
*/
|
|
42
145
|
static multiply<T extends VectorType, U extends VectorLike>(this: T, a: U, b: VectorLike | number): U;
|
|
146
|
+
/**
|
|
147
|
+
* Divides two vectors by their components, or divides a vector by a scalar value.
|
|
148
|
+
* @param a - The vector.
|
|
149
|
+
* @param b - The second vector or scalar vector.
|
|
150
|
+
* @returns A new vector with divided components.
|
|
151
|
+
*/
|
|
43
152
|
static divide<T extends VectorType, U extends VectorLike>(this: T, a: U, b: VectorLike | number): U;
|
|
153
|
+
/**
|
|
154
|
+
* Calculates the dot product of two vectors.
|
|
155
|
+
* @param a - The first vector.
|
|
156
|
+
* @param b - The second vector.
|
|
157
|
+
* @returns A scalar value representing the degree of alignment between the input vectors.
|
|
158
|
+
*/
|
|
44
159
|
static dotProduct<T extends VectorType, U extends VectorLike>(this: T, a: U, b: U): number;
|
|
160
|
+
/**
|
|
161
|
+
* Calculates the cross product of two vectors in three-dimensional space.
|
|
162
|
+
* @param a - The first vector.
|
|
163
|
+
* @param b - The second vector.
|
|
164
|
+
* @returns A new vector perpendicular to both input vectors.
|
|
165
|
+
*/
|
|
166
|
+
static crossProduct<T extends VectorType, U extends VectorObject>(this: T, a: U, b: U): U;
|
|
167
|
+
/**
|
|
168
|
+
* Normalizes a vector, producing a new vector with the same direction but with a magnitude of 1.
|
|
169
|
+
* @param vector - The vector to be normalized.
|
|
170
|
+
* @returns The new normalized vector.
|
|
171
|
+
*/
|
|
45
172
|
static normalize<T extends VectorType, U extends VectorLike>(this: T, a: U): U;
|
|
46
173
|
/**
|
|
47
174
|
* Creates a vector from an array of numbers.
|
|
48
175
|
* @param primitive An array of numbers (usually returned by a native).
|
|
49
176
|
*/
|
|
50
|
-
static fromArray<T extends VectorType
|
|
177
|
+
static fromArray<T extends VectorType, U extends VectorArray<T>>(this: T, primitive: U): InferVector<U>;
|
|
178
|
+
/**
|
|
179
|
+
* Creates a vector from an array or object containing vector components.
|
|
180
|
+
* @param primitive The object to use as a vector.
|
|
181
|
+
*/
|
|
182
|
+
static fromObject<T extends VectorType, U extends InferVector<T> | VectorArray<T>>(this: T, primitive: U): InstanceType<T>;
|
|
51
183
|
/**
|
|
52
184
|
* Creates an array of vectors from an array of number arrays
|
|
53
185
|
* @param primitives A multi-dimensional array of number arrays
|
|
54
186
|
*/
|
|
55
|
-
static fromArrays<T extends VectorType>(this: T, primitives:
|
|
187
|
+
static fromArrays<T extends VectorType, U extends VectorArray<T>[]>(this: T, primitives: U): InferVector<VectorArray<T>>[];
|
|
188
|
+
/**
|
|
189
|
+
* Calculates the length (magnitude) of a vector.
|
|
190
|
+
* @param obj - The vector for which to calculate the length.
|
|
191
|
+
* @returns The magnitude of the vector.
|
|
192
|
+
*/
|
|
56
193
|
static Length<T extends VectorType, U extends VectorLike>(this: T, obj: U): number;
|
|
194
|
+
/**
|
|
195
|
+
* Constructs a new vector.
|
|
196
|
+
* @param size The size of the vector (number of components).
|
|
197
|
+
* @param x The x-component of the vector.
|
|
198
|
+
* @param y The y-component of the vector (optional, defaults to x).
|
|
199
|
+
* @param z The z-component of the vector (optional).
|
|
200
|
+
* @param w The w-component of the vector (optional).
|
|
201
|
+
*/
|
|
57
202
|
constructor(size: number, x?: number, y?: number, z?: number | undefined, w?: number | undefined);
|
|
58
203
|
[Symbol.iterator](): Iterator<number>;
|
|
59
204
|
toString(): string;
|
|
60
205
|
toJSON(): string;
|
|
61
|
-
|
|
206
|
+
/**
|
|
207
|
+
* @see Vector.clone
|
|
208
|
+
*/
|
|
209
|
+
clone(): InferVector<this>;
|
|
62
210
|
/**
|
|
63
211
|
* The product of the Euclidean magnitudes of this and another Vector.
|
|
64
212
|
*
|
|
@@ -73,32 +221,116 @@ export declare class Vector {
|
|
|
73
221
|
* @returns Distance between this and another vector.
|
|
74
222
|
*/
|
|
75
223
|
distance(v: VectorLike): number;
|
|
76
|
-
|
|
224
|
+
/**
|
|
225
|
+
* @see Vector.normalize
|
|
226
|
+
*/
|
|
227
|
+
normalize(): this;
|
|
228
|
+
/**
|
|
229
|
+
* @see Vector.dotProduct
|
|
230
|
+
*/
|
|
77
231
|
dotProduct(v: this): number;
|
|
232
|
+
/**
|
|
233
|
+
* @see Vector.add
|
|
234
|
+
*/
|
|
78
235
|
add(v: VectorLike | number): this;
|
|
236
|
+
/**
|
|
237
|
+
* @see Vector.addX
|
|
238
|
+
*/
|
|
239
|
+
addX(x: number): InferVector<this>;
|
|
240
|
+
/**
|
|
241
|
+
* @see Vector.addY
|
|
242
|
+
*/
|
|
243
|
+
addY(x: number): InferVector<this>;
|
|
244
|
+
/**
|
|
245
|
+
* @see Vector.subtract
|
|
246
|
+
*/
|
|
79
247
|
subtract(v: VectorLike): this;
|
|
248
|
+
/**
|
|
249
|
+
* @see Vector.multiply
|
|
250
|
+
*/
|
|
80
251
|
multiply(v: VectorLike | number): this;
|
|
252
|
+
/**
|
|
253
|
+
* @see Vector.divide
|
|
254
|
+
*/
|
|
81
255
|
divide(v: VectorLike | number): this;
|
|
256
|
+
/**
|
|
257
|
+
* Converts the vector to an array of its components.
|
|
258
|
+
*/
|
|
82
259
|
toArray(): number[];
|
|
260
|
+
/**
|
|
261
|
+
* Replaces the components of the vector with the components of another vector object.
|
|
262
|
+
* @param v - The object whose components will replace the current vector's components.
|
|
263
|
+
*/
|
|
83
264
|
replace<T extends VectorLike>(v: T): void;
|
|
265
|
+
/**
|
|
266
|
+
* Calculates the length (magnitude) of a vector.
|
|
267
|
+
* @returns The magnitude of the vector.
|
|
268
|
+
*/
|
|
84
269
|
get Length(): number;
|
|
85
270
|
}
|
|
271
|
+
/**
|
|
272
|
+
* Represents a 2-dimensional vector.
|
|
273
|
+
*/
|
|
86
274
|
export declare class Vector2 extends Vector {
|
|
87
275
|
type: string;
|
|
88
|
-
constructor(x: number, y?: number);
|
|
89
276
|
static readonly Zero: Vector2;
|
|
277
|
+
/**
|
|
278
|
+
* Constructs a new 2D vector.
|
|
279
|
+
* @param x The x-component of the vector.
|
|
280
|
+
* @param y The y-component of the vector (optional, defaults to x).
|
|
281
|
+
*/
|
|
282
|
+
constructor(x: number, y?: number);
|
|
90
283
|
}
|
|
284
|
+
/**
|
|
285
|
+
* Represents a 3-dimensional vector.
|
|
286
|
+
*/
|
|
91
287
|
export declare class Vector3 extends Vector implements Vec3 {
|
|
92
288
|
type: string;
|
|
93
289
|
z: number;
|
|
94
|
-
constructor(x: number, y?: number, z?: number);
|
|
95
290
|
static readonly Zero: Vector3;
|
|
291
|
+
/**
|
|
292
|
+
* Constructs a new 3D vector.
|
|
293
|
+
* @param x The x-component of the vector.
|
|
294
|
+
* @param y The y-component of the vector (optional, defaults to x).
|
|
295
|
+
* @param z The z-component of the vector (optional, defaults to y).
|
|
296
|
+
*/
|
|
297
|
+
constructor(x: number, y?: number, z?: number);
|
|
298
|
+
/**
|
|
299
|
+
* @see Vector.addZ
|
|
300
|
+
*/
|
|
301
|
+
addZ(z: number): InferVector<this>;
|
|
302
|
+
/**
|
|
303
|
+
* @see Vector.crossProduct
|
|
304
|
+
*/
|
|
305
|
+
crossProduct(v: VectorLike): VectorLike;
|
|
96
306
|
}
|
|
307
|
+
/**
|
|
308
|
+
* Represents a 4-dimensional vector.
|
|
309
|
+
*/
|
|
97
310
|
export declare class Vector4 extends Vector {
|
|
98
311
|
type: string;
|
|
99
312
|
z: number;
|
|
100
313
|
w: number;
|
|
101
|
-
constructor(x: number, y?: number, z?: number, w?: number);
|
|
102
314
|
static readonly Zero: Vector4;
|
|
315
|
+
/**
|
|
316
|
+
* Constructs a new 4D vector.
|
|
317
|
+
* @param x The x-component of the vector.
|
|
318
|
+
* @param y The y-component of the vector (optional, defaults to x).
|
|
319
|
+
* @param z The z-component of the vector (optional, defaults to y).
|
|
320
|
+
* @param w The w-component of the vector (optional, defaults to z).
|
|
321
|
+
*/
|
|
322
|
+
constructor(x: number, y?: number, z?: number, w?: number);
|
|
323
|
+
/**
|
|
324
|
+
* @see Vector.addZ
|
|
325
|
+
*/
|
|
326
|
+
addZ(z: number): InferVector<this>;
|
|
327
|
+
/**
|
|
328
|
+
* @see Vector.addW
|
|
329
|
+
*/
|
|
330
|
+
addW(w: number): InferVector<this>;
|
|
331
|
+
/**
|
|
332
|
+
* @see Vector.crossProduct
|
|
333
|
+
*/
|
|
334
|
+
crossProduct(v: VectorLike): VectorLike;
|
|
103
335
|
}
|
|
104
336
|
export {};
|
package/common/utils/Vector.js
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
// Adapted from https://raw.githubusercontent.com/you21979/typescript-vector/master/vector3.ts
|
|
2
|
+
/**
|
|
3
|
+
* A base vector class inherited by all vector classes.
|
|
4
|
+
*/
|
|
2
5
|
export class Vector {
|
|
6
|
+
/**
|
|
7
|
+
* Creates a new vector based on the provided parameters.
|
|
8
|
+
* @param x The x-component of the vector.
|
|
9
|
+
* @param y The y-component of the vector (optional, defaults to the value of x).
|
|
10
|
+
* @param z The z-component of the vector (optional, defaults to the value of y).
|
|
11
|
+
* @param w The w-component of the vector (optional, defaults to the value of z).
|
|
12
|
+
* @returns A new vector instance.
|
|
13
|
+
*/
|
|
3
14
|
static create(x, y, z, w) {
|
|
4
15
|
if (y === undefined && typeof x === 'number')
|
|
5
16
|
return new Vector2(x, x);
|
|
@@ -18,38 +29,129 @@ export class Vector {
|
|
|
18
29
|
return new Vector4(x, y, z, w);
|
|
19
30
|
}
|
|
20
31
|
}
|
|
32
|
+
/**
|
|
33
|
+
* Creates a vector from binary data in a MsgpackBuffer.
|
|
34
|
+
* @param msgpackBuffer The buffer containing binary data.
|
|
35
|
+
* @returns A new vector instance.
|
|
36
|
+
*/
|
|
21
37
|
static fromBuffer({ buffer }) {
|
|
22
38
|
const arr = [];
|
|
23
39
|
for (let offset = 0; offset < buffer.length; offset += 4)
|
|
24
40
|
arr.push(buffer.readFloatLE(offset));
|
|
25
41
|
return this.fromArray(arr);
|
|
26
42
|
}
|
|
43
|
+
/**
|
|
44
|
+
* Creates a deep copy of the provided vector.
|
|
45
|
+
* @param obj The vector to clone.
|
|
46
|
+
* @returns A new vector instance that is a copy of the provided vector.
|
|
47
|
+
*/
|
|
27
48
|
static clone(obj) {
|
|
28
49
|
return this.create(obj);
|
|
29
50
|
}
|
|
51
|
+
/**
|
|
52
|
+
* Performs an operation between a vector and either another vector or scalar value.
|
|
53
|
+
* @param a - The first vector.
|
|
54
|
+
* @param b - The second vector or scalar value.
|
|
55
|
+
* @param operator - The function defining the operation to perform.
|
|
56
|
+
* @returns A new vector resulting from the operation.
|
|
57
|
+
*/
|
|
30
58
|
static operate(a, b, operator) {
|
|
31
59
|
let { x, y, z, w } = a;
|
|
32
60
|
const isNumber = typeof b === 'number';
|
|
33
|
-
x = operator(x, isNumber ? b : b.x);
|
|
34
|
-
y = operator(y, isNumber ? b : b.y);
|
|
61
|
+
x = operator(x, isNumber ? b : b.x ?? 0);
|
|
62
|
+
y = operator(y, isNumber ? b : b.y ?? 0);
|
|
35
63
|
if (z)
|
|
36
64
|
z = operator(z, isNumber ? b : b.z ?? 0);
|
|
37
65
|
if (w)
|
|
38
66
|
w = operator(w, isNumber ? b : b.w ?? 0);
|
|
39
67
|
return this.create(x, y, z, w);
|
|
40
68
|
}
|
|
69
|
+
/**
|
|
70
|
+
* Adds two vectors or a scalar value to a vector.
|
|
71
|
+
* @param a - The first vector or scalar value.
|
|
72
|
+
* @param b - The second vector or scalar value.
|
|
73
|
+
* @returns A new vector with incremented components.
|
|
74
|
+
*/
|
|
41
75
|
static add(a, b) {
|
|
42
76
|
return this.operate(a, b, (x, y) => x + y);
|
|
43
77
|
}
|
|
78
|
+
/**
|
|
79
|
+
* Adds a scalar value to the x-component of a vector.
|
|
80
|
+
* @param obj - The vector.
|
|
81
|
+
* @param x - The value to add to the x-component.
|
|
82
|
+
* @returns A new vector with the x-component incremented.
|
|
83
|
+
*/
|
|
84
|
+
static addX(obj, x) {
|
|
85
|
+
const vec = this.clone(obj);
|
|
86
|
+
vec.x += x;
|
|
87
|
+
return vec;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Adds a scalar value to the y-component of a vector.
|
|
91
|
+
* @param obj - The vector.
|
|
92
|
+
* @param y - The value to add to the y-component.
|
|
93
|
+
* @returns A new vector with the y-component incremented.
|
|
94
|
+
*/
|
|
95
|
+
static addY(obj, y) {
|
|
96
|
+
const vec = this.clone(obj);
|
|
97
|
+
vec.y += y;
|
|
98
|
+
return vec;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Adds a scalar value to the z-component of a vector.
|
|
102
|
+
* @param obj - The vector.
|
|
103
|
+
* @param z - The value to add to the z-component.
|
|
104
|
+
* @returns A new vector with the z-component incremented.
|
|
105
|
+
*/
|
|
106
|
+
static addZ(obj, z) {
|
|
107
|
+
const vec = this.clone(obj);
|
|
108
|
+
vec.z += z;
|
|
109
|
+
return vec;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Adds a scalar value to the w-component of a vector.
|
|
113
|
+
* @param obj - The vector.
|
|
114
|
+
* @param w - The value to add to the w-component.
|
|
115
|
+
* @returns A new vector with the w-component incremented.
|
|
116
|
+
*/
|
|
117
|
+
static addW(obj, w) {
|
|
118
|
+
const vec = this.clone(obj);
|
|
119
|
+
vec.w += w;
|
|
120
|
+
return vec;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Subtracts one vector from another or subtracts a scalar value from a vector.
|
|
124
|
+
* @param a - The vector.
|
|
125
|
+
* @param b - The second vector or scalar value.
|
|
126
|
+
* @returns A new vector with subtracted components.
|
|
127
|
+
*/
|
|
44
128
|
static subtract(a, b) {
|
|
45
129
|
return this.operate(a, b, (x, y) => x - y);
|
|
46
130
|
}
|
|
131
|
+
/**
|
|
132
|
+
* Multiplies two vectors by their components, or multiplies a vector by a scalar value.
|
|
133
|
+
* @param a - The vector.
|
|
134
|
+
* @param b - The second vector or scalar value.
|
|
135
|
+
* @returns A new vector with multiplied components.
|
|
136
|
+
*/
|
|
47
137
|
static multiply(a, b) {
|
|
48
138
|
return this.operate(a, b, (x, y) => x * y);
|
|
49
139
|
}
|
|
140
|
+
/**
|
|
141
|
+
* Divides two vectors by their components, or divides a vector by a scalar value.
|
|
142
|
+
* @param a - The vector.
|
|
143
|
+
* @param b - The second vector or scalar vector.
|
|
144
|
+
* @returns A new vector with divided components.
|
|
145
|
+
*/
|
|
50
146
|
static divide(a, b) {
|
|
51
147
|
return this.operate(a, b, (x, y) => x / y);
|
|
52
148
|
}
|
|
149
|
+
/**
|
|
150
|
+
* Calculates the dot product of two vectors.
|
|
151
|
+
* @param a - The first vector.
|
|
152
|
+
* @param b - The second vector.
|
|
153
|
+
* @returns A scalar value representing the degree of alignment between the input vectors.
|
|
154
|
+
*/
|
|
53
155
|
static dotProduct(a, b) {
|
|
54
156
|
let result = 0;
|
|
55
157
|
for (const key of ['x', 'y', 'z', 'w']) {
|
|
@@ -63,6 +165,29 @@ export class Vector {
|
|
|
63
165
|
}
|
|
64
166
|
return result;
|
|
65
167
|
}
|
|
168
|
+
/**
|
|
169
|
+
* Calculates the cross product of two vectors in three-dimensional space.
|
|
170
|
+
* @param a - The first vector.
|
|
171
|
+
* @param b - The second vector.
|
|
172
|
+
* @returns A new vector perpendicular to both input vectors.
|
|
173
|
+
*/
|
|
174
|
+
static crossProduct(a, b) {
|
|
175
|
+
const { x: ax, y: ay, z: az, w: aw } = a;
|
|
176
|
+
const { x: bx, y: by, z: bz } = b;
|
|
177
|
+
if (ax === undefined ||
|
|
178
|
+
ay === undefined ||
|
|
179
|
+
az === undefined ||
|
|
180
|
+
bx === undefined ||
|
|
181
|
+
by === undefined ||
|
|
182
|
+
bz === undefined)
|
|
183
|
+
throw new Error('Vector.crossProduct requires two three-dimensional vectors.');
|
|
184
|
+
return this.create(ay * bz - az * by, az * bx - ax * bz, ax * by - ay * bx, aw);
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Normalizes a vector, producing a new vector with the same direction but with a magnitude of 1.
|
|
188
|
+
* @param vector - The vector to be normalized.
|
|
189
|
+
* @returns The new normalized vector.
|
|
190
|
+
*/
|
|
66
191
|
static normalize(a) {
|
|
67
192
|
const length = a instanceof Vector ? a.Length : this.Length(a);
|
|
68
193
|
return this.divide(a, length);
|
|
@@ -73,15 +198,17 @@ export class Vector {
|
|
|
73
198
|
*/
|
|
74
199
|
static fromArray(primitive) {
|
|
75
200
|
const [x, y, z, w] = primitive;
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
201
|
+
return this.create(x, y, z, w);
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Creates a vector from an array or object containing vector components.
|
|
205
|
+
* @param primitive The object to use as a vector.
|
|
206
|
+
*/
|
|
207
|
+
static fromObject(primitive) {
|
|
208
|
+
if (Array.isArray(primitive))
|
|
209
|
+
return this.fromArray(primitive);
|
|
210
|
+
const { x, y, z, w } = primitive;
|
|
211
|
+
return this.create(x, y, z, w);
|
|
85
212
|
}
|
|
86
213
|
/**
|
|
87
214
|
* Creates an array of vectors from an array of number arrays
|
|
@@ -90,6 +217,11 @@ export class Vector {
|
|
|
90
217
|
static fromArrays(primitives) {
|
|
91
218
|
return primitives.map(this.fromArray);
|
|
92
219
|
}
|
|
220
|
+
/**
|
|
221
|
+
* Calculates the length (magnitude) of a vector.
|
|
222
|
+
* @param obj - The vector for which to calculate the length.
|
|
223
|
+
* @returns The magnitude of the vector.
|
|
224
|
+
*/
|
|
93
225
|
static Length(obj) {
|
|
94
226
|
let sum = 0;
|
|
95
227
|
for (const key of ['x', 'y', 'z', 'w']) {
|
|
@@ -100,12 +232,23 @@ export class Vector {
|
|
|
100
232
|
}
|
|
101
233
|
return Math.sqrt(sum);
|
|
102
234
|
}
|
|
235
|
+
/**
|
|
236
|
+
* Constructs a new vector.
|
|
237
|
+
* @param size The size of the vector (number of components).
|
|
238
|
+
* @param x The x-component of the vector.
|
|
239
|
+
* @param y The y-component of the vector (optional, defaults to x).
|
|
240
|
+
* @param z The z-component of the vector (optional).
|
|
241
|
+
* @param w The w-component of the vector (optional).
|
|
242
|
+
*/
|
|
103
243
|
constructor(size, x = 0, y = x, z, w) {
|
|
104
244
|
this.size = size;
|
|
105
245
|
this.x = x;
|
|
106
246
|
this.y = y;
|
|
107
247
|
this.z = z;
|
|
108
248
|
this.w = w;
|
|
249
|
+
/**
|
|
250
|
+
* The type identifier for vectors.
|
|
251
|
+
*/
|
|
109
252
|
this.type = 'vec';
|
|
110
253
|
}
|
|
111
254
|
*[Symbol.iterator]() {
|
|
@@ -123,6 +266,9 @@ export class Vector {
|
|
|
123
266
|
toJSON() {
|
|
124
267
|
return this.toString();
|
|
125
268
|
}
|
|
269
|
+
/**
|
|
270
|
+
* @see Vector.clone
|
|
271
|
+
*/
|
|
126
272
|
clone() {
|
|
127
273
|
return Vector.clone(this);
|
|
128
274
|
}
|
|
@@ -145,33 +291,74 @@ export class Vector {
|
|
|
145
291
|
distance(v) {
|
|
146
292
|
return Math.sqrt(this.distanceSquared(v));
|
|
147
293
|
}
|
|
148
|
-
|
|
294
|
+
/**
|
|
295
|
+
* @see Vector.normalize
|
|
296
|
+
*/
|
|
297
|
+
normalize() {
|
|
149
298
|
return Vector.normalize(this);
|
|
150
299
|
}
|
|
300
|
+
/**
|
|
301
|
+
* @see Vector.dotProduct
|
|
302
|
+
*/
|
|
151
303
|
dotProduct(v) {
|
|
152
304
|
return Vector.dotProduct(this, v);
|
|
153
305
|
}
|
|
306
|
+
/**
|
|
307
|
+
* @see Vector.add
|
|
308
|
+
*/
|
|
154
309
|
add(v) {
|
|
155
310
|
return Vector.add(this, v);
|
|
156
311
|
}
|
|
312
|
+
/**
|
|
313
|
+
* @see Vector.addX
|
|
314
|
+
*/
|
|
315
|
+
addX(x) {
|
|
316
|
+
return Vector.addX(this, x);
|
|
317
|
+
}
|
|
318
|
+
/**
|
|
319
|
+
* @see Vector.addY
|
|
320
|
+
*/
|
|
321
|
+
addY(x) {
|
|
322
|
+
return Vector.addY(this, x);
|
|
323
|
+
}
|
|
324
|
+
/**
|
|
325
|
+
* @see Vector.subtract
|
|
326
|
+
*/
|
|
157
327
|
subtract(v) {
|
|
158
328
|
return Vector.subtract(this, v);
|
|
159
329
|
}
|
|
330
|
+
/**
|
|
331
|
+
* @see Vector.multiply
|
|
332
|
+
*/
|
|
160
333
|
multiply(v) {
|
|
161
334
|
return Vector.multiply(this, v);
|
|
162
335
|
}
|
|
336
|
+
/**
|
|
337
|
+
* @see Vector.divide
|
|
338
|
+
*/
|
|
163
339
|
divide(v) {
|
|
164
340
|
return Vector.divide(this, v);
|
|
165
341
|
}
|
|
342
|
+
/**
|
|
343
|
+
* Converts the vector to an array of its components.
|
|
344
|
+
*/
|
|
166
345
|
toArray() {
|
|
167
346
|
return [...this];
|
|
168
347
|
}
|
|
348
|
+
/**
|
|
349
|
+
* Replaces the components of the vector with the components of another vector object.
|
|
350
|
+
* @param v - The object whose components will replace the current vector's components.
|
|
351
|
+
*/
|
|
169
352
|
replace(v) {
|
|
170
353
|
for (const key of ['x', 'y', 'z', 'w']) {
|
|
171
354
|
if (key in this && key in v)
|
|
172
355
|
this[key] = v[key];
|
|
173
356
|
}
|
|
174
357
|
}
|
|
358
|
+
/**
|
|
359
|
+
* Calculates the length (magnitude) of a vector.
|
|
360
|
+
* @returns The magnitude of the vector.
|
|
361
|
+
*/
|
|
175
362
|
get Length() {
|
|
176
363
|
let sum = 0;
|
|
177
364
|
for (let value of this)
|
|
@@ -179,27 +366,84 @@ export class Vector {
|
|
|
179
366
|
return Math.sqrt(sum);
|
|
180
367
|
}
|
|
181
368
|
}
|
|
369
|
+
/**
|
|
370
|
+
* Represents a 2-dimensional vector.
|
|
371
|
+
*/
|
|
182
372
|
export class Vector2 extends Vector {
|
|
373
|
+
/**
|
|
374
|
+
* Constructs a new 2D vector.
|
|
375
|
+
* @param x The x-component of the vector.
|
|
376
|
+
* @param y The y-component of the vector (optional, defaults to x).
|
|
377
|
+
*/
|
|
183
378
|
constructor(x, y = x) {
|
|
184
379
|
super(2, x, y);
|
|
185
380
|
this.type = 'vec2';
|
|
186
381
|
}
|
|
187
382
|
}
|
|
188
383
|
Vector2.Zero = new Vector2(0, 0);
|
|
384
|
+
/**
|
|
385
|
+
* Represents a 3-dimensional vector.
|
|
386
|
+
*/
|
|
189
387
|
export class Vector3 extends Vector {
|
|
388
|
+
/**
|
|
389
|
+
* Constructs a new 3D vector.
|
|
390
|
+
* @param x The x-component of the vector.
|
|
391
|
+
* @param y The y-component of the vector (optional, defaults to x).
|
|
392
|
+
* @param z The z-component of the vector (optional, defaults to y).
|
|
393
|
+
*/
|
|
190
394
|
constructor(x, y = x, z = y) {
|
|
191
395
|
super(3, x, y, z);
|
|
192
396
|
this.type = 'vec3';
|
|
193
397
|
this.z = z;
|
|
194
398
|
}
|
|
399
|
+
/**
|
|
400
|
+
* @see Vector.addZ
|
|
401
|
+
*/
|
|
402
|
+
addZ(z) {
|
|
403
|
+
return Vector.addZ(this, z);
|
|
404
|
+
}
|
|
405
|
+
/**
|
|
406
|
+
* @see Vector.crossProduct
|
|
407
|
+
*/
|
|
408
|
+
crossProduct(v) {
|
|
409
|
+
return Vector.crossProduct(this, v);
|
|
410
|
+
}
|
|
195
411
|
}
|
|
196
412
|
Vector3.Zero = new Vector3(0, 0, 0);
|
|
413
|
+
/**
|
|
414
|
+
* Represents a 4-dimensional vector.
|
|
415
|
+
*/
|
|
197
416
|
export class Vector4 extends Vector {
|
|
417
|
+
/**
|
|
418
|
+
* Constructs a new 4D vector.
|
|
419
|
+
* @param x The x-component of the vector.
|
|
420
|
+
* @param y The y-component of the vector (optional, defaults to x).
|
|
421
|
+
* @param z The z-component of the vector (optional, defaults to y).
|
|
422
|
+
* @param w The w-component of the vector (optional, defaults to z).
|
|
423
|
+
*/
|
|
198
424
|
constructor(x, y = x, z = y, w = z) {
|
|
199
425
|
super(4, x, y, z, w);
|
|
200
426
|
this.type = 'vec4';
|
|
201
427
|
this.z = z;
|
|
202
428
|
this.w = w;
|
|
203
429
|
}
|
|
430
|
+
/**
|
|
431
|
+
* @see Vector.addZ
|
|
432
|
+
*/
|
|
433
|
+
addZ(z) {
|
|
434
|
+
return Vector.addZ(this, z);
|
|
435
|
+
}
|
|
436
|
+
/**
|
|
437
|
+
* @see Vector.addW
|
|
438
|
+
*/
|
|
439
|
+
addW(w) {
|
|
440
|
+
return Vector.addW(this, w);
|
|
441
|
+
}
|
|
442
|
+
/**
|
|
443
|
+
* @see Vector.crossProduct
|
|
444
|
+
*/
|
|
445
|
+
crossProduct(v) {
|
|
446
|
+
return Vector.crossProduct(this, v);
|
|
447
|
+
}
|
|
204
448
|
}
|
|
205
449
|
Vector4.Zero = new Vector4(0, 0, 0, 0);
|
package/package.json
CHANGED
package/server/Events.js
CHANGED
|
@@ -8,15 +8,15 @@ const getClassFromArguments = (...args) => {
|
|
|
8
8
|
for (const arg of args) {
|
|
9
9
|
switch (arg.type) {
|
|
10
10
|
case ClassTypes.Vector2: {
|
|
11
|
-
newArgs.push(Vector2.
|
|
11
|
+
newArgs.push(Vector2.fromObject(arg));
|
|
12
12
|
continue;
|
|
13
13
|
}
|
|
14
14
|
case ClassTypes.Vector3: {
|
|
15
|
-
newArgs.push(Vector3.
|
|
15
|
+
newArgs.push(Vector3.fromObject(arg));
|
|
16
16
|
continue;
|
|
17
17
|
}
|
|
18
18
|
case ClassTypes.Vector4: {
|
|
19
|
-
newArgs.push(Vector4.
|
|
19
|
+
newArgs.push(Vector4.fromObject(arg));
|
|
20
20
|
continue;
|
|
21
21
|
}
|
|
22
22
|
case ClassTypes.Ped: {
|
|
@@ -9,12 +9,18 @@ export declare class BaseEntity {
|
|
|
9
9
|
protected handle: number;
|
|
10
10
|
protected type: ClassTypes;
|
|
11
11
|
constructor(handle: number);
|
|
12
|
+
static fromNetworkId(networkId: number): BaseEntity | null;
|
|
13
|
+
static fromStateBagName(stateBagName: string): BaseEntity | null;
|
|
12
14
|
get State(): StateBagInterface;
|
|
13
15
|
get Handle(): number;
|
|
14
16
|
get Owner(): number;
|
|
15
17
|
get FirstOwner(): number;
|
|
16
18
|
get Exists(): boolean;
|
|
17
|
-
|
|
19
|
+
/**
|
|
20
|
+
* @returns the entity that the calling entity is attached to, or null if
|
|
21
|
+
* there is none
|
|
22
|
+
*/
|
|
23
|
+
get AttachedTo(): BaseEntity | null;
|
|
18
24
|
get Position(): Vector3;
|
|
19
25
|
get Heading(): number;
|
|
20
26
|
get PositionAndHeading(): Vector4;
|
|
@@ -7,6 +7,18 @@ export class BaseEntity {
|
|
|
7
7
|
this.handle = handle;
|
|
8
8
|
this.type = ClassTypes.Entity;
|
|
9
9
|
}
|
|
10
|
+
static fromNetworkId(networkId) {
|
|
11
|
+
const ent = NetworkGetEntityFromNetworkId(networkId);
|
|
12
|
+
if (ent === 0)
|
|
13
|
+
return null;
|
|
14
|
+
return new BaseEntity(ent);
|
|
15
|
+
}
|
|
16
|
+
static fromStateBagName(stateBagName) {
|
|
17
|
+
const ent = GetEntityFromStateBagName(stateBagName);
|
|
18
|
+
if (ent === 0)
|
|
19
|
+
return null;
|
|
20
|
+
return new BaseEntity(ent);
|
|
21
|
+
}
|
|
10
22
|
get State() {
|
|
11
23
|
return cfx.Entity(this.handle).state;
|
|
12
24
|
}
|
|
@@ -22,8 +34,15 @@ export class BaseEntity {
|
|
|
22
34
|
get Exists() {
|
|
23
35
|
return this.handle !== 0 && DoesEntityExist(this.handle);
|
|
24
36
|
}
|
|
37
|
+
/**
|
|
38
|
+
* @returns the entity that the calling entity is attached to, or null if
|
|
39
|
+
* there is none
|
|
40
|
+
*/
|
|
25
41
|
get AttachedTo() {
|
|
26
|
-
|
|
42
|
+
const ent = GetEntityAttachedTo(this.handle);
|
|
43
|
+
if (ent === 0)
|
|
44
|
+
return null;
|
|
45
|
+
return new BaseEntity(ent);
|
|
27
46
|
}
|
|
28
47
|
get Position() {
|
|
29
48
|
return Vector3.fromArray(GetEntityCoords(this.handle));
|
|
@@ -83,6 +102,8 @@ export class BaseEntity {
|
|
|
83
102
|
return HasEntityBeenMarkedAsNoLongerNeeded(this.handle);
|
|
84
103
|
}
|
|
85
104
|
delete() {
|
|
86
|
-
|
|
105
|
+
if (this.Exists) {
|
|
106
|
+
DeleteEntity(this.handle);
|
|
107
|
+
}
|
|
87
108
|
}
|
|
88
109
|
}
|
package/server/entities/Ped.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { ClassTypes } from '../enum/ClassTypes';
|
|
2
2
|
import { Hash } from '../type/Hash';
|
|
3
3
|
import { BaseEntity } from './BaseEntity';
|
|
4
|
+
import { Vehicle } from './Vehicle';
|
|
4
5
|
export declare class Ped extends BaseEntity {
|
|
5
6
|
protected type: ClassTypes;
|
|
6
7
|
constructor(handle: number);
|
|
@@ -9,9 +10,9 @@ export declare class Ped extends BaseEntity {
|
|
|
9
10
|
* @returns Iterable list of Peds.
|
|
10
11
|
*/
|
|
11
12
|
static AllPeds(): IterableIterator<Ped>;
|
|
12
|
-
static fromNetworkId(netId: number): Ped;
|
|
13
|
+
static fromNetworkId(netId: number): Ped | null;
|
|
14
|
+
static fromStateBagName(stateBagName: string): Ped | null;
|
|
13
15
|
static fromSource(source: number): Ped;
|
|
14
|
-
static fromHandle(handle: number): Ped;
|
|
15
16
|
get Armour(): number;
|
|
16
17
|
get CauseOfDeath(): Hash;
|
|
17
18
|
get DesiredHeading(): number;
|
|
@@ -19,10 +20,13 @@ export declare class Ped extends BaseEntity {
|
|
|
19
20
|
get TaskCommand(): Hash;
|
|
20
21
|
get TaskStage(): number;
|
|
21
22
|
get LastSourceOfDamage(): number;
|
|
22
|
-
get DeathCause():
|
|
23
|
+
get DeathCause(): Hash;
|
|
23
24
|
get Weapon(): Hash;
|
|
24
|
-
|
|
25
|
-
|
|
25
|
+
/**
|
|
26
|
+
* @returns the current vehicle the ped is in, or null if it doesn't exist
|
|
27
|
+
*/
|
|
28
|
+
get CurrentVehicle(): Vehicle | null;
|
|
29
|
+
get LastVehicle(): Vehicle | null;
|
|
26
30
|
get IsPlayer(): boolean;
|
|
27
|
-
|
|
31
|
+
getSpecificTaskType(index: number): number;
|
|
28
32
|
}
|
package/server/entities/Ped.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ClassTypes } from '../enum/ClassTypes';
|
|
2
2
|
import { BaseEntity } from './BaseEntity';
|
|
3
|
+
import { Vehicle } from './Vehicle';
|
|
3
4
|
export class Ped extends BaseEntity {
|
|
4
5
|
constructor(handle) {
|
|
5
6
|
super(handle);
|
|
@@ -15,14 +16,20 @@ export class Ped extends BaseEntity {
|
|
|
15
16
|
}
|
|
16
17
|
}
|
|
17
18
|
static fromNetworkId(netId) {
|
|
18
|
-
|
|
19
|
+
const ent = NetworkGetEntityFromNetworkId(netId);
|
|
20
|
+
if (ent === 0)
|
|
21
|
+
return null;
|
|
22
|
+
return new Ped(ent);
|
|
23
|
+
}
|
|
24
|
+
static fromStateBagName(stateBagName) {
|
|
25
|
+
const handle = GetEntityFromStateBagName(stateBagName);
|
|
26
|
+
if (handle === 0)
|
|
27
|
+
return null;
|
|
28
|
+
return new Ped(handle);
|
|
19
29
|
}
|
|
20
30
|
static fromSource(source) {
|
|
21
31
|
return new Ped(GetPlayerPed(source));
|
|
22
32
|
}
|
|
23
|
-
static fromHandle(handle) {
|
|
24
|
-
return new Ped(handle);
|
|
25
|
-
}
|
|
26
33
|
get Armour() {
|
|
27
34
|
return GetPedArmour(this.handle);
|
|
28
35
|
}
|
|
@@ -50,16 +57,25 @@ export class Ped extends BaseEntity {
|
|
|
50
57
|
get Weapon() {
|
|
51
58
|
return GetSelectedPedWeapon(this.handle);
|
|
52
59
|
}
|
|
53
|
-
|
|
54
|
-
|
|
60
|
+
/**
|
|
61
|
+
* @returns the current vehicle the ped is in, or null if it doesn't exist
|
|
62
|
+
*/
|
|
63
|
+
get CurrentVehicle() {
|
|
64
|
+
const vehicle = GetVehiclePedIsIn(this.handle, false);
|
|
65
|
+
if (vehicle === 0)
|
|
66
|
+
return null;
|
|
67
|
+
return new Vehicle(vehicle);
|
|
55
68
|
}
|
|
56
69
|
get LastVehicle() {
|
|
57
|
-
|
|
70
|
+
const vehicle = GetVehiclePedIsIn(this.handle, false);
|
|
71
|
+
if (vehicle === 0)
|
|
72
|
+
return null;
|
|
73
|
+
return new Vehicle(GetVehiclePedIsIn(this.handle, true));
|
|
58
74
|
}
|
|
59
75
|
get IsPlayer() {
|
|
60
76
|
return IsPedAPlayer(this.handle);
|
|
61
77
|
}
|
|
62
|
-
|
|
78
|
+
getSpecificTaskType(index) {
|
|
63
79
|
return GetPedSpecificTaskType(this.handle, index);
|
|
64
80
|
}
|
|
65
81
|
}
|
|
@@ -8,6 +8,7 @@ export declare class Prop extends BaseEntity {
|
|
|
8
8
|
* @returns Iterable list of Props.
|
|
9
9
|
*/
|
|
10
10
|
static AllProps(): IterableIterator<Prop>;
|
|
11
|
-
static fromNetworkId(
|
|
11
|
+
static fromNetworkId(networkId: number): Prop | null;
|
|
12
|
+
static fromStateBagName(stateBagName: string): Prop | null;
|
|
12
13
|
static fromHandle(handle: number): Prop;
|
|
13
14
|
}
|
package/server/entities/Prop.js
CHANGED
|
@@ -14,8 +14,17 @@ export class Prop extends BaseEntity {
|
|
|
14
14
|
yield new Prop(prop);
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
|
-
static fromNetworkId(
|
|
18
|
-
|
|
17
|
+
static fromNetworkId(networkId) {
|
|
18
|
+
const ent = NetworkGetEntityFromNetworkId(networkId);
|
|
19
|
+
if (ent === 0)
|
|
20
|
+
return null;
|
|
21
|
+
return new Prop(ent);
|
|
22
|
+
}
|
|
23
|
+
static fromStateBagName(stateBagName) {
|
|
24
|
+
const ent = GetEntityFromStateBagName(stateBagName);
|
|
25
|
+
if (ent === 0)
|
|
26
|
+
return null;
|
|
27
|
+
return new Prop(ent);
|
|
19
28
|
}
|
|
20
29
|
static fromHandle(handle) {
|
|
21
30
|
return new Prop(handle);
|
|
@@ -12,8 +12,8 @@ export declare class Vehicle extends BaseEntity {
|
|
|
12
12
|
* @returns Iterable list of Vehicles.
|
|
13
13
|
*/
|
|
14
14
|
static AllVehicles(): IterableIterator<Vehicle>;
|
|
15
|
-
static fromNetworkId(
|
|
16
|
-
static
|
|
15
|
+
static fromNetworkId(networkId: number): Vehicle | null;
|
|
16
|
+
static fromStateBagName(stateBageName: string): Vehicle | null;
|
|
17
17
|
get IsEngineRunning(): boolean;
|
|
18
18
|
get IsPrimaryColourCustom(): boolean;
|
|
19
19
|
get IsSecondaryColourCustom(): boolean;
|
|
@@ -15,11 +15,17 @@ export class Vehicle extends BaseEntity {
|
|
|
15
15
|
yield new Vehicle(veh);
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
|
-
static fromNetworkId(
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
return new Vehicle(
|
|
18
|
+
static fromNetworkId(networkId) {
|
|
19
|
+
const ent = NetworkGetEntityFromNetworkId(networkId);
|
|
20
|
+
if (ent === 0)
|
|
21
|
+
return null;
|
|
22
|
+
return new Vehicle(ent);
|
|
23
|
+
}
|
|
24
|
+
static fromStateBagName(stateBageName) {
|
|
25
|
+
const ent = GetEntityFromStateBagName(stateBageName);
|
|
26
|
+
if (ent === 0)
|
|
27
|
+
return null;
|
|
28
|
+
return new Vehicle(ent);
|
|
23
29
|
}
|
|
24
30
|
get IsEngineRunning() {
|
|
25
31
|
return GetIsVehicleEngineRunning(this.handle);
|
|
@@ -79,7 +85,6 @@ export class Vehicle extends BaseEntity {
|
|
|
79
85
|
return GetVehicleInteriorColour(this.handle);
|
|
80
86
|
}
|
|
81
87
|
get LightsState() {
|
|
82
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
83
88
|
const [_, lightsOn, highbeansOn] = GetVehicleLightsState(this.handle);
|
|
84
89
|
return [lightsOn, highbeansOn];
|
|
85
90
|
}
|
|
@@ -132,7 +137,7 @@ export class Vehicle extends BaseEntity {
|
|
|
132
137
|
return IsVehicleSirenOn(this.handle);
|
|
133
138
|
}
|
|
134
139
|
get MaxHealth() {
|
|
135
|
-
return
|
|
140
|
+
return GetEntityMaxHealth(this.handle);
|
|
136
141
|
}
|
|
137
142
|
get ScriptTaskCommand() {
|
|
138
143
|
return GetPedScriptTaskCommand(this.handle);
|