@nativewrappers/fivem 0.0.30 → 0.0.32

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.
Files changed (36) hide show
  1. package/client/Game.js +1 -1
  2. package/client/Raycast.d.ts +23 -1
  3. package/client/Raycast.js +56 -10
  4. package/client/TaskSequence.js +1 -0
  5. package/client/World.d.ts +24 -11
  6. package/client/World.js +30 -15
  7. package/client/enums/RaycastEnums.d.ts +27 -0
  8. package/client/enums/RaycastEnums.js +30 -0
  9. package/client/enums/index.d.ts +1 -1
  10. package/client/enums/index.js +1 -1
  11. package/client/index.d.ts +1 -1
  12. package/client/index.js +1 -1
  13. package/client/models/BaseEntity.d.ts +10 -10
  14. package/client/models/BaseEntity.js +16 -16
  15. package/client/models/EntityBoneCollection.d.ts +0 -2
  16. package/client/models/EntityBoneCollection.js +0 -1
  17. package/client/models/Ped.d.ts +6 -6
  18. package/client/models/Ped.js +47 -50
  19. package/client/models/Player.d.ts +1 -1
  20. package/client/models/Prop.d.ts +1 -1
  21. package/client/models/Prop.js +3 -3
  22. package/client/models/Vehicle.d.ts +4 -4
  23. package/client/models/VehicleModCollection.d.ts +1 -1
  24. package/client/models/VehicleModCollection.js +1 -2
  25. package/client/models/VehicleWindowCollection.d.ts +2 -2
  26. package/client/models/VehicleWindowCollection.js +6 -5
  27. package/client/ui/menu/Menu.d.ts +2 -2
  28. package/client/ui/menu/items/UIMenuItem.d.ts +1 -1
  29. package/client/ui/menu/items/panels/AbstractUIMenuPanel.d.ts +2 -2
  30. package/client/ui/menu/items/panels/AbstractUIMenuPanel.js +1 -1
  31. package/client/ui/menu/items/panels/UIMenuGridPanel.d.ts +4 -4
  32. package/common/utils/Vector.d.ts +53 -3
  33. package/common/utils/Vector.js +89 -3
  34. package/package.json +1 -1
  35. package/client/enums/IntersectOptions.d.ts +0 -15
  36. package/client/enums/IntersectOptions.js +0 -16
package/client/Game.js CHANGED
@@ -76,7 +76,7 @@ export class Game {
76
76
  */
77
77
  static get Player() {
78
78
  const handle = PlayerId();
79
- if (typeof this.cachedPlayer === 'undefined' || handle !== this.cachedPlayer.Handle) {
79
+ if (this.cachedPlayer === undefined || handle !== this.cachedPlayer.Handle) {
80
80
  this.cachedPlayer = new Player(handle);
81
81
  }
82
82
  return this.cachedPlayer;
@@ -4,7 +4,7 @@ import { Vector3 } from './utils';
4
4
  /**
5
5
  * Class that represents the result of a raycast.
6
6
  */
7
- export declare class RaycastResult {
7
+ declare abstract class RaycastResult {
8
8
  /**
9
9
  * Return the entity that was hit.
10
10
  */
@@ -33,6 +33,17 @@ export declare class RaycastResult {
33
33
  * Raycast result's handle.
34
34
  */
35
35
  get Result(): number;
36
+ /**
37
+ * @returns if the shape test handle was already discarded
38
+ */
39
+ get WasDiscarded(): boolean;
40
+ /**
41
+ * NOTE: These will not be updated unless polled by `resolve` or the shape
42
+ * test is synchronous
43
+ * @returns if the raycast has been marked as ready by the engine
44
+ */
45
+ get HasResolved(): boolean;
46
+ protected applyShapeTestResults(): void;
36
47
  private handle;
37
48
  private hitPositionArg;
38
49
  private hitSomethingArg;
@@ -47,3 +58,14 @@ export declare class RaycastResult {
47
58
  */
48
59
  constructor(handle: number);
49
60
  }
61
+ export declare class SynchronousRaycastResult extends RaycastResult {
62
+ constructor(handle: number);
63
+ }
64
+ export declare class AsynchronousRaycastResult extends RaycastResult {
65
+ /**
66
+ * waits until the shape test handle is valid and then sets the expected
67
+ * values on the RaycastResult
68
+ */
69
+ resolve(timeoutInMs?: number): Promise<void>;
70
+ }
71
+ export {};
package/client/Raycast.js CHANGED
@@ -1,9 +1,10 @@
1
+ import { ShapeTestStatus } from './enums/RaycastEnums';
1
2
  import { Game } from './Game';
2
- import { Vector3 } from './utils';
3
+ import { Delay, Vector3 } from './utils';
3
4
  /**
4
5
  * Class that represents the result of a raycast.
5
6
  */
6
- export class RaycastResult {
7
+ class RaycastResult {
7
8
  /**
8
9
  * Return the entity that was hit.
9
10
  */
@@ -46,7 +47,33 @@ export class RaycastResult {
46
47
  get Result() {
47
48
  return this.result;
48
49
  }
49
- // FIXME: This only works with StartExpensiveSynchronousShapeTestLosProbe, this should have some getter you have to await afterwards for all of the data
50
+ /**
51
+ * @returns if the shape test handle was already discarded
52
+ */
53
+ get WasDiscarded() {
54
+ return this.result === ShapeTestStatus.Discarded;
55
+ }
56
+ /**
57
+ * NOTE: These will not be updated unless polled by `resolve` or the shape
58
+ * test is synchronous
59
+ * @returns if the raycast has been marked as ready by the engine
60
+ */
61
+ get HasResolved() {
62
+ return this.result === ShapeTestStatus.Ready;
63
+ }
64
+ applyShapeTestResults() {
65
+ const [result, hit, endCoords, surfaceNormal, materialHash, entityHit] = GetShapeTestResultIncludingMaterial(this.handle);
66
+ this.result = result;
67
+ if (!this.HasResolved || this.WasDiscarded)
68
+ return;
69
+ this.hitSomethingArg = hit;
70
+ this.hitPositionArg = Vector3.fromArray(endCoords);
71
+ this.surfaceNormalArg = Vector3.fromArray(surfaceNormal);
72
+ this.materialArg = materialHash;
73
+ if (entityHit !== 0) {
74
+ this.entityHandleArg = Game.entityFromHandle(entityHit);
75
+ }
76
+ }
50
77
  /**
51
78
  * Create a RaycastResult object that gets the results from a StartShapeTestRay()
52
79
  *
@@ -59,12 +86,31 @@ export class RaycastResult {
59
86
  this.entityHandleArg = null;
60
87
  this.surfaceNormalArg = new Vector3(0, 0, 0);
61
88
  this.materialArg = 0;
62
- const [result, hit, endCoords, surfaceNormal, materialHash, entityHit] = GetShapeTestResultIncludingMaterial(this.handle);
63
- this.hitSomethingArg = hit;
64
- this.hitPositionArg = Vector3.fromArray(endCoords);
65
- this.surfaceNormalArg = Vector3.fromArray(surfaceNormal);
66
- this.materialArg = materialHash;
67
- this.entityHandleArg = Game.entityFromHandle(entityHit);
68
- this.result = result;
89
+ this.result = ShapeTestStatus.NotReady;
90
+ }
91
+ }
92
+ export class SynchronousRaycastResult extends RaycastResult {
93
+ constructor(handle) {
94
+ super(handle);
95
+ // if we're using a synchronous call then we want to instantly update our
96
+ // data, if its invalid then the caller can deal with it.
97
+ this.applyShapeTestResults();
98
+ }
99
+ }
100
+ export class AsynchronousRaycastResult extends RaycastResult {
101
+ /**
102
+ * waits until the shape test handle is valid and then sets the expected
103
+ * values on the RaycastResult
104
+ */
105
+ async resolve(timeoutInMs = 1000) {
106
+ const timeout = GetGameTimer() + timeoutInMs;
107
+ // this has to be polled every frame or the engien will mark the field shape
108
+ // test handle as discarded
109
+ while (!this.HasResolved && !this.WasDiscarded) {
110
+ this.applyShapeTestResults();
111
+ if (timeout < GetGameTimer())
112
+ break;
113
+ await Delay(0);
114
+ }
69
115
  }
70
116
  }
@@ -1,4 +1,5 @@
1
1
  import { Ped } from './models/Ped';
2
+ // TODO: Figure out why this uses 'null ped'
2
3
  export class TaskSequence {
3
4
  constructor(handle) {
4
5
  this.handle = 0;
package/client/World.d.ts CHANGED
@@ -1,11 +1,11 @@
1
1
  import { Model, Prop } from './';
2
2
  import { Blip } from './Blip';
3
3
  import { Camera } from './Camera';
4
- import { CameraTypes, CloudHat, IntersectOptions, MarkerType, PickupType, RopeType, Weather } from './enums';
4
+ import { CameraTypes, CloudHat, IntersectFlags, MarkerType, PickupType, RopeType, Weather } from './enums';
5
5
  import { Ped, Vehicle } from './models';
6
6
  import type { BaseEntity } from './models/BaseEntity';
7
7
  import { Pickup } from './Pickup';
8
- import { RaycastResult } from './Raycast';
8
+ import { AsynchronousRaycastResult, SynchronousRaycastResult } from './Raycast';
9
9
  import { Rope } from './Rope';
10
10
  import { Color, Vector3 } from './utils';
11
11
  /**
@@ -340,24 +340,37 @@ export declare abstract class World {
340
340
  */
341
341
  static drawPoly(vertexA: Vector3, vertexB: Vector3, vertexC: Vector3, color: Color): void;
342
342
  /**
343
- * Cast ("shoot") a ray in a certain direction to detect entities in the way.
343
+ * Cast a ray from {@param start} to {@param end}.
344
344
  *
345
- * @param source Starting position of raycast.
346
- * @param direction Direction to cast a ray to.
347
- * @param maxDistance Max distance to cast the ray.
345
+ * @param start Starting position of raycast.
346
+ * @param end Direction to cast a ray to.
347
+ * @param losFlags The entity type(s) that the raycast should intersect with
348
+ * defaults to {@enum IntersectFlags.All}
348
349
  * @param options Possible entity types to detect.
349
350
  * @param ignoreEntity An entity to ignore (usually player's Ped).
350
- * @returns RaycastResult object.
351
+ * @returns {@see SynchronousRaycastResult} object.
352
+ */
353
+ static expensiveRaycast(start: Vector3, end: Vector3, losFlags?: IntersectFlags, shapeTestOptions?: number, ignoreEntity?: BaseEntity): SynchronousRaycastResult;
354
+ /**
355
+ * Cast a ray from {@param start} to {@param end} and returns the first hit
356
+ * entity or coordinate .
357
+ *
358
+ * @param start starting position of raycast.
359
+ * @param end the ending position to raycast to.
360
+ * @param losFlags The entity type(s) that the raycast should intersect with defaults to {@enum IntersectFlags.All}
361
+ * @param shapeTestOptions shape test collision modifiers defaults to ignoring glass, see through, and no collided entities
362
+ * @param ignoreEntity An entity to ignore (usually player's Ped).
363
+ * @returns {@see AsynchronousRaycastResult} object that must be awaited to get its results.
351
364
  */
352
- static raycast(source: Vector3, direction: Vector3, maxDistance: number, options: IntersectOptions, ignoreEntity: BaseEntity): RaycastResult;
365
+ static raycast(start: Vector3, end: Vector3, losFlags?: IntersectFlags, shapeTestOptions?: number, ignoreEntity?: BaseEntity): AsynchronousRaycastResult;
353
366
  /**
354
367
  * Cast a ray from the local players camera until it hits an entity
355
368
  *
356
369
  * @param maxDistance Max distance to cast the ray.
357
- * @param options Possible entity types to detect.
358
- * @returns RaycastResult object.
370
+ * @param flags Possible entity types to detect.
371
+ * @returns SynchronousRaycast object.
359
372
  */
360
- static raycastPlayerCamera(maxDistance: number, options: IntersectOptions): RaycastResult;
373
+ static raycastPlayerCamera(maxDistance: number, flags: IntersectFlags): SynchronousRaycastResult;
361
374
  /**
362
375
  * Gets the closest object of this model
363
376
  */
package/client/World.js CHANGED
@@ -1,14 +1,14 @@
1
1
  import { Model, Prop } from './';
2
2
  import { Blip } from './Blip';
3
3
  import { Camera } from './Camera';
4
- import { CameraTypes, CloudHat, Weather, } from './enums';
4
+ import { CameraTypes, CloudHat, IntersectFlags, SHAPE_TEST_DEFAULT, Weather, } from './enums';
5
5
  import { GameplayCamera } from './GameplayCamera';
6
6
  import { VehicleHash } from './hashes';
7
7
  import { Ped, Vehicle } from './models';
8
8
  import { Pickup } from './Pickup';
9
- import { RaycastResult } from './Raycast';
9
+ import { AsynchronousRaycastResult, SynchronousRaycastResult } from './Raycast';
10
10
  import { Rope } from './Rope';
11
- import { Maths, Vector3, Wait } from './utils';
11
+ import { Maths, Wait } from './utils';
12
12
  /**
13
13
  * Class with common world manipulations.
14
14
  *
@@ -570,32 +570,47 @@ export class World {
570
570
  static drawPoly(vertexA, vertexB, vertexC, color) {
571
571
  DrawPoly(vertexA.x, vertexA.y, vertexA.z, vertexB.x, vertexB.y, vertexB.z, vertexC.x, vertexC.y, vertexC.z, color.r, color.g, color.b, color.a);
572
572
  }
573
+ // TODO: Add a raycast option for every type.
573
574
  /**
574
- * Cast ("shoot") a ray in a certain direction to detect entities in the way.
575
+ * Cast a ray from {@param start} to {@param end}.
575
576
  *
576
- * @param source Starting position of raycast.
577
- * @param direction Direction to cast a ray to.
578
- * @param maxDistance Max distance to cast the ray.
577
+ * @param start Starting position of raycast.
578
+ * @param end Direction to cast a ray to.
579
+ * @param losFlags The entity type(s) that the raycast should intersect with
580
+ * defaults to {@enum IntersectFlags.All}
579
581
  * @param options Possible entity types to detect.
580
582
  * @param ignoreEntity An entity to ignore (usually player's Ped).
581
- * @returns RaycastResult object.
583
+ * @returns {@see SynchronousRaycastResult} object.
582
584
  */
583
- static raycast(source, direction, maxDistance, options, ignoreEntity) {
584
- const target = Vector3.add(source, Vector3.multiply(direction, maxDistance));
585
- return new RaycastResult(StartExpensiveSynchronousShapeTestLosProbe(source.x, source.y, source.z, target.x, target.y, target.z, Number(options), ignoreEntity.Handle, 7));
585
+ static expensiveRaycast(start, end, losFlags = IntersectFlags.All, shapeTestOptions = SHAPE_TEST_DEFAULT, ignoreEntity) {
586
+ return new SynchronousRaycastResult(StartExpensiveSynchronousShapeTestLosProbe(start.x, start.y, start.z, end.x, end.y, end.z, losFlags, ignoreEntity?.Handle ?? 0, shapeTestOptions));
587
+ }
588
+ /**
589
+ * Cast a ray from {@param start} to {@param end} and returns the first hit
590
+ * entity or coordinate .
591
+ *
592
+ * @param start starting position of raycast.
593
+ * @param end the ending position to raycast to.
594
+ * @param losFlags The entity type(s) that the raycast should intersect with defaults to {@enum IntersectFlags.All}
595
+ * @param shapeTestOptions shape test collision modifiers defaults to ignoring glass, see through, and no collided entities
596
+ * @param ignoreEntity An entity to ignore (usually player's Ped).
597
+ * @returns {@see AsynchronousRaycastResult} object that must be awaited to get its results.
598
+ */
599
+ static raycast(start, end, losFlags = IntersectFlags.All, shapeTestOptions = SHAPE_TEST_DEFAULT, ignoreEntity) {
600
+ return new AsynchronousRaycastResult(StartShapeTestLosProbe(start.x, start.y, start.z, end.x, end.y, end.z, losFlags, ignoreEntity?.Handle ?? 0, shapeTestOptions));
586
601
  }
587
602
  /**
588
603
  * Cast a ray from the local players camera until it hits an entity
589
604
  *
590
605
  * @param maxDistance Max distance to cast the ray.
591
- * @param options Possible entity types to detect.
592
- * @returns RaycastResult object.
606
+ * @param flags Possible entity types to detect.
607
+ * @returns SynchronousRaycast object.
593
608
  */
594
- static raycastPlayerCamera(maxDistance, options) {
609
+ static raycastPlayerCamera(maxDistance, flags) {
595
610
  const camera = GameplayCamera.Position;
596
611
  const direction = GameplayCamera.ForwardVector;
597
612
  const destination = direction.multiply(maxDistance).add(camera);
598
- return new RaycastResult(StartExpensiveSynchronousShapeTestLosProbe(camera.x, camera.y, camera.z, destination.x, destination.y, destination.z, Number(options), PlayerPedId(), 7));
613
+ return new SynchronousRaycastResult(StartExpensiveSynchronousShapeTestLosProbe(camera.x, camera.y, camera.z, destination.x, destination.y, destination.z, flags, PlayerPedId(), 7));
599
614
  }
600
615
  /**
601
616
  * Gets the closest object of this model
@@ -0,0 +1,27 @@
1
+ /**
2
+ * List of possible entity intersections. Used for raycasting.
3
+ */
4
+ export declare enum IntersectFlags {
5
+ None = 0,
6
+ World = 1,
7
+ Vehicles = 2,
8
+ Ped = 4,
9
+ Ragdoll = 8,
10
+ Object = 16,
11
+ Pickup = 32,
12
+ River = 128,
13
+ Foliage = 256,
14
+ All = 511
15
+ }
16
+ export declare enum ShapeTestOptions {
17
+ None = 0,
18
+ IgnoreGlass = 1,
19
+ IgnoreSeeThrough = 2,
20
+ IgnoreNoCollision = 4
21
+ }
22
+ export declare enum ShapeTestStatus {
23
+ Discarded = 0,
24
+ NotReady = 1,
25
+ Ready = 2
26
+ }
27
+ export declare const SHAPE_TEST_DEFAULT: number;
@@ -0,0 +1,30 @@
1
+ /**
2
+ * List of possible entity intersections. Used for raycasting.
3
+ */
4
+ export var IntersectFlags;
5
+ (function (IntersectFlags) {
6
+ IntersectFlags[IntersectFlags["None"] = 0] = "None";
7
+ IntersectFlags[IntersectFlags["World"] = 1] = "World";
8
+ IntersectFlags[IntersectFlags["Vehicles"] = 2] = "Vehicles";
9
+ IntersectFlags[IntersectFlags["Ped"] = 4] = "Ped";
10
+ IntersectFlags[IntersectFlags["Ragdoll"] = 8] = "Ragdoll";
11
+ IntersectFlags[IntersectFlags["Object"] = 16] = "Object";
12
+ IntersectFlags[IntersectFlags["Pickup"] = 32] = "Pickup";
13
+ IntersectFlags[IntersectFlags["River"] = 128] = "River";
14
+ IntersectFlags[IntersectFlags["Foliage"] = 256] = "Foliage";
15
+ IntersectFlags[IntersectFlags["All"] = 511] = "All";
16
+ })(IntersectFlags || (IntersectFlags = {}));
17
+ export var ShapeTestOptions;
18
+ (function (ShapeTestOptions) {
19
+ ShapeTestOptions[ShapeTestOptions["None"] = 0] = "None";
20
+ ShapeTestOptions[ShapeTestOptions["IgnoreGlass"] = 1] = "IgnoreGlass";
21
+ ShapeTestOptions[ShapeTestOptions["IgnoreSeeThrough"] = 2] = "IgnoreSeeThrough";
22
+ ShapeTestOptions[ShapeTestOptions["IgnoreNoCollision"] = 4] = "IgnoreNoCollision";
23
+ })(ShapeTestOptions || (ShapeTestOptions = {}));
24
+ export var ShapeTestStatus;
25
+ (function (ShapeTestStatus) {
26
+ ShapeTestStatus[ShapeTestStatus["Discarded"] = 0] = "Discarded";
27
+ ShapeTestStatus[ShapeTestStatus["NotReady"] = 1] = "NotReady";
28
+ ShapeTestStatus[ShapeTestStatus["Ready"] = 2] = "Ready";
29
+ })(ShapeTestStatus || (ShapeTestStatus = {}));
30
+ export const SHAPE_TEST_DEFAULT = ShapeTestOptions.IgnoreGlass | ShapeTestOptions.IgnoreSeeThrough | ShapeTestOptions.IgnoreNoCollision;
@@ -20,7 +20,7 @@ export { HelmetType } from './HelmetType';
20
20
  export { HudColor } from './HudColor';
21
21
  export { HudComponent } from './HudComponent';
22
22
  export { InputMode } from './InputMode';
23
- export { IntersectOptions } from './IntersectOptions';
23
+ export { IntersectFlags, ShapeTestOptions, SHAPE_TEST_DEFAULT } from './RaycastEnums';
24
24
  export { InvertAxis, InvertAxisFlags } from './InvertAxis';
25
25
  export { Language } from './Language';
26
26
  export { LeaveVehicleFlags } from './LeaveVehicleFlags';
@@ -20,7 +20,7 @@ export { HelmetType } from './HelmetType';
20
20
  export { HudColor } from './HudColor';
21
21
  export { HudComponent } from './HudComponent';
22
22
  export { InputMode } from './InputMode';
23
- export { IntersectOptions } from './IntersectOptions';
23
+ export { IntersectFlags, ShapeTestOptions, SHAPE_TEST_DEFAULT } from './RaycastEnums';
24
24
  export { InvertAxisFlags } from './InvertAxis';
25
25
  export { Language } from './Language';
26
26
  export { LeaveVehicleFlags } from './LeaveVehicleFlags';
package/client/index.d.ts CHANGED
@@ -10,7 +10,7 @@ export { GameplayCamera } from './GameplayCamera';
10
10
  export { ParticleEffect } from './ParticleEffect';
11
11
  export { ParticleEffectAsset } from './ParticleEffectAsset';
12
12
  export { Pickup } from './Pickup';
13
- export { RaycastResult } from './Raycast';
13
+ export { AsynchronousRaycastResult, SynchronousRaycastResult } from './Raycast';
14
14
  export { RelationshipGroup } from './RelationshipGroup';
15
15
  export { Tasks } from './Tasks';
16
16
  export { TaskSequence } from './TaskSequence';
package/client/index.js CHANGED
@@ -10,7 +10,7 @@ export { GameplayCamera } from './GameplayCamera';
10
10
  export { ParticleEffect } from './ParticleEffect';
11
11
  export { ParticleEffectAsset } from './ParticleEffectAsset';
12
12
  export { Pickup } from './Pickup';
13
- export { RaycastResult } from './Raycast';
13
+ export { AsynchronousRaycastResult, SynchronousRaycastResult } from './Raycast';
14
14
  export { RelationshipGroup } from './RelationshipGroup';
15
15
  export { Tasks } from './Tasks';
16
16
  export { TaskSequence } from './TaskSequence';
@@ -132,19 +132,11 @@ export declare class BaseEntity {
132
132
  isNearEntity(entity: BaseEntity, bounds: Vector3): boolean;
133
133
  isTouching(entity: BaseEntity): boolean;
134
134
  isTouchingModel(model: Model): boolean;
135
- /**
136
- * @deprecated use [[getAbsolutePositionOffset]]
137
- */
138
- getOffsetPosition(offset: Vector3): Vector3;
139
135
  /**
140
136
  * @param offset: the amount to offset from the entity
141
137
  * @returns the offset position from the entity in world coords
142
138
  */
143
- getAbsolutePositionOffset(offset: Vector3): Vector3;
144
- /**
145
- * @deprecated use [[getRelativePositionOffset]] instead
146
- */
147
- getPositionOffset(worldCoords: Vector3): Vector3;
139
+ getAbsolutePositionOffset(worldCoords: Vector3): Vector3;
148
140
  /**
149
141
  * @example
150
142
  * ```typescript
@@ -161,7 +153,15 @@ export declare class BaseEntity {
161
153
  * @param worldCoords: the offset given the world coords
162
154
  * @returns the offset position from the entity in relative coords
163
155
  */
164
- getRelativePositionOffset(worldCoords: Vector3): Vector3;
156
+ getRelativePositionOffset(offset: Vector3): Vector3;
157
+ /**
158
+ * @deprecated use [[getAbsolutePositionOffset]] instead
159
+ */
160
+ getPositionOffset(worldCoords: Vector3): Vector3;
161
+ /**
162
+ * @deprecated use [[getRelativePositionOffset]]
163
+ */
164
+ getOffsetPosition(offset: Vector3): Vector3;
165
165
  attachTo(entity: BaseEntity, position: Vector3, rotation: Vector3, collisions?: boolean, unk9?: boolean, useSoftPinning?: boolean, rotationOrder?: number): void;
166
166
  attachToBone(entityBone: EntityBone, position: Vector3, rotation: Vector3, collisions?: boolean, unk9?: boolean, useSoftPinning?: boolean, rotationOrder?: number): void;
167
167
  detach(): void;
@@ -362,24 +362,12 @@ export class BaseEntity {
362
362
  isTouchingModel(model) {
363
363
  return IsEntityTouchingModel(this.handle, model.Hash);
364
364
  }
365
- /**
366
- * @deprecated use [[getAbsolutePositionOffset]]
367
- */
368
- getOffsetPosition(offset) {
369
- return Vector3.fromArray(GetOffsetFromEntityInWorldCoords(this.handle, offset.x, offset.y, offset.z));
370
- }
371
365
  /**
372
366
  * @param offset: the amount to offset from the entity
373
367
  * @returns the offset position from the entity in world coords
374
368
  */
375
- getAbsolutePositionOffset(offset) {
376
- return Vector3.fromArray(GetOffsetFromEntityInWorldCoords(this.handle, offset.x, offset.y, offset.z));
377
- }
378
- /**
379
- * @deprecated use [[getRelativePositionOffset]] instead
380
- */
381
- getPositionOffset(worldCoords) {
382
- return this.getRelativePositionOffset(worldCoords);
369
+ getAbsolutePositionOffset(worldCoords) {
370
+ return Vector3.fromArray(GetOffsetFromEntityGivenWorldCoords(this.handle, worldCoords.x, worldCoords.y, worldCoords.z));
383
371
  }
384
372
  // TODO: Better example
385
373
  /**
@@ -398,8 +386,20 @@ export class BaseEntity {
398
386
  * @param worldCoords: the offset given the world coords
399
387
  * @returns the offset position from the entity in relative coords
400
388
  */
401
- getRelativePositionOffset(worldCoords) {
402
- return Vector3.fromArray(GetOffsetFromEntityGivenWorldCoords(this.handle, worldCoords.x, worldCoords.y, worldCoords.z));
389
+ getRelativePositionOffset(offset) {
390
+ return Vector3.fromArray(GetOffsetFromEntityInWorldCoords(this.handle, offset.x, offset.y, offset.z));
391
+ }
392
+ /**
393
+ * @deprecated use [[getAbsolutePositionOffset]] instead
394
+ */
395
+ getPositionOffset(worldCoords) {
396
+ return this.getAbsolutePositionOffset(worldCoords);
397
+ }
398
+ /**
399
+ * @deprecated use [[getRelativePositionOffset]]
400
+ */
401
+ getOffsetPosition(offset) {
402
+ return this.getRelativePositionOffset(offset);
403
403
  }
404
404
  attachTo(entity, position, rotation, collisions = false, unk9 = true, useSoftPinning = true, rotationOrder = 1) {
405
405
  if (this.handle == entity.Handle) {
@@ -2,8 +2,6 @@ import { EntityBone } from './';
2
2
  import type { BaseEntity } from './BaseEntity';
3
3
  export declare class EntityBoneCollection {
4
4
  protected readonly owner: BaseEntity;
5
- private readonly _collection;
6
- private _currentIndex;
7
5
  constructor(owner: BaseEntity);
8
6
  hasBone(name: string): boolean;
9
7
  getBone(boneIndex?: number, boneName?: string): EntityBone;
@@ -1,7 +1,6 @@
1
1
  import { EntityBone } from './';
2
2
  export class EntityBoneCollection {
3
3
  constructor(owner) {
4
- this._currentIndex = -1;
5
4
  this.owner = owner;
6
5
  }
7
6
  hasBone(name) {
@@ -9,11 +9,11 @@ import { BaseEntity } from './BaseEntity';
9
9
  export declare class Ped extends BaseEntity {
10
10
  static exists(ped: Ped): boolean;
11
11
  static fromHandle(handle: number): Ped | null;
12
- static fromNetworkId(networkId: number, errorOnInvalid?: boolean): Ped | null;
12
+ static fromNetworkId(networkId: number): Ped | null;
13
13
  protected type: ClassTypes;
14
- private pedBones;
15
- private weapons;
16
- private readonly speechModifierNames;
14
+ private pedBones?;
15
+ private weapons?;
16
+ private static readonly speechModifierNames;
17
17
  private tasks;
18
18
  constructor(handle: number);
19
19
  get Player(): Player;
@@ -107,7 +107,7 @@ export declare class Ped extends BaseEntity {
107
107
  set DrivingStyle(style: DrivingStyle);
108
108
  set IsDrunk(isDrunk: boolean);
109
109
  set MotionBlur(value: boolean);
110
- get Task(): Tasks | undefined;
110
+ get Task(): Tasks;
111
111
  get DeathCause(): number;
112
112
  get TaskSequenceProgress(): number;
113
113
  set BlockPermanentEvents(block: boolean);
@@ -157,7 +157,7 @@ export declare class Ped extends BaseEntity {
157
157
  setConfigFlag(flagId: number, value: boolean): void;
158
158
  resetConfigFlag(flagId: number): void;
159
159
  clone(): Ped;
160
- exists(ped?: Ped): boolean;
160
+ exists(): boolean;
161
161
  isFacingPed(ped: Ped, angle?: number): boolean;
162
162
  setComponentVariation(componentId: number, drawableId: number, textureId: number, paletteId?: number): void;
163
163
  setRandomComponentVariation(): void;
@@ -12,54 +12,15 @@ export class Ped extends BaseEntity {
12
12
  static fromHandle(handle) {
13
13
  return new Ped(handle);
14
14
  }
15
- static fromNetworkId(networkId, errorOnInvalid = false) {
16
- if (errorOnInvalid && NetworkDoesEntityExistWithNetworkId(networkId)) {
17
- throw new Error(`Entity with ${networkId} doesn't exist`);
15
+ static fromNetworkId(networkId) {
16
+ if (!NetworkDoesEntityExistWithNetworkId(networkId)) {
17
+ return null;
18
18
  }
19
19
  return new Ped(NetworkGetEntityFromNetworkId(networkId));
20
20
  }
21
21
  constructor(handle) {
22
22
  super(handle);
23
23
  this.type = ClassTypes.Ped;
24
- this.speechModifierNames = [
25
- 'SPEECH_PARAMS_STANDARD',
26
- 'SPEECH_PARAMS_ALLOW_REPEAT',
27
- 'SPEECH_PARAMS_BEAT',
28
- 'SPEECH_PARAMS_FORCE',
29
- 'SPEECH_PARAMS_FORCE_FRONTEND',
30
- 'SPEECH_PARAMS_FORCE_NO_REPEAT_FRONTEND',
31
- 'SPEECH_PARAMS_FORCE_NORMAL',
32
- 'SPEECH_PARAMS_FORCE_NORMAL_CLEAR',
33
- 'SPEECH_PARAMS_FORCE_NORMAL_CRITICAL',
34
- 'SPEECH_PARAMS_FORCE_SHOUTED',
35
- 'SPEECH_PARAMS_FORCE_SHOUTED_CLEAR',
36
- 'SPEECH_PARAMS_FORCE_SHOUTED_CRITICAL',
37
- 'SPEECH_PARAMS_FORCE_PRELOAD_ONLY',
38
- 'SPEECH_PARAMS_MEGAPHONE',
39
- 'SPEECH_PARAMS_HELI',
40
- 'SPEECH_PARAMS_FORCE_MEGAPHONE',
41
- 'SPEECH_PARAMS_FORCE_HELI',
42
- 'SPEECH_PARAMS_INTERRUPT',
43
- 'SPEECH_PARAMS_INTERRUPT_SHOUTED',
44
- 'SPEECH_PARAMS_INTERRUPT_SHOUTED_CLEAR',
45
- 'SPEECH_PARAMS_INTERRUPT_SHOUTED_CRITICAL',
46
- 'SPEECH_PARAMS_INTERRUPT_NO_FORCE',
47
- 'SPEECH_PARAMS_INTERRUPT_FRONTEND',
48
- 'SPEECH_PARAMS_INTERRUPT_NO_FORCE_FRONTEND',
49
- 'SPEECH_PARAMS_ADD_BLIP',
50
- 'SPEECH_PARAMS_ADD_BLIP_ALLOW_REPEAT',
51
- 'SPEECH_PARAMS_ADD_BLIP_FORCE',
52
- 'SPEECH_PARAMS_ADD_BLIP_SHOUTED',
53
- 'SPEECH_PARAMS_ADD_BLIP_SHOUTED_FORCE',
54
- 'SPEECH_PARAMS_ADD_BLIP_INTERRUPT',
55
- 'SPEECH_PARAMS_ADD_BLIP_INTERRUPT_FORCE',
56
- 'SPEECH_PARAMS_FORCE_PRELOAD_ONLY_SHOUTED',
57
- 'SPEECH_PARAMS_FORCE_PRELOAD_ONLY_SHOUTED_CLEAR',
58
- 'SPEECH_PARAMS_FORCE_PRELOAD_ONLY_SHOUTED_CRITICAL',
59
- 'SPEECH_PARAMS_SHOUTED',
60
- 'SPEECH_PARAMS_SHOUTED_CLEAR',
61
- 'SPEECH_PARAMS_SHOUTED_CRITICAL',
62
- ];
63
24
  }
64
25
  get Player() {
65
26
  return new Player(NetworkGetPlayerIndexFromPed(this.handle));
@@ -441,12 +402,12 @@ export class Ped extends BaseEntity {
441
402
  RemovePedFromGroup(this.handle);
442
403
  }
443
404
  playAmbientSpeed(speechName, voiceName = '', modifier = SpeechModifier.Standard) {
444
- if (Number(modifier) >= 0 && Number(modifier) < this.speechModifierNames.length) {
405
+ if (Number(modifier) >= 0 && Number(modifier) < Ped.speechModifierNames.length) {
445
406
  if (voiceName === '') {
446
- PlayAmbientSpeech1(this.handle, speechName, this.speechModifierNames[Number(modifier)]);
407
+ PlayAmbientSpeech1(this.handle, speechName, Ped.speechModifierNames[Number(modifier)]);
447
408
  }
448
409
  else {
449
- PlayAmbientSpeechWithVoice(this.handle, speechName, voiceName, this.speechModifierNames[Number(modifier)], false);
410
+ PlayAmbientSpeechWithVoice(this.handle, speechName, voiceName, Ped.speechModifierNames[Number(modifier)], false);
450
411
  }
451
412
  }
452
413
  else {
@@ -533,11 +494,8 @@ export class Ped extends BaseEntity {
533
494
  clone() {
534
495
  return new Ped(ClonePed(this.handle, false, false, false));
535
496
  }
536
- exists(ped) {
537
- if (!ped) {
538
- return super.exists() && GetEntityType(this.handle) === 1;
539
- }
540
- return ped?.exists() ?? false;
497
+ exists() {
498
+ return super.exists() && GetEntityType(this.handle) === 1;
541
499
  }
542
500
  isFacingPed(ped, angle = 25.0) {
543
501
  return IsPedFacingPed(this.handle, ped.Handle, angle);
@@ -683,3 +641,42 @@ export class Ped extends BaseEntity {
683
641
  return HasPedHeadBlendFinished(this.handle);
684
642
  }
685
643
  }
644
+ Ped.speechModifierNames = [
645
+ 'SPEECH_PARAMS_STANDARD',
646
+ 'SPEECH_PARAMS_ALLOW_REPEAT',
647
+ 'SPEECH_PARAMS_BEAT',
648
+ 'SPEECH_PARAMS_FORCE',
649
+ 'SPEECH_PARAMS_FORCE_FRONTEND',
650
+ 'SPEECH_PARAMS_FORCE_NO_REPEAT_FRONTEND',
651
+ 'SPEECH_PARAMS_FORCE_NORMAL',
652
+ 'SPEECH_PARAMS_FORCE_NORMAL_CLEAR',
653
+ 'SPEECH_PARAMS_FORCE_NORMAL_CRITICAL',
654
+ 'SPEECH_PARAMS_FORCE_SHOUTED',
655
+ 'SPEECH_PARAMS_FORCE_SHOUTED_CLEAR',
656
+ 'SPEECH_PARAMS_FORCE_SHOUTED_CRITICAL',
657
+ 'SPEECH_PARAMS_FORCE_PRELOAD_ONLY',
658
+ 'SPEECH_PARAMS_MEGAPHONE',
659
+ 'SPEECH_PARAMS_HELI',
660
+ 'SPEECH_PARAMS_FORCE_MEGAPHONE',
661
+ 'SPEECH_PARAMS_FORCE_HELI',
662
+ 'SPEECH_PARAMS_INTERRUPT',
663
+ 'SPEECH_PARAMS_INTERRUPT_SHOUTED',
664
+ 'SPEECH_PARAMS_INTERRUPT_SHOUTED_CLEAR',
665
+ 'SPEECH_PARAMS_INTERRUPT_SHOUTED_CRITICAL',
666
+ 'SPEECH_PARAMS_INTERRUPT_NO_FORCE',
667
+ 'SPEECH_PARAMS_INTERRUPT_FRONTEND',
668
+ 'SPEECH_PARAMS_INTERRUPT_NO_FORCE_FRONTEND',
669
+ 'SPEECH_PARAMS_ADD_BLIP',
670
+ 'SPEECH_PARAMS_ADD_BLIP_ALLOW_REPEAT',
671
+ 'SPEECH_PARAMS_ADD_BLIP_FORCE',
672
+ 'SPEECH_PARAMS_ADD_BLIP_SHOUTED',
673
+ 'SPEECH_PARAMS_ADD_BLIP_SHOUTED_FORCE',
674
+ 'SPEECH_PARAMS_ADD_BLIP_INTERRUPT',
675
+ 'SPEECH_PARAMS_ADD_BLIP_INTERRUPT_FORCE',
676
+ 'SPEECH_PARAMS_FORCE_PRELOAD_ONLY_SHOUTED',
677
+ 'SPEECH_PARAMS_FORCE_PRELOAD_ONLY_SHOUTED_CLEAR',
678
+ 'SPEECH_PARAMS_FORCE_PRELOAD_ONLY_SHOUTED_CRITICAL',
679
+ 'SPEECH_PARAMS_SHOUTED',
680
+ 'SPEECH_PARAMS_SHOUTED_CLEAR',
681
+ 'SPEECH_PARAMS_SHOUTED_CRITICAL',
682
+ ];
@@ -3,7 +3,7 @@ import { StateBagChangeHandler } from '../cfx';
3
3
  import { BaseEntity, Ped } from './';
4
4
  export declare class Player {
5
5
  private handle;
6
- private ped;
6
+ private ped?;
7
7
  private pvp;
8
8
  private stateBagCookies;
9
9
  private source;
@@ -3,7 +3,7 @@ import { BaseEntity } from './BaseEntity';
3
3
  export declare class Prop extends BaseEntity {
4
4
  static exists(prop: Prop): boolean;
5
5
  static fromHandle(handle: number): Prop | null;
6
- static fromNetworkId(networkId: number, errorOnInvalid?: boolean): Prop | null;
6
+ static fromNetworkId(networkId: number): Prop | null;
7
7
  protected type: ClassTypes;
8
8
  constructor(handle: number);
9
9
  exists(): boolean;
@@ -7,9 +7,9 @@ export class Prop extends BaseEntity {
7
7
  static fromHandle(handle) {
8
8
  return new Prop(handle);
9
9
  }
10
- static fromNetworkId(networkId, errorOnInvalid = false) {
11
- if (errorOnInvalid && NetworkDoesEntityExistWithNetworkId(networkId)) {
12
- throw new Error(`Entity with ${networkId} doesn't exist`);
10
+ static fromNetworkId(networkId) {
11
+ if (!NetworkDoesEntityExistWithNetworkId(networkId)) {
12
+ return null;
13
13
  }
14
14
  return new Prop(NetworkGetEntityFromNetworkId(networkId));
15
15
  }
@@ -11,10 +11,10 @@ export declare class Vehicle extends BaseEntity {
11
11
  static exists(vehicle: Vehicle): boolean;
12
12
  static fromHandle(handle: number): Vehicle | null;
13
13
  static fromNetworkId(networkId: number): Vehicle | null;
14
- private _doors;
15
- private _mods;
16
- private _wheels;
17
- private _windows;
14
+ private _doors?;
15
+ private _mods?;
16
+ private _wheels?;
17
+ private _windows?;
18
18
  protected type: ClassTypes;
19
19
  constructor(handle: number);
20
20
  exists(): boolean;
@@ -16,7 +16,7 @@ export declare class VehicleModCollection {
16
16
  set WheelType(type: VehicleWheelType);
17
17
  installModKit(): void;
18
18
  get Livery(): number | undefined;
19
- set Livery(value: number | undefined);
19
+ set Livery(value: number);
20
20
  get LiveryCount(): number;
21
21
  get WindowTint(): VehicleWindowTint;
22
22
  set WindowTint(tint: VehicleWindowTint);
@@ -44,6 +44,7 @@ export class VehicleModCollection {
44
44
  installModKit() {
45
45
  SetVehicleModKit(this._owner.Handle, 0);
46
46
  }
47
+ // TODO: This should return always return a number
47
48
  get Livery() {
48
49
  const modCount = this.getMod(VehicleModType.Livery)?.ModCount;
49
50
  if (modCount !== undefined && modCount > 0) {
@@ -52,8 +53,6 @@ export class VehicleModCollection {
52
53
  return GetVehicleLivery(this._owner.Handle);
53
54
  }
54
55
  set Livery(value) {
55
- if (value === undefined)
56
- return;
57
56
  const mod = this.getMod(VehicleModType.Livery);
58
57
  if (mod !== undefined && mod.ModCount > 0) {
59
58
  mod.Index = value;
@@ -5,8 +5,8 @@ export declare class VehicleWindowCollection {
5
5
  private _owner;
6
6
  private readonly _vehicleWindows;
7
7
  constructor(owner: Vehicle);
8
- getWindow(index: VehicleWindowIndex): VehicleWindow | undefined;
9
- getAllWindows(): (VehicleWindow | null | undefined)[];
8
+ getWindow(index: VehicleWindowIndex): VehicleWindow;
9
+ getAllWindows(): (VehicleWindow | null)[];
10
10
  get AreAllWindowsIntact(): boolean;
11
11
  rollDownAllWindows(): void;
12
12
  rollUpAllWindows(): void;
@@ -6,10 +6,13 @@ export class VehicleWindowCollection {
6
6
  this._owner = owner;
7
7
  }
8
8
  getWindow(index) {
9
- if (!this._vehicleWindows.has(index)) {
10
- this._vehicleWindows.set(index, new VehicleWindow(this._owner, index));
9
+ let window = this._vehicleWindows.get(index);
10
+ if (!window) {
11
+ const vehicleWindow = new VehicleWindow(this._owner, index);
12
+ this._vehicleWindows.set(index, vehicleWindow);
13
+ return vehicleWindow;
11
14
  }
12
- return this._vehicleWindows.get(index);
15
+ return window;
13
16
  }
14
17
  getAllWindows() {
15
18
  return Object.keys(VehicleWindowIndex)
@@ -37,8 +40,6 @@ export class VehicleWindowCollection {
37
40
  });
38
41
  }
39
42
  hasWindow(window) {
40
- if (this._owner.Bones === undefined)
41
- return false;
42
43
  switch (window) {
43
44
  case VehicleWindowIndex.FrontLeftWindow:
44
45
  return this._owner.Bones.hasBone('window_lf');
@@ -9,8 +9,8 @@ export declare class Menu {
9
9
  static screenResolution: Size;
10
10
  readonly id: string;
11
11
  visible: boolean;
12
- parentMenu: Menu | undefined;
13
- parentItem: UIMenuItem | undefined;
12
+ parentMenu?: Menu;
13
+ parentItem?: UIMenuItem;
14
14
  items: UIMenuItem[];
15
15
  children: Map<string, Menu>;
16
16
  readonly menuOpen: LiteEvent;
@@ -18,7 +18,7 @@ export declare class UIMenuItem {
18
18
  selected: boolean;
19
19
  hovered: boolean;
20
20
  offset: Point;
21
- parent: Menu | undefined;
21
+ parent?: Menu;
22
22
  readonly activated: LiteEvent;
23
23
  readonly panelActivated: LiteEvent;
24
24
  protected supportsDescription: boolean;
@@ -3,9 +3,9 @@ import { Rectangle, Sprite } from '../../../';
3
3
  import { Menu } from '../../';
4
4
  export declare abstract class AbstractUIMenuPanel {
5
5
  readonly id: string;
6
- protected parentItem: UIMenuItem | undefined;
6
+ protected parentItem?: UIMenuItem;
7
7
  protected enabled: boolean;
8
- protected readonly background: Sprite | Rectangle | undefined;
8
+ protected readonly background?: Sprite | Rectangle;
9
9
  get ParentMenu(): Menu | undefined;
10
10
  get ParentItem(): UIMenuItem | undefined;
11
11
  set ParentItem(value: UIMenuItem | undefined);
@@ -10,7 +10,7 @@ export class AbstractUIMenuPanel {
10
10
  return this.parentItem ? this.parentItem.parent : undefined;
11
11
  }
12
12
  get ParentItem() {
13
- return this.parentItem ?? undefined;
13
+ return this.parentItem;
14
14
  }
15
15
  set ParentItem(value) {
16
16
  this.parentItem = value;
@@ -7,10 +7,10 @@ export declare class UIMenuGridPanel extends AbstractUIMenuPanel {
7
7
  private _pressed;
8
8
  private _lockXAxis;
9
9
  private _lockYAxis;
10
- private _topText;
11
- private _leftText;
12
- private _rightText;
13
- private _bottomText;
10
+ private _topText?;
11
+ private _leftText?;
12
+ private _rightText?;
13
+ private _bottomText?;
14
14
  private _lastCirclePosition;
15
15
  private readonly _grid;
16
16
  private readonly _circle;
@@ -55,9 +55,6 @@ export declare class Vector {
55
55
  y: number;
56
56
  z?: number | undefined;
57
57
  w?: number | undefined;
58
- /**
59
- * The type identifier for vectors.
60
- */
61
58
  type: ClassTypes;
62
59
  protected static create(x: number, y?: number): Vector2;
63
60
  protected static create(x: number, y?: number, z?: number): Vector3;
@@ -144,6 +141,35 @@ export declare class Vector {
144
141
  * @returns A new vector with divided components.
145
142
  */
146
143
  static divide<T extends VectorType, U extends VectorLike>(this: T, a: U, b: VectorLike | number): U;
144
+ /**
145
+ * Performs an operation between a vector and either another vector or scalar value converting the vector into absolute values.
146
+ * @param a - The first vector.
147
+ * @param b - The second vector or scalar value.
148
+ * @param operator - The function defining the operation to perform.
149
+ * @returns A new vector resulting from the operation.
150
+ */
151
+ private static operateAbsolute;
152
+ /**
153
+ * Subtracts one vector from another or subtracts a scalar value from a vector.
154
+ * @param a - The vector.
155
+ * @param b - The second vector or scalar value.
156
+ * @returns A new vector with subtracted components.
157
+ */
158
+ static subtractAbsolute<T extends VectorType, U extends VectorLike>(this: T, a: U, b: VectorLike | number): U;
159
+ /**
160
+ * Multiplies two vectors by their components, or multiplies a vector by a scalar value.
161
+ * @param a - The vector.
162
+ * @param b - The second vector or scalar value.
163
+ * @returns A new vector with multiplied components.
164
+ */
165
+ static multiplyAbsolute<T extends VectorType, U extends VectorLike>(this: T, a: U, b: VectorLike | number): U;
166
+ /**
167
+ * Divides two vectors by their components, or divides a vector by a scalar value
168
+ * @param a - The vector.
169
+ * @param b - The second vector or scalar vector.
170
+ * @returns A new vector with divided components.
171
+ */
172
+ static divideAbsolute<T extends VectorType, U extends VectorLike>(this: T, a: U, b: VectorLike | number): U;
147
173
  /**
148
174
  * Calculates the dot product of two vectors.
149
175
  * @param a - The first vector.
@@ -246,6 +272,18 @@ export declare class Vector {
246
272
  * @see Vector.divide
247
273
  */
248
274
  divide(v: VectorLike | number): this;
275
+ /**
276
+ * @see Vector.subtractAbsolute
277
+ */
278
+ subtractAbsolute(v: VectorLike): this;
279
+ /**
280
+ * @see Vector.multiply
281
+ */
282
+ multiplyAbsolute(v: VectorLike | number): this;
283
+ /**
284
+ * @see Vector.divide
285
+ */
286
+ divideAbsolute(v: VectorLike | number): this;
249
287
  /**
250
288
  * Converts the vector to an array of its components.
251
289
  */
@@ -296,6 +334,10 @@ export declare class Vector3 extends Vector implements Vec3 {
296
334
  * @see Vector.crossProduct
297
335
  */
298
336
  crossProduct(v: Vec3 | Vec4): Vec3 | Vec4;
337
+ /**
338
+ * @returns the x and y values as Vec2
339
+ */
340
+ toVec2(): Vector2;
299
341
  }
300
342
  /**
301
343
  * Represents a 4-dimensional vector.
@@ -325,5 +367,13 @@ export declare class Vector4 extends Vector {
325
367
  * @see Vector.crossProduct
326
368
  */
327
369
  crossProduct(v: Vec3 | Vec4): Vec3 | Vec4;
370
+ /**
371
+ * @returns the x and y values as Vec2
372
+ */
373
+ toVec2(): Vector2;
374
+ /**
375
+ * @returns the x and y values as Vec3
376
+ */
377
+ toVec3(): Vector3;
328
378
  }
329
379
  export {};
@@ -145,6 +145,51 @@ export class Vector {
145
145
  static divide(a, b) {
146
146
  return this.operate(a, b, (x, y) => x / y);
147
147
  }
148
+ /**
149
+ * Performs an operation between a vector and either another vector or scalar value converting the vector into absolute values.
150
+ * @param a - The first vector.
151
+ * @param b - The second vector or scalar value.
152
+ * @param operator - The function defining the operation to perform.
153
+ * @returns A new vector resulting from the operation.
154
+ */
155
+ static operateAbsolute(a, b, operator) {
156
+ let { x, y, z, w } = a;
157
+ const isNumber = typeof b === 'number';
158
+ x = operator(Math.abs(x), isNumber ? b : Math.abs(b.x ?? 0));
159
+ y = operator(Math.abs(y), isNumber ? b : Math.abs(b.y ?? 0));
160
+ if (z)
161
+ z = operator(Math.abs(z), isNumber ? b : Math.abs(b.z ?? 0));
162
+ if (w)
163
+ w = operator(Math.abs(w), isNumber ? b : Math.abs(b.w ?? 0));
164
+ return this.create(x, y, z, w);
165
+ }
166
+ /**
167
+ * Subtracts one vector from another or subtracts a scalar value from a vector.
168
+ * @param a - The vector.
169
+ * @param b - The second vector or scalar value.
170
+ * @returns A new vector with subtracted components.
171
+ */
172
+ static subtractAbsolute(a, b) {
173
+ return this.operateAbsolute(a, b, (x, y) => x - y);
174
+ }
175
+ /**
176
+ * Multiplies two vectors by their components, or multiplies a vector by a scalar value.
177
+ * @param a - The vector.
178
+ * @param b - The second vector or scalar value.
179
+ * @returns A new vector with multiplied components.
180
+ */
181
+ static multiplyAbsolute(a, b) {
182
+ return this.operateAbsolute(a, b, (x, y) => x * y);
183
+ }
184
+ /**
185
+ * Divides two vectors by their components, or divides a vector by a scalar value
186
+ * @param a - The vector.
187
+ * @param b - The second vector or scalar vector.
188
+ * @returns A new vector with divided components.
189
+ */
190
+ static divideAbsolute(a, b) {
191
+ return this.operateAbsolute(a, b, (x, y) => x / y);
192
+ }
148
193
  /**
149
194
  * Calculates the dot product of two vectors.
150
195
  * @param a - The first vector.
@@ -244,9 +289,8 @@ export class Vector {
244
289
  this.y = y;
245
290
  this.z = z;
246
291
  this.w = w;
247
- /**
248
- * The type identifier for vectors.
249
- */
292
+ // DO NOT USE, ONLY EXPOSED BECAUSE TS IS TRASH, THIS TYPE IS NOT GUARANTEED
293
+ // TO EXIST
250
294
  this.type = ClassTypes.Vector2;
251
295
  }
252
296
  *[Symbol.iterator]() {
@@ -333,6 +377,24 @@ export class Vector {
333
377
  divide(v) {
334
378
  return Vector.divide(this, v);
335
379
  }
380
+ /**
381
+ * @see Vector.subtractAbsolute
382
+ */
383
+ subtractAbsolute(v) {
384
+ return Vector.subtractAbsolute(this, v);
385
+ }
386
+ /**
387
+ * @see Vector.multiply
388
+ */
389
+ multiplyAbsolute(v) {
390
+ return Vector.multiplyAbsolute(this, v);
391
+ }
392
+ /**
393
+ * @see Vector.divide
394
+ */
395
+ divideAbsolute(v) {
396
+ return Vector.divideAbsolute(this, v);
397
+ }
336
398
  /**
337
399
  * Converts the vector to an array of its components.
338
400
  */
@@ -371,6 +433,8 @@ export class Vector2 extends Vector {
371
433
  */
372
434
  constructor(x, y = x) {
373
435
  super(2, x, y);
436
+ // DO NOT USE, ONLY EXPOSED BECAUSE TS IS TRASH, THIS TYPE IS NOT GUARANTEED
437
+ // TO EXIST, CHANGING IT WILL BREAK STUFF
374
438
  this.type = ClassTypes.Vector2;
375
439
  }
376
440
  }
@@ -387,6 +451,8 @@ export class Vector3 extends Vector {
387
451
  */
388
452
  constructor(x, y = x, z = y) {
389
453
  super(3, x, y, z);
454
+ // DO NOT USE, ONLY EXPOSED BECAUSE TS IS TRASH, THIS TYPE IS NOT GUARANTEED
455
+ // TO EXIST, CHANGING IT WILL BREAK STUFF
390
456
  this.type = ClassTypes.Vector3;
391
457
  this.z = z;
392
458
  }
@@ -402,6 +468,12 @@ export class Vector3 extends Vector {
402
468
  crossProduct(v) {
403
469
  return Vector.crossProduct(this, v);
404
470
  }
471
+ /**
472
+ * @returns the x and y values as Vec2
473
+ */
474
+ toVec2() {
475
+ return new Vector2(this.x, this.y);
476
+ }
405
477
  }
406
478
  Vector3.Zero = new Vector3(0, 0, 0);
407
479
  /**
@@ -417,6 +489,8 @@ export class Vector4 extends Vector {
417
489
  */
418
490
  constructor(x, y = x, z = y, w = z) {
419
491
  super(4, x, y, z, w);
492
+ // DO NOT USE, ONLY EXPOSED BECAUSE TS IS TRASH, THIS TYPE IS NOT GUARANTEED
493
+ // TO EXIST, CHANGING IT WILL BREAK STUFF
420
494
  this.type = ClassTypes.Vector4;
421
495
  this.z = z;
422
496
  this.w = w;
@@ -439,5 +513,17 @@ export class Vector4 extends Vector {
439
513
  crossProduct(v) {
440
514
  return Vector.crossProduct(this, v);
441
515
  }
516
+ /**
517
+ * @returns the x and y values as Vec2
518
+ */
519
+ toVec2() {
520
+ return new Vector2(this.x, this.y);
521
+ }
522
+ /**
523
+ * @returns the x and y values as Vec3
524
+ */
525
+ toVec3() {
526
+ return new Vector3(this.x, this.y, this.z);
527
+ }
442
528
  }
443
529
  Vector4.Zero = new Vector4(0, 0, 0, 0);
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.30",
7
+ "version": "0.0.32",
8
8
  "publishConfig": {
9
9
  "directory": "lib"
10
10
  },
@@ -1,15 +0,0 @@
1
- /**
2
- * List of possible entity intersections. Used for raycasting.
3
- */
4
- export declare enum IntersectOptions {
5
- Everything = -1,
6
- None = 0,
7
- World = 1,
8
- Vehicles = 2,
9
- PedsSimpleCollision = 4,
10
- Peds = 8,
11
- Objects = 16,
12
- Water = 32,
13
- Unk3 = 128,
14
- Foliage = 256
15
- }
@@ -1,16 +0,0 @@
1
- /**
2
- * List of possible entity intersections. Used for raycasting.
3
- */
4
- export var IntersectOptions;
5
- (function (IntersectOptions) {
6
- IntersectOptions[IntersectOptions["Everything"] = -1] = "Everything";
7
- IntersectOptions[IntersectOptions["None"] = 0] = "None";
8
- IntersectOptions[IntersectOptions["World"] = 1] = "World";
9
- IntersectOptions[IntersectOptions["Vehicles"] = 2] = "Vehicles";
10
- IntersectOptions[IntersectOptions["PedsSimpleCollision"] = 4] = "PedsSimpleCollision";
11
- IntersectOptions[IntersectOptions["Peds"] = 8] = "Peds";
12
- IntersectOptions[IntersectOptions["Objects"] = 16] = "Objects";
13
- IntersectOptions[IntersectOptions["Water"] = 32] = "Water";
14
- IntersectOptions[IntersectOptions["Unk3"] = 128] = "Unk3";
15
- IntersectOptions[IntersectOptions["Foliage"] = 256] = "Foliage";
16
- })(IntersectOptions || (IntersectOptions = {}));