@nativewrappers/fivem 0.0.35 → 0.0.36

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
  *
package/client/World.js CHANGED
@@ -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
  }
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.36",
8
8
  "publishConfig": {
9
9
  "directory": "lib"
10
10
  },