@nativewrappers/redm 0.0.62 → 0.0.64

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.
@@ -2,10 +2,66 @@ import { Vector3 } from "../../common/utils";
2
2
  export declare class BaseEntity {
3
3
  private handle;
4
4
  constructor(entHandle: number);
5
+ /**
6
+ * Replaces the current handle for the entity used on, this hsould be used sparringly, mainly
7
+ * in situations where you're going to reuse an entity over and over and don't want to make a
8
+ * new entity every time.
9
+ *
10
+ * **WARNING**: This does no checks, if you provide it an invalid entity it will use it
11
+ *
12
+ * ```ts
13
+ * const REUSABLE_ENTITY = new Entity(entityHandle);
14
+ *
15
+ * onNet("entityHandler", (entNetId: number) => {
16
+ * // if no net entity we should ignore
17
+ * if (!NetworkDoesEntityExistWithNetworkId(entNetId)) return;
18
+ *
19
+ * // Reuse our entity so we don't have to initialize a new one
20
+ * REUSABLE_ENTITY.replaceHandle(NetworkGetEntityFromNetworkId(entNetId));
21
+ * // Do something with REUSABLE_ENTITY entity
22
+ * })
23
+ ```
24
+ */
5
25
  replaceHandle(newHandle: number): void;
26
+ /**
27
+ * @returns the network for the specified entity, this doesn't check if the entity is networked, you should use {@link BaseEntity.IsNetworked}
28
+ */
29
+ get NetworkId(): number;
30
+ /**
31
+ * @returns `true` if the current entity is networked, false otherwise
32
+ */
33
+ get IsNetworked(): boolean;
34
+ /**
35
+ * @returns Returns true if the entity handle is not 0 and exists in the game engine
36
+ */
37
+ get Exists(): boolean;
38
+ /**
39
+ * @returns The entitys current handle.
40
+ */
6
41
  get Handle(): number;
42
+ /**
43
+ * @param amount the health to set the health to, setting to `0` will kill the entity, if using on a {@link Ped} you should check the MaxHealth before setting.
44
+ */
7
45
  set Health(amount: number);
46
+ /**
47
+ * @returns the amount of health the current {@link BaseEntity} has
48
+ */
8
49
  get Health(): number;
50
+ /**
51
+ * @returns the heading of the current {@link BaseEntity}
52
+ */
53
+ get Heading(): number;
54
+ /**
55
+ * @param heading sets the entitys heading to the specified heading, this can be in the range of 0..360
56
+ */
57
+ set Heading(heading: number);
58
+ /**
59
+ * @returns the position of the current Entity
60
+ */
9
61
  get Position(): Vector3;
62
+ /**
63
+ * You should (almost) always try to load the collisions before setting the entitys position if going a long distance.
64
+ * @param pos sets the position for the current ped
65
+ */
10
66
  set Position(pos: Vector3);
11
67
  }
@@ -4,39 +4,87 @@ export class BaseEntity {
4
4
  constructor(entHandle) {
5
5
  this.handle = entHandle;
6
6
  }
7
- // Replaces the current handle for the entity used on, this hsould be used sparringly, mainly
8
- // in situations where you're going to reuse an entity over and over and don't want to make a
9
- // new entity every time.
10
- //
11
- // **WARNING**: This does no checks, if you provide it an invalid entity it will use it
12
- //
13
- // ```ts
14
- // const REUSABLE_ENTITY = new Entity(entityHandle);
15
- //
16
- // onNet("entityHandler", (entNetId: number) => {
17
- // // if no net entity we should ignore
18
- // if (!NetworkDoesEntityExistWithNetworkId(entNetId)) return;
19
- //
20
- // // Reuse our entity so we don't have to initialize a new one
21
- // REUSABLE_ENTITY.replaceHandle(NetworkGetEntityFromNetworkId(entNetId));
22
- // // Do something with REUSABLE_ENTITY entity
23
- // })
24
- // ```
7
+ /**
8
+ * Replaces the current handle for the entity used on, this hsould be used sparringly, mainly
9
+ * in situations where you're going to reuse an entity over and over and don't want to make a
10
+ * new entity every time.
11
+ *
12
+ * **WARNING**: This does no checks, if you provide it an invalid entity it will use it
13
+ *
14
+ * ```ts
15
+ * const REUSABLE_ENTITY = new Entity(entityHandle);
16
+ *
17
+ * onNet("entityHandler", (entNetId: number) => {
18
+ * // if no net entity we should ignore
19
+ * if (!NetworkDoesEntityExistWithNetworkId(entNetId)) return;
20
+ *
21
+ * // Reuse our entity so we don't have to initialize a new one
22
+ * REUSABLE_ENTITY.replaceHandle(NetworkGetEntityFromNetworkId(entNetId));
23
+ * // Do something with REUSABLE_ENTITY entity
24
+ * })
25
+ ```
26
+ */
25
27
  replaceHandle(newHandle) {
26
28
  this.handle = newHandle;
27
29
  }
30
+ /**
31
+ * @returns the network for the specified entity, this doesn't check if the entity is networked, you should use {@link BaseEntity.IsNetworked}
32
+ */
33
+ get NetworkId() {
34
+ return NetworkGetNetworkIdFromEntity(this.Handle);
35
+ }
36
+ /**
37
+ * @returns `true` if the current entity is networked, false otherwise
38
+ */
39
+ get IsNetworked() {
40
+ return NetworkGetEntityIsNetworked(this.Handle);
41
+ }
42
+ /**
43
+ * @returns Returns true if the entity handle is not 0 and exists in the game engine
44
+ */
45
+ get Exists() {
46
+ return this.handle !== 0 && DoesEntityExist(this.Handle);
47
+ }
48
+ /**
49
+ * @returns The entitys current handle.
50
+ */
28
51
  get Handle() {
29
52
  return this.handle;
30
53
  }
54
+ /**
55
+ * @param amount the health to set the health to, setting to `0` will kill the entity, if using on a {@link Ped} you should check the MaxHealth before setting.
56
+ */
31
57
  set Health(amount) {
32
58
  SetEntityHealth(this.Handle, amount, 0);
33
59
  }
60
+ /**
61
+ * @returns the amount of health the current {@link BaseEntity} has
62
+ */
34
63
  get Health() {
35
64
  return GetEntityHealth(this.Handle);
36
65
  }
66
+ /**
67
+ * @returns the heading of the current {@link BaseEntity}
68
+ */
69
+ get Heading() {
70
+ return GetEntityHeading(this.Handle);
71
+ }
72
+ /**
73
+ * @param heading sets the entitys heading to the specified heading, this can be in the range of 0..360
74
+ */
75
+ set Heading(heading) {
76
+ SetEntityHeading(this.Handle, heading);
77
+ }
78
+ /**
79
+ * @returns the position of the current Entity
80
+ */
37
81
  get Position() {
38
82
  return Vector3.fromArray(GetEntityCoords(this.handle, true, true));
39
83
  }
84
+ /**
85
+ * You should (almost) always try to load the collisions before setting the entitys position if going a long distance.
86
+ * @param pos sets the position for the current ped
87
+ */
40
88
  set Position(pos) {
41
89
  SetEntityCoords(this.handle, pos.x, pos.y, pos.z, false, false, false, false);
42
90
  }
@@ -2,6 +2,7 @@ import { EntityType, ForceType } from "../enums/Entity";
2
2
  import { _N } from "../utils";
3
3
  import { BaseEntity } from "./BaseEntity";
4
4
  export class Entity extends BaseEntity {
5
+ // NOTE: There is nothing stopping you from using creating an invalid entity, you should do your own due-diligence
5
6
  constructor(handle) {
6
7
  super(handle);
7
8
  }
package/entities/Ped.d.ts CHANGED
@@ -5,7 +5,6 @@ import { Vector3 } from "../utils";
5
5
  import { BaseEntity } from "./BaseEntity";
6
6
  import { Vehicle } from "./Vehicle";
7
7
  import { Player } from "./Player";
8
- export type OptionalPed = Ped | null;
9
8
  export declare class Ped extends BaseEntity {
10
9
  private attributes;
11
10
  constructor(handle: number);
@@ -39,8 +38,6 @@ export declare class Ped extends BaseEntity {
39
38
  get IsInjured(): boolean;
40
39
  get IsFatallyInjured(): boolean;
41
40
  get IsPlayer(): boolean;
42
- get Heading(): number;
43
- set Heading(heading: number);
44
41
  get IsShooting(): boolean;
45
42
  get Accuracy(): number;
46
43
  set Accuracy(accuracy: number);
@@ -48,19 +45,19 @@ export declare class Ped extends BaseEntity {
48
45
  get IsMale(): boolean;
49
46
  get IsHuman(): boolean;
50
47
  get IsOnTopOfVehicle(): boolean;
51
- get Vehicle(): Vehicle;
48
+ get Vehicle(): Vehicle | null;
52
49
  /**
53
50
  * @returns the last mount that this ped was on, or null if it doesn't exist
54
51
  */
55
- get Mount(): OptionalPed;
52
+ get Mount(): Ped | null;
56
53
  /**
57
54
  * returns the horse that this ped is leading
58
55
  */
59
- get LeadingHorse(): OptionalPed;
56
+ get LeadingHorse(): Ped | null;
60
57
  /**
61
58
  * returns the owner of the current animal
62
59
  */
63
- get Owner(): OptionalPed;
60
+ get Owner(): Ped | null;
64
61
  get TamingState(): TamingState;
65
62
  get IsInteractingWithAnimal(): boolean;
66
63
  get IsSittingInAnyVehicle(): boolean;
@@ -113,12 +110,6 @@ export declare class Ped extends BaseEntity {
113
110
  */
114
111
  setOntoMount(targetPed: Ped, seatIndex: VehicleSeat): void;
115
112
  removeFromMount(): void;
116
- /**
117
- *
118
- * @param seatIndex the seat index to check
119
- * @returns true of the specified seat is free on the mount
120
- */
121
- isSeatFree(seatIndex: VehicleSeat): boolean;
122
113
  /**
123
114
  * Sets the ped into the specified vehicle
124
115
  * @param vehicle the vehicle to put the ped into
@@ -157,7 +148,7 @@ export declare class Ped extends BaseEntity {
157
148
  * @param amount - the amount of armour to add to the ped
158
149
  */
159
150
  addArmour(amount: number): void;
160
- applyDamage(damageAmount: number, boneId?: number, pedKiller?: OptionalPed): void;
151
+ applyDamage(damageAmount: number, boneId?: number, pedKiller?: Ped | null): void;
161
152
  /**
162
153
  * @param damagePack - the damage decal to apply see [here](https://github.com/femga/rdr3_discoveries/blob/master/peds_customization/ped_decals.lua) for more documentation
163
154
  * @param damage - the damage to apply
package/entities/Ped.js CHANGED
@@ -57,12 +57,6 @@ export class Ped extends BaseEntity {
57
57
  get IsPlayer() {
58
58
  return IsPedAPlayer(this.Handle);
59
59
  }
60
- get Heading() {
61
- return GetEntityHeading(this.Handle);
62
- }
63
- set Heading(heading) {
64
- SetEntityHeading(this.Handle, heading);
65
- }
66
60
  get IsShooting() {
67
61
  return IsPedShooting(this.Handle);
68
62
  }
@@ -85,7 +79,11 @@ export class Ped extends BaseEntity {
85
79
  return IsPedOnVehicle(this.Handle, false);
86
80
  }
87
81
  get Vehicle() {
88
- return new Vehicle(GetVehiclePedIsIn(this.Handle, false));
82
+ const vehicle = GetVehiclePedIsIn(this.Handle, false);
83
+ if (vehicle === 0) {
84
+ return null;
85
+ }
86
+ return new Vehicle(vehicle);
89
87
  }
90
88
  /**
91
89
  * @returns the last mount that this ped was on, or null if it doesn't exist
@@ -194,7 +192,8 @@ export class Ped extends BaseEntity {
194
192
  return _N("0x6CFC373008A1EDAF", this.Handle, Citizen.resultAsInteger());
195
193
  }
196
194
  set IsDamaged(damaged) {
197
- _N("_SET_PED_DAMAGED", this.Handle, damaged);
195
+ // _SET_PED_DAMAGED
196
+ _N("0xDACE03C65C6666DB", this.Handle, damaged);
198
197
  }
199
198
  get DamageCleanliness() {
200
199
  return _N("0x88EFFED5FE8B0B4A", this.Handle, Citizen.resultAsInteger());
@@ -257,14 +256,6 @@ export class Ped extends BaseEntity {
257
256
  // REMOVE_PED_FROM_MOUNT
258
257
  _N("0x5337B721C51883A9", this.Handle, true, true);
259
258
  }
260
- /**
261
- *
262
- * @param seatIndex the seat index to check
263
- * @returns true of the specified seat is free on the mount
264
- */
265
- isSeatFree(seatIndex) {
266
- return _N("0xAAB0FE202E9FC9F0", this.Vehicle.Handle, seatIndex, Citizen.resultAsInteger());
267
- }
268
259
  /**
269
260
  * Sets the ped into the specified vehicle
270
261
  * @param vehicle the vehicle to put the ped into
@@ -1,4 +1,11 @@
1
+ import { VehicleSeat } from "../../redm/enums";
1
2
  import { BaseEntity } from "./BaseEntity";
2
3
  export declare class Vehicle extends BaseEntity {
3
4
  constructor(handle: number);
5
+ /**
6
+ *
7
+ * @param seatIndex the seat index to check
8
+ * @returns true of the specified seat is free on the mount
9
+ */
10
+ isSeatFree(seatIndex: VehicleSeat): boolean;
4
11
  }
@@ -1,6 +1,15 @@
1
1
  import { BaseEntity } from "./BaseEntity";
2
+ import { _N } from "../../redm/utils";
2
3
  export class Vehicle extends BaseEntity {
3
4
  constructor(handle) {
4
5
  super(handle);
5
6
  }
7
+ /**
8
+ *
9
+ * @param seatIndex the seat index to check
10
+ * @returns true of the specified seat is free on the mount
11
+ */
12
+ isSeatFree(seatIndex) {
13
+ return _N("0xAAB0FE202E9FC9F0", this.Handle, seatIndex, Citizen.resultAsInteger());
14
+ }
6
15
  }
package/index.d.ts CHANGED
@@ -8,3 +8,4 @@ export * from "./world";
8
8
  export * from "./GameConstants";
9
9
  export * from "./RelationshipGroup";
10
10
  export * from "./Attribute";
11
+ export { Convar, Kvp, Resource, Command } from "../common/index";
package/index.js CHANGED
@@ -8,3 +8,4 @@ export * from "./world";
8
8
  export * from "./GameConstants";
9
9
  export * from "./RelationshipGroup";
10
10
  export * from "./Attribute";
11
+ export { Convar, Kvp, Resource, Command } from "../common/index";
package/package.json CHANGED
@@ -1,10 +1,9 @@
1
1
  {
2
2
  "name": "@nativewrappers/redm",
3
3
  "description": "Native wrappers and utilities for use with RedM.",
4
- "author": "Remco Troost <d0p3t>",
5
4
  "license": "MIT",
6
5
  "type": "module",
7
- "version": "0.0.62",
6
+ "version": "0.0.64",
8
7
  "repository": {
9
8
  "type": "git",
10
9
  "url": "https://github.com/nativewrappers/nativewrappers.git"
@@ -28,6 +27,6 @@
28
27
  ".": "./index.js"
29
28
  },
30
29
  "dependencies": {
31
- "@nativewrappers/common": "0.0.62"
30
+ "@nativewrappers/common": "0.0.64"
32
31
  }
33
32
  }