@nativewrappers/fivem 0.0.25 → 0.0.28

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/Events.js CHANGED
@@ -1,5 +1,4 @@
1
- /* eslint-disable */
2
- import { ClassTypes } from './enums/ClassTypes';
1
+ import { ClassTypes } from '../common/utils/ClassTypes';
3
2
  import { Ped } from './models/Ped';
4
3
  import { Vector2, Vector3, Vector4 } from './utils';
5
4
  import { Player } from './models/Player';
@@ -9,6 +8,10 @@ import { BaseEntity } from './models';
9
8
  const getClassFromArguments = (...args) => {
10
9
  const newArgs = [];
11
10
  for (const arg of args) {
11
+ if (!arg.type) {
12
+ newArgs.push(arg);
13
+ continue;
14
+ }
12
15
  switch (arg.type) {
13
16
  case ClassTypes.Vector2: {
14
17
  newArgs.push(Vector2.fromObject(arg));
package/client/Game.js CHANGED
@@ -430,7 +430,10 @@ export class Game {
430
430
  ExtendWorldBoundaryForPlayer(vec.x, vec.y, vec.z);
431
431
  }
432
432
  get LastVehicle() {
433
- return new Vehicle(GetPlayersLastVehicle());
433
+ const vehicle = GetPlayersLastVehicle();
434
+ if (vehicle === 0)
435
+ return null;
436
+ return new Vehicle(vehicle);
434
437
  }
435
438
  static getWaypointBlip() {
436
439
  if (!Game.IsWaypointActive)
@@ -7,7 +7,7 @@ import { Quaternion, Vector3 } from '../utils';
7
7
  import { EntityBoneCollection } from './';
8
8
  import { EntityBone } from './EntityBone';
9
9
  import { StateBagChangeHandler } from '../cfx';
10
- import { ClassTypes } from '../enums/ClassTypes';
10
+ import { ClassTypes } from '../../common/utils/ClassTypes';
11
11
  export declare class BaseEntity {
12
12
  static fromNetworkId(networkId: number): BaseEntity | null;
13
13
  static fromStateBagName(stateBagName: string): BaseEntity | null;
@@ -4,17 +4,16 @@ import { Model } from '../Model';
4
4
  import { Quaternion, Vector3 } from '../utils';
5
5
  import { EntityBoneCollection } from './';
6
6
  import cfx from '../cfx';
7
- import { ClassTypes } from '../enums/ClassTypes';
7
+ import { ClassTypes } from '../../common/utils/ClassTypes';
8
8
  export class BaseEntity {
9
9
  static fromNetworkId(networkId) {
10
10
  return new BaseEntity(NetworkGetEntityFromNetworkId(networkId));
11
11
  }
12
12
  static fromStateBagName(stateBagName) {
13
13
  const entity = GetEntityFromStateBagName(stateBagName);
14
- if (entity !== 0) {
15
- return new BaseEntity(entity);
16
- }
17
- return null;
14
+ if (entity === 0)
15
+ return null;
16
+ return new BaseEntity(entity);
18
17
  }
19
18
  constructor(handle) {
20
19
  this.stateBagCookies = [];
@@ -4,7 +4,7 @@ import { WeaponHash } from '../hashes';
4
4
  import { Tasks } from '../Tasks';
5
5
  import { PedBoneCollection, Vehicle } from './';
6
6
  import { WeaponCollection } from '../weapon/WeaponCollection';
7
- import { ClassTypes } from '../enums/ClassTypes';
7
+ import { ClassTypes } from '../../common/utils/ClassTypes';
8
8
  import { BaseEntity } from './BaseEntity';
9
9
  export declare class Ped extends BaseEntity {
10
10
  static exists(ped: Ped): boolean;
@@ -3,7 +3,7 @@ import { Gender, RagdollType, SpeechModifier, VehicleSeat, } from '../enums';
3
3
  import { Tasks } from '../Tasks';
4
4
  import { PedBoneCollection, Vehicle } from './';
5
5
  import { WeaponCollection } from '../weapon/WeaponCollection';
6
- import { ClassTypes } from '../enums/ClassTypes';
6
+ import { ClassTypes } from '../../common/utils/ClassTypes';
7
7
  import { BaseEntity } from './BaseEntity';
8
8
  export class Ped extends BaseEntity {
9
9
  static exists(ped) {
@@ -1,6 +1,6 @@
1
1
  import { Model, Color } from '..';
2
2
  import cfx from '../cfx';
3
- import { ClassTypes } from '../enums/ClassTypes';
3
+ import { ClassTypes } from '../../common/utils/ClassTypes';
4
4
  import { BaseEntity, Ped } from './';
5
5
  export class Player {
6
6
  static fromPedHandle(handle) {
@@ -1,4 +1,4 @@
1
- import { ClassTypes } from '../enums/ClassTypes';
1
+ import { ClassTypes } from '../../common/utils/ClassTypes';
2
2
  import { BaseEntity } from './BaseEntity';
3
3
  export declare class Prop extends BaseEntity {
4
4
  static exists(prop: Prop): boolean;
@@ -1,4 +1,4 @@
1
- import { ClassTypes } from '../enums/ClassTypes';
1
+ import { ClassTypes } from '../../common/utils/ClassTypes';
2
2
  import { BaseEntity } from './BaseEntity';
3
3
  export class Prop extends BaseEntity {
4
4
  static exists(prop) {
@@ -2,7 +2,7 @@ import { Ped, VehicleDoorCollection, VehicleModCollection, VehicleWheelCollectio
2
2
  import { RadioStation, VehicleClass, VehicleLandingGearState, VehicleLockStatus, VehicleRoofState, VehicleSeat } from '../enums';
3
3
  import { Model } from '../Model';
4
4
  import { Vector3 } from '../utils';
5
- import { ClassTypes } from '../enums/ClassTypes';
5
+ import { ClassTypes } from '../../common/utils/ClassTypes';
6
6
  import { BaseEntity } from './BaseEntity';
7
7
  export declare class Vehicle extends BaseEntity {
8
8
  static getModelDisplayName(vehicleModel: Model): string;
@@ -2,7 +2,7 @@ import { Ped, VehicleDoorCollection, VehicleModCollection, VehicleWheelCollectio
2
2
  import { VehicleRoofState, VehicleSeat, } from '../enums';
3
3
  import { Game } from '../Game';
4
4
  import { Vector3 } from '../utils';
5
- import { ClassTypes } from '../enums/ClassTypes';
5
+ import { ClassTypes } from '../../common/utils/ClassTypes';
6
6
  import { BaseEntity } from './BaseEntity';
7
7
  export class Vehicle extends BaseEntity {
8
8
  static getModelDisplayName(vehicleModel) {
@@ -1,4 +1,5 @@
1
1
  import type { MsgpackBuffer } from '../types';
2
+ import { ClassTypes } from './ClassTypes';
2
3
  /**
3
4
  * Represents a 2-dimensional vector.
4
5
  */
@@ -57,7 +58,7 @@ export declare class Vector {
57
58
  /**
58
59
  * The type identifier for vectors.
59
60
  */
60
- type: string;
61
+ type: ClassTypes;
61
62
  protected static create(x: number, y?: number): Vector2;
62
63
  protected static create(x: number, y?: number, z?: number): Vector3;
63
64
  protected static create(x: number, y?: number, z?: number, w?: number): Vector4;
@@ -195,7 +196,6 @@ export declare class Vector {
195
196
  constructor(size: number, x?: number, y?: number, z?: number | undefined, w?: number | undefined);
196
197
  [Symbol.iterator](): Iterator<number>;
197
198
  toString(): string;
198
- toJSON(): string;
199
199
  /**
200
200
  * @see Vector.clone
201
201
  */
@@ -265,7 +265,7 @@ export declare class Vector {
265
265
  * Represents a 2-dimensional vector.
266
266
  */
267
267
  export declare class Vector2 extends Vector {
268
- type: string;
268
+ type: ClassTypes;
269
269
  static readonly Zero: Vector2;
270
270
  /**
271
271
  * Constructs a new 2D vector.
@@ -278,7 +278,7 @@ export declare class Vector2 extends Vector {
278
278
  * Represents a 3-dimensional vector.
279
279
  */
280
280
  export declare class Vector3 extends Vector implements Vec3 {
281
- type: string;
281
+ type: ClassTypes;
282
282
  z: number;
283
283
  static readonly Zero: Vector3;
284
284
  /**
@@ -301,7 +301,7 @@ export declare class Vector3 extends Vector implements Vec3 {
301
301
  * Represents a 4-dimensional vector.
302
302
  */
303
303
  export declare class Vector4 extends Vector {
304
- type: string;
304
+ type: ClassTypes;
305
305
  z: number;
306
306
  w: number;
307
307
  static readonly Zero: Vector4;
@@ -1,4 +1,5 @@
1
1
  // Adapted from https://raw.githubusercontent.com/you21979/typescript-vector/master/vector3.ts
2
+ import { ClassTypes } from './ClassTypes';
2
3
  /**
3
4
  * A base vector class inherited by all vector classes.
4
5
  */
@@ -16,16 +17,14 @@ export class Vector {
16
17
  return new Vector2(x, x);
17
18
  if (typeof x === 'object')
18
19
  ({ x, y, z, w } = x);
19
- const type = this instanceof Vector
20
- ? this.type
21
- : `vec${[x, y, z, w].filter(arg => arg !== undefined).length}`;
22
- switch (type) {
20
+ const size = this instanceof Vector ? this.size : [x, y, z, w].filter(arg => arg !== undefined).length;
21
+ switch (size) {
23
22
  default:
24
- case 'vec':
23
+ case 2:
25
24
  return new Vector2(x, y);
26
- case 'vec3':
25
+ case 3:
27
26
  return new Vector3(x, y, z);
28
- case 'vec4':
27
+ case 4:
29
28
  return new Vector4(x, y, z, w);
30
29
  }
31
30
  }
@@ -155,11 +154,12 @@ export class Vector {
155
154
  static dotProduct(a, b) {
156
155
  let result = 0;
157
156
  for (const key of ['x', 'y', 'z', 'w']) {
158
- if (key in a && key in b)
159
- result += a[key] * b[key];
160
- else {
157
+ const x = a[key];
158
+ const y = b[key];
159
+ if (!!x && !!y)
160
+ result += x * y;
161
+ else if (x || y)
161
162
  throw new Error('Vectors must have the same dimensions');
162
- }
163
163
  }
164
164
  return result;
165
165
  }
@@ -247,7 +247,7 @@ export class Vector {
247
247
  /**
248
248
  * The type identifier for vectors.
249
249
  */
250
- this.type = 'vec';
250
+ this.type = ClassTypes.Vector2;
251
251
  }
252
252
  *[Symbol.iterator]() {
253
253
  yield this.x;
@@ -258,11 +258,7 @@ export class Vector {
258
258
  yield this.w;
259
259
  }
260
260
  toString() {
261
- const { x, y, z, w } = this;
262
- return `${this.type}(${[x, y, z, w].filter(val => val !== undefined).join(', ')})`;
263
- }
264
- toJSON() {
265
- return this.toString();
261
+ return `vector${this.size}(${this.toArray().join(', ')})`;
266
262
  }
267
263
  /**
268
264
  * @see Vector.clone
@@ -375,7 +371,7 @@ export class Vector2 extends Vector {
375
371
  */
376
372
  constructor(x, y = x) {
377
373
  super(2, x, y);
378
- this.type = 'vec2';
374
+ this.type = ClassTypes.Vector2;
379
375
  }
380
376
  }
381
377
  Vector2.Zero = new Vector2(0, 0);
@@ -391,7 +387,7 @@ export class Vector3 extends Vector {
391
387
  */
392
388
  constructor(x, y = x, z = y) {
393
389
  super(3, x, y, z);
394
- this.type = 'vec3';
390
+ this.type = ClassTypes.Vector3;
395
391
  this.z = z;
396
392
  }
397
393
  /**
@@ -421,7 +417,7 @@ export class Vector4 extends Vector {
421
417
  */
422
418
  constructor(x, y = x, z = y, w = z) {
423
419
  super(4, x, y, z, w);
424
- this.type = 'vec4';
420
+ this.type = ClassTypes.Vector4;
425
421
  this.z = z;
426
422
  this.w = w;
427
423
  }
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.25",
7
+ "version": "0.0.28",
8
8
  "publishConfig": {
9
9
  "directory": "lib"
10
10
  },
@@ -1,5 +1,6 @@
1
1
  import { Player } from './entities/Player';
2
2
  export type NetEvent = (player: Player, ...args: any[]) => void;
3
+ export type LocalEvent = (...args: any[]) => void;
3
4
  export declare class Events {
4
5
  static cancel(): void;
5
6
  static wasCanceled(): boolean;
@@ -11,5 +12,5 @@ export declare class Events {
11
12
  /**
12
13
  * An on wrapper that properly converts the classes
13
14
  */
14
- static on: (eventName: string, event: NetEvent) => void;
15
+ static on: (eventName: string, event: LocalEvent) => void;
15
16
  }
package/server/Events.js CHANGED
@@ -1,11 +1,14 @@
1
- /* eslint-disable @typescript-eslint/no-explicit-any */
2
1
  import { Ped, Prop, Vehicle, Entity } from './entities';
3
2
  import { Player } from './entities/Player';
4
- import { ClassTypes } from './enum/ClassTypes';
3
+ import { ClassTypes } from '../common/utils/ClassTypes';
5
4
  import { Vector2, Vector3, Vector4 } from './utils';
6
5
  const getClassFromArguments = (...args) => {
7
6
  const newArgs = [];
8
7
  for (const arg of args) {
8
+ if (!arg.type) {
9
+ newArgs.push(arg);
10
+ continue;
11
+ }
9
12
  switch (arg.type) {
10
13
  case ClassTypes.Vector2: {
11
14
  newArgs.push(Vector2.fromObject(arg));
@@ -71,7 +74,6 @@ Events.onNet = (eventName, event) => {
71
74
  */
72
75
  Events.on = (eventName, event) => {
73
76
  on(eventName, (...args) => {
74
- const ply = new Player(source);
75
- event(ply, ...getClassFromArguments(...args));
77
+ event(...getClassFromArguments(...args));
76
78
  });
77
79
  };
@@ -1,5 +1,5 @@
1
1
  /// <reference types="@citizenfx/server" />
2
- import { ClassTypes } from '../enum/ClassTypes';
2
+ import { ClassTypes } from '../../common/utils/ClassTypes';
3
3
  import { eEntityType } from '../enum/eEntityType';
4
4
  import { PopulationType } from '../enum/PopulationType';
5
5
  import { Hash } from '../type/Hash';
@@ -1,5 +1,5 @@
1
1
  import cfx from '../cfx';
2
- import { ClassTypes } from '../enum/ClassTypes';
2
+ import { ClassTypes } from '../../common/utils/ClassTypes';
3
3
  import { Vector4 } from '../utils';
4
4
  import { Vector3 } from '../utils';
5
5
  export class BaseEntity {
@@ -1,4 +1,4 @@
1
- import { ClassTypes } from '../enum/ClassTypes';
1
+ import { ClassTypes } from '../../common/utils/ClassTypes';
2
2
  import { Hash } from '../type/Hash';
3
3
  import { BaseEntity } from './BaseEntity';
4
4
  import { Vehicle } from './Vehicle';
@@ -1,4 +1,4 @@
1
- import { ClassTypes } from '../enum/ClassTypes';
1
+ import { ClassTypes } from '../../common/utils/ClassTypes';
2
2
  import { BaseEntity } from './BaseEntity';
3
3
  import { Vehicle } from './Vehicle';
4
4
  export class Ped extends BaseEntity {
@@ -1,5 +1,5 @@
1
1
  /// <reference types="@citizenfx/server" />
2
- import { ClassTypes } from '../enum/ClassTypes';
2
+ import { ClassTypes } from '../../common/utils/ClassTypes';
3
3
  import { Vector3 } from '../utils';
4
4
  import { Ped } from './Ped';
5
5
  export declare class Player {
@@ -1,5 +1,5 @@
1
1
  import cfx from '../cfx';
2
- import { ClassTypes } from '../enum/ClassTypes';
2
+ import { ClassTypes } from '../../common/utils/ClassTypes';
3
3
  import { cleanPlayerName } from '../utils';
4
4
  import { Vector3 } from '../utils';
5
5
  import { Ped } from './Ped';
@@ -129,7 +129,6 @@ export class Player {
129
129
  drop(reason = 'No reason specified') {
130
130
  DropPlayer(this.Src, reason);
131
131
  }
132
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
133
132
  emit(eventName, ...args) {
134
133
  TriggerClientEvent(eventName, this.source, ...args);
135
134
  }
@@ -1,4 +1,4 @@
1
- import { ClassTypes } from '../enum/ClassTypes';
1
+ import { ClassTypes } from '../../common/utils/ClassTypes';
2
2
  import { BaseEntity } from './BaseEntity';
3
3
  export declare class Prop extends BaseEntity {
4
4
  protected type: ClassTypes;
@@ -1,4 +1,4 @@
1
- import { ClassTypes } from '../enum/ClassTypes';
1
+ import { ClassTypes } from '../../common/utils/ClassTypes';
2
2
  import { BaseEntity } from './BaseEntity';
3
3
  export class Prop extends BaseEntity {
4
4
  constructor(handle) {
@@ -1,4 +1,4 @@
1
- import { ClassTypes } from '../enum/ClassTypes';
1
+ import { ClassTypes } from '../../common/utils/ClassTypes';
2
2
  import { VehicleLockStatus } from '../enum/VehicleLockStatus';
3
3
  import { VehicleType } from '../enum/VehicleType';
4
4
  import { Hash } from '../type/Hash';
@@ -1,4 +1,4 @@
1
- import { ClassTypes } from '../enum/ClassTypes';
1
+ import { ClassTypes } from '../../common/utils/ClassTypes';
2
2
  import { Color } from '../utils';
3
3
  import { BaseEntity } from './BaseEntity';
4
4
  export class Vehicle extends BaseEntity {
@@ -1,4 +1,3 @@
1
- export { ClassTypes } from './ClassTypes';
2
1
  export { eEntityType } from './eEntityType';
3
2
  export { PopulationType } from './PopulationType';
4
3
  export { VehicleLockStatus } from './VehicleLockStatus';
@@ -1,4 +1,3 @@
1
- export { ClassTypes } from './ClassTypes';
2
1
  export { eEntityType } from './eEntityType';
3
2
  export { PopulationType } from './PopulationType';
4
3
  export { VehicleLockStatus } from './VehicleLockStatus';
@@ -1,11 +0,0 @@
1
- export declare enum ClassTypes {
2
- Ped = 0,
3
- Prop = 1,
4
- Vehicle = 2,
5
- Entity = 3,
6
- Player = 4,
7
- Vector2 = 5,
8
- Vector3 = 6,
9
- Vector4 = 7,
10
- Quanterion = 8
11
- }
@@ -1,12 +0,0 @@
1
- export var ClassTypes;
2
- (function (ClassTypes) {
3
- ClassTypes[ClassTypes["Ped"] = 0] = "Ped";
4
- ClassTypes[ClassTypes["Prop"] = 1] = "Prop";
5
- ClassTypes[ClassTypes["Vehicle"] = 2] = "Vehicle";
6
- ClassTypes[ClassTypes["Entity"] = 3] = "Entity";
7
- ClassTypes[ClassTypes["Player"] = 4] = "Player";
8
- ClassTypes[ClassTypes["Vector2"] = 5] = "Vector2";
9
- ClassTypes[ClassTypes["Vector3"] = 6] = "Vector3";
10
- ClassTypes[ClassTypes["Vector4"] = 7] = "Vector4";
11
- ClassTypes[ClassTypes["Quanterion"] = 8] = "Quanterion";
12
- })(ClassTypes || (ClassTypes = {}));
File without changes
File without changes