@nativewrappers/fivem 0.0.35 → 0.0.37

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/Model.d.ts CHANGED
@@ -123,10 +123,12 @@ export declare class Model {
123
123
  get Dimensions(): Dimensions;
124
124
  /**
125
125
  * Request and load the model with a specified timeout. Default timeout is 1000 (recommended).
126
+ * This function will not automatically set the model as no longer needed when
127
+ * done.
126
128
  *
127
129
  * @param timeout Maximum allowed time for model to load.
128
130
  */
129
- request(timeout?: number): Promise<boolean>;
131
+ request(timeoutMs?: number): Promise<boolean>;
130
132
  /**
131
133
  * Sets the model as no longer needed allowing the game engine to free memory.
132
134
  */
package/client/Model.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { Game } from './Game';
2
2
  import { VehicleHash } from './hashes';
3
- import { Vector3 } from './utils';
3
+ import { Vector3, Wait } from './utils';
4
4
  /**
5
5
  * Class to create and manage entity models.
6
6
  */
@@ -170,24 +170,25 @@ export class Model {
170
170
  }
171
171
  /**
172
172
  * Request and load the model with a specified timeout. Default timeout is 1000 (recommended).
173
+ * This function will not automatically set the model as no longer needed when
174
+ * done.
173
175
  *
174
176
  * @param timeout Maximum allowed time for model to load.
175
177
  */
176
- request(timeout = 1000) {
177
- return new Promise(resolve => {
178
- if (!this.IsInCdImage && !this.IsValid && !IsWeaponValid(this.hash)) {
179
- resolve(false);
180
- }
181
- RequestModel(this.hash);
182
- const start = GetGameTimer();
183
- const interval = setInterval(() => {
184
- if (this.IsLoaded || GetGameTimer() - start >= timeout) {
185
- clearInterval(interval);
186
- this.markAsNoLongerNeeded();
187
- resolve(this.IsLoaded);
188
- }
189
- }, 0);
190
- });
178
+ async request(timeoutMs = 1000) {
179
+ if (!this.IsInCdImage && !this.IsValid && !IsWeaponValid(this.hash)) {
180
+ return false;
181
+ }
182
+ // pre-check so if its already loaded we don't add another ref
183
+ if (this.IsLoaded) {
184
+ return true;
185
+ }
186
+ RequestModel(this.hash);
187
+ const timeout = GetGameTimer() + timeoutMs;
188
+ while (!this.IsLoaded && timeout < GetGameTimer()) {
189
+ await Wait(0);
190
+ }
191
+ return this.IsLoaded;
191
192
  }
192
193
  /**
193
194
  * Sets the model as no longer needed allowing the game engine to free memory.
package/client/World.d.ts CHANGED
@@ -179,7 +179,7 @@ export declare abstract class World {
179
179
  * @param isNetwork
180
180
  * @returns Ped object.
181
181
  */
182
- static createPed(model: Model, position: Vector3, heading?: number, isNetwork?: boolean): Promise<Ped | null>;
182
+ static createPed(model: Model, position: Vector3, heading?: number, isNetwork?: boolean, pinToScript?: boolean): Promise<Ped | null>;
183
183
  /**
184
184
  * Creates a [[`Ped`]] with a random model.
185
185
  *
@@ -207,7 +207,7 @@ export declare abstract class World {
207
207
  * @param isNetwork
208
208
  * @returns Vehicle object.
209
209
  */
210
- static createVehicle(model: Model, position: Vector3, heading?: number, isNetwork?: boolean): Promise<Vehicle | null>;
210
+ static createVehicle(model: Model, position: Vector3, heading?: number, isNetwork?: boolean, pinToScript?: boolean): Promise<Vehicle | null>;
211
211
  /**
212
212
  * Create a random vehicle at a desired location.
213
213
  *
@@ -234,12 +234,12 @@ export declare abstract class World {
234
234
  *
235
235
  * @param model The [[`Model`]] to spawn (must be a Prop)
236
236
  * @param position Location of Prop
237
- * @param dynamic If set to true, the Prop will have physics otherwise it's static.
237
+ * @param doorFlag If set to true, the Prop will have physics otherwise it's static.
238
238
  * @param placeOnGround If set to true, sets the Prop on the ground nearest to position.
239
239
  * @param isNetwork
240
240
  * @returns Prop object.
241
241
  */
242
- static createProp(model: Model, position: Vector3, dynamic: boolean, placeOnGround: boolean, isNetwork?: boolean): Promise<Prop | null>;
242
+ static createProp(model: Model, position: Vector3, placeOnGround: boolean, isNetwork?: boolean, pinToScript?: boolean, forceToBeObject?: boolean): Promise<Prop | null>;
243
243
  /**
244
244
  * Create a pickup in a specific position in the world with a specified type and value.
245
245
  *
@@ -250,7 +250,7 @@ export declare abstract class World {
250
250
  * @param rotation If set, create a rotating pickup with this rotation.
251
251
  * @returns Pickup object.
252
252
  */
253
- static CreatePickup(type: PickupType, position: Vector3, model: Model, value: number, rotation?: Vector3): Promise<Pickup | null>;
253
+ static createPickup(type: PickupType, position: Vector3, model: Model, value: number, rotation?: Vector3): Promise<Pickup | null>;
254
254
  /**
255
255
  * Creates an ambient pickup.
256
256
  *
@@ -260,7 +260,7 @@ export declare abstract class World {
260
260
  * @param value The value tied to the pickup.
261
261
  * @returns The pickup in form of a Prop.
262
262
  */
263
- static CreateAmbientPickup(type: PickupType, position: Vector3, model: Model, value: number): Promise<Prop | null>;
263
+ static createAmbientPickup(type: PickupType, position: Vector3, model: Model, value: number): Promise<Prop | null>;
264
264
  /**
265
265
  * Draw a marker at a desired location. Careful! Must be drawn every tick.
266
266
  *
@@ -363,6 +363,7 @@ export declare abstract class World {
363
363
  * @returns {@see AsynchronousRaycastResult} object that must be awaited to get its results.
364
364
  */
365
365
  static raycast(start: Vector3, end: Vector3, losFlags?: IntersectFlags, shapeTestOptions?: number, ignoreEntity?: BaseEntity): AsynchronousRaycastResult;
366
+ static raycastDirection(source: Vector3, direction: Vector3, maxDistance: number, losFlags?: IntersectFlags, shapeTestOptions?: number, ignoreEntity?: BaseEntity): AsynchronousRaycastResult;
366
367
  /**
367
368
  * Cast a ray from the local players camera until it hits an entity
368
369
  *
package/client/World.js CHANGED
@@ -8,7 +8,7 @@ import { Ped, Vehicle } from './models';
8
8
  import { Pickup } from './Pickup';
9
9
  import { AsynchronousRaycastResult, SynchronousRaycastResult } from './Raycast';
10
10
  import { Rope } from './Rope';
11
- import { Maths, Wait } from './utils';
11
+ import { Maths, Vector3, Wait } from './utils';
12
12
  /**
13
13
  * Class with common world manipulations.
14
14
  *
@@ -322,11 +322,16 @@ export class World {
322
322
  * @param isNetwork
323
323
  * @returns Ped object.
324
324
  */
325
- static async createPed(model, position, heading = 0, isNetwork = true) {
325
+ static async createPed(model, position, heading = 0, isNetwork = true, pinToScript = true) {
326
326
  if (!model.IsPed || !(await model.request(1000))) {
327
327
  return null;
328
328
  }
329
- return new Ped(CreatePed(26, model.Hash, position.x, position.y, position.z, heading, isNetwork, false));
329
+ const ped = CreatePed(-1, model.Hash, position.x, position.y, position.z, heading, isNetwork, pinToScript);
330
+ model.markAsNoLongerNeeded();
331
+ if (ped === 0) {
332
+ return null;
333
+ }
334
+ return new Ped(ped);
330
335
  }
331
336
  /**
332
337
  * Creates a [[`Ped`]] with a random model.
@@ -357,11 +362,15 @@ export class World {
357
362
  * @param isNetwork
358
363
  * @returns Vehicle object.
359
364
  */
360
- static async createVehicle(model, position, heading = 0, isNetwork = true) {
365
+ static async createVehicle(model, position, heading = 0.0, isNetwork = true, pinToScript = true) {
361
366
  if (!model.IsVehicle || !(await model.request(1000))) {
362
367
  return null;
363
368
  }
364
- return new Vehicle(CreateVehicle(model.Hash, position.x, position.y, position.z, heading, isNetwork, false));
369
+ const vehicle = CreateVehicle(model.Hash, position.x, position.y, position.z, heading, isNetwork, pinToScript);
370
+ if (vehicle === 0) {
371
+ return null;
372
+ }
373
+ return new Vehicle(vehicle);
365
374
  }
366
375
  /**
367
376
  * Create a random vehicle at a desired location.
@@ -376,16 +385,13 @@ export class World {
376
385
  * @param isNetwork
377
386
  * @returns Vehicle object.
378
387
  */
379
- static async createRandomVehicle(position, heading = 0, isNetwork = true) {
388
+ static async createRandomVehicle(position, heading = 0.0, isNetwork = true) {
380
389
  const vehicleCount = Object.keys(VehicleHash).length / 2; // check
381
390
  const randomIndex = Maths.getRandomInt(0, vehicleCount);
382
391
  const randomVehicleName = VehicleHash[randomIndex];
383
392
  const modelHash = GetHashKey(randomVehicleName);
384
393
  const model = new Model(modelHash);
385
- if (!model.IsVehicle || !(await model.request(1000))) {
386
- return null;
387
- }
388
- return new Vehicle(CreateVehicle(model.Hash, position.x, position.y, position.z, heading, isNetwork, false));
394
+ return this.createVehicle(model, position, heading, isNetwork, false);
389
395
  }
390
396
  /*
391
397
  * Creates a rope at the specified location.
@@ -422,16 +428,21 @@ export class World {
422
428
  *
423
429
  * @param model The [[`Model`]] to spawn (must be a Prop)
424
430
  * @param position Location of Prop
425
- * @param dynamic If set to true, the Prop will have physics otherwise it's static.
431
+ * @param doorFlag If set to true, the Prop will have physics otherwise it's static.
426
432
  * @param placeOnGround If set to true, sets the Prop on the ground nearest to position.
427
433
  * @param isNetwork
428
434
  * @returns Prop object.
429
435
  */
430
- static async createProp(model, position, dynamic, placeOnGround, isNetwork = true) {
436
+ static async createProp(model, position, placeOnGround, isNetwork = true, pinToScript = true, forceToBeObject = false) {
431
437
  if (!model.IsProp || !(await model.request(1000))) {
432
438
  return null;
433
439
  }
434
- const prop = new Prop(CreateObject(model.Hash, position.x, position.y, position.z, isNetwork, true, dynamic));
440
+ const object = CreateObject(model.Hash, position.x, position.y, position.z, isNetwork, pinToScript, forceToBeObject);
441
+ model.markAsNoLongerNeeded();
442
+ if (object === 0) {
443
+ return null;
444
+ }
445
+ const prop = new Prop(object);
435
446
  if (placeOnGround) {
436
447
  prop.placeOnGround();
437
448
  }
@@ -447,7 +458,7 @@ export class World {
447
458
  * @param rotation If set, create a rotating pickup with this rotation.
448
459
  * @returns Pickup object.
449
460
  */
450
- static async CreatePickup(type, position, model, value, rotation) {
461
+ static async createPickup(type, position, model, value, rotation) {
451
462
  if (!(await model.request(1000))) {
452
463
  return null;
453
464
  }
@@ -456,6 +467,7 @@ export class World {
456
467
  handle = CreatePickupRotate(type, position.x, position.y, position.z, rotation.x, rotation.y, rotation.z, 0, value, 2, true, model.Hash);
457
468
  else
458
469
  handle = CreatePickup(type, position.x, position.y, position.z, 0, value, true, model.Hash);
470
+ model.markAsNoLongerNeeded();
459
471
  if (handle === 0) {
460
472
  return null;
461
473
  }
@@ -470,11 +482,12 @@ export class World {
470
482
  * @param value The value tied to the pickup.
471
483
  * @returns The pickup in form of a Prop.
472
484
  */
473
- static async CreateAmbientPickup(type, position, model, value) {
485
+ static async createAmbientPickup(type, position, model, value) {
474
486
  if (!(await model.request(1000))) {
475
487
  return null;
476
488
  }
477
489
  const handle = CreateAmbientPickup(type, position.x, position.y, position.z, 0, value, model.Hash, false, true);
490
+ model.markAsNoLongerNeeded();
478
491
  if (handle === 0) {
479
492
  return null;
480
493
  }
@@ -599,6 +612,10 @@ export class World {
599
612
  static raycast(start, end, losFlags = IntersectFlags.All, shapeTestOptions = SHAPE_TEST_DEFAULT, ignoreEntity) {
600
613
  return new AsynchronousRaycastResult(StartShapeTestLosProbe(start.x, start.y, start.z, end.x, end.y, end.z, losFlags, ignoreEntity?.Handle ?? 0, shapeTestOptions));
601
614
  }
615
+ static raycastDirection(source, direction, maxDistance, losFlags = IntersectFlags.All, shapeTestOptions = SHAPE_TEST_DEFAULT, ignoreEntity) {
616
+ const target = Vector3.add(source, Vector3.multiply(direction, maxDistance));
617
+ return new AsynchronousRaycastResult(StartShapeTestLosProbe(source.x, source.y, source.z, target.x, target.y, target.z, losFlags, ignoreEntity?.Handle ?? 0, shapeTestOptions));
618
+ }
602
619
  /**
603
620
  * Cast a ray from the local players camera until it hits an entity
604
621
  *
@@ -206,7 +206,7 @@ export declare class Vector {
206
206
  * Creates a vector from an array or object containing vector components.
207
207
  * @param primitive The object to use as a vector.
208
208
  */
209
- static fromObject<T extends VectorType, U extends InferVector<T> | VectorArray<T>>(this: T, primitive: U): InstanceType<T>;
209
+ static fromObject<T extends VectorType, U extends InferVector<T> | VectorArray<T>>(this: T, primitive: U | MsgpackBuffer): InstanceType<T>;
210
210
  /**
211
211
  * Creates an array of vectors from an array of number arrays
212
212
  * @param primitives A multi-dimensional array of number arrays
@@ -280,8 +280,8 @@ export declare class Vector {
280
280
  */
281
281
  divide(v: VectorLike | number): this;
282
282
  /**
283
- * @see Vector.addAbsolute
284
- */
283
+ * @see Vector.addAbsolute
284
+ */
285
285
  addAbsolute(v: VectorLike): this;
286
286
  /**
287
287
  * @see Vector.subtractAbsolute
@@ -346,8 +346,8 @@ export declare class Vector3 extends Vector implements Vec3 {
346
346
  */
347
347
  crossProduct(v: Vec3 | Vec4): Vec3 | Vec4;
348
348
  /**
349
- * @returns the x and y values as Vec2
350
- */
349
+ * @returns the x and y values as Vec2
350
+ */
351
351
  toVec2(): Vector2;
352
352
  }
353
353
  /**
@@ -379,12 +379,12 @@ export declare class Vector4 extends Vector {
379
379
  */
380
380
  crossProduct(v: Vec3 | Vec4): Vec3 | Vec4;
381
381
  /**
382
- * @returns the x and y values as Vec2
383
- */
382
+ * @returns the x and y values as Vec2
383
+ */
384
384
  toVec2(): Vector2;
385
385
  /**
386
- * @returns the x and y values as Vec3
387
- */
386
+ * @returns the x and y values as Vec3
387
+ */
388
388
  toVec3(): Vector3;
389
389
  }
390
390
  export {};
@@ -57,12 +57,12 @@ export class Vector {
57
57
  static operate(a, b, operator) {
58
58
  let { x, y, z, w } = a;
59
59
  const isNumber = typeof b === 'number';
60
- x = operator(x, isNumber ? b : b.x ?? 0);
61
- y = operator(y, isNumber ? b : b.y ?? 0);
60
+ x = operator(x, isNumber ? b : (b.x ?? 0));
61
+ y = operator(y, isNumber ? b : (b.y ?? 0));
62
62
  if (z)
63
- z = operator(z, isNumber ? b : b.z ?? 0);
63
+ z = operator(z, isNumber ? b : (b.z ?? 0));
64
64
  if (w)
65
- w = operator(w, isNumber ? b : b.w ?? 0);
65
+ w = operator(w, isNumber ? b : (b.w ?? 0));
66
66
  return this.create(x, y, z, w);
67
67
  }
68
68
  /**
@@ -259,6 +259,8 @@ export class Vector {
259
259
  static fromObject(primitive) {
260
260
  if (Array.isArray(primitive))
261
261
  return this.fromArray(primitive);
262
+ if ('buffer' in primitive && 'type' in primitive)
263
+ return this.fromBuffer(primitive);
262
264
  const { x, y, z, w } = primitive;
263
265
  return this.create(x, y, z, w);
264
266
  }
@@ -387,8 +389,8 @@ export class Vector {
387
389
  return Vector.divide(this, v);
388
390
  }
389
391
  /**
390
- * @see Vector.addAbsolute
391
- */
392
+ * @see Vector.addAbsolute
393
+ */
392
394
  addAbsolute(v) {
393
395
  return Vector.addAbsolute(this, v);
394
396
  }
@@ -484,8 +486,8 @@ export class Vector3 extends Vector {
484
486
  return Vector.crossProduct(this, v);
485
487
  }
486
488
  /**
487
- * @returns the x and y values as Vec2
488
- */
489
+ * @returns the x and y values as Vec2
490
+ */
489
491
  toVec2() {
490
492
  return new Vector2(this.x, this.y);
491
493
  }
@@ -529,14 +531,14 @@ export class Vector4 extends Vector {
529
531
  return Vector.crossProduct(this, v);
530
532
  }
531
533
  /**
532
- * @returns the x and y values as Vec2
533
- */
534
+ * @returns the x and y values as Vec2
535
+ */
534
536
  toVec2() {
535
537
  return new Vector2(this.x, this.y);
536
538
  }
537
539
  /**
538
- * @returns the x and y values as Vec3
539
- */
540
+ * @returns the x and y values as Vec3
541
+ */
540
542
  toVec3() {
541
543
  return new Vector3(this.x, this.y, this.z);
542
544
  }
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "author": "Remco Troost <d0p3t>",
5
5
  "license": "MIT",
6
6
  "type": "module",
7
- "version": "0.0.35",
7
+ "version": "0.0.37",
8
8
  "publishConfig": {
9
9
  "directory": "lib"
10
10
  },