@nativewrappers/redm 0.0.98 → 0.0.100

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/Model.d.ts CHANGED
@@ -6,8 +6,12 @@ export declare class Model implements Disposable {
6
6
  /**
7
7
  * Hash of this model.
8
8
  */
9
- private hash;
10
- private requestedModel;
9
+ protected hash: number;
10
+ protected requestCount: number;
11
+ /**
12
+ * Returns the amount of times this model has been requested from the client, useful for finding situations where the client fails to release the ref
13
+ */
14
+ get RequestCount(): number;
11
15
  /**
12
16
  * Creates a model object based on the hash key or model string.
13
17
  *
package/Model.js CHANGED
@@ -10,7 +10,13 @@ class Model {
10
10
  * Hash of this model.
11
11
  */
12
12
  hash;
13
- requestedModel = false;
13
+ requestCount = 0;
14
+ /**
15
+ * Returns the amount of times this model has been requested from the client, useful for finding situations where the client fails to release the ref
16
+ */
17
+ get RequestCount() {
18
+ return this.requestCount;
19
+ }
14
20
  /**
15
21
  * Creates a model object based on the hash key or model string.
16
22
  *
@@ -24,7 +30,7 @@ class Model {
24
30
  }
25
31
  }
26
32
  [Symbol.dispose]() {
27
- if (this.requestedModel) {
33
+ if (this.requestCount > 0) {
28
34
  this.markAsNoLongerNeeded();
29
35
  }
30
36
  }
@@ -127,11 +133,8 @@ class Model {
127
133
  }
128
134
  // TODO: Metaped stuff too at some point
129
135
  requestModel() {
130
- if (this.IsWeapon) {
131
- Citizen.invokeNative("0x72D4CB5DB927009C", this.hash, 0, true);
132
- } else {
133
- RequestModel(this.hash, false);
134
- }
136
+ RequestModel(this.hash, false);
137
+ this.requestCount++;
135
138
  }
136
139
  /**
137
140
  * Request and load the model with a specified timeout. Default timeout is 1000 (recommended).
@@ -152,7 +155,9 @@ class Model {
152
155
  while (!this.IsLoaded && GetGameTimer() < timeout) {
153
156
  await Delay(0);
154
157
  }
155
- this.requestedModel = true;
158
+ if (!this.IsLoaded) {
159
+ this.markAsNoLongerNeeded();
160
+ }
156
161
  return this.IsLoaded;
157
162
  }
158
163
  /**
package/Weapons.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { WeaponModel } from "./models/WeaponModel";
2
+ export declare const WEAPON_UNARMED: WeaponModel;
2
3
  export declare const WEAPON_MELEE_HATCHET_MELEEONLY: WeaponModel;
3
4
  export declare const WEAPON_MELEE_KNIFE_MINER: WeaponModel;
4
5
  export declare const WEAPON_MELEE_KNIFE_JAWBONE: WeaponModel;
package/Weapons.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { WeaponModel } from "./models/WeaponModel";
2
+ const WEAPON_UNARMED = new WeaponModel("WEAPON_UNARMED");
2
3
  const WEAPON_MELEE_HATCHET_MELEEONLY = new WeaponModel("WEAPON_MELEE_HATCHET_MELEEONLY");
3
4
  const WEAPON_MELEE_KNIFE_MINER = new WeaponModel("WEAPON_MELEE_KNIFE_MINER");
4
5
  const WEAPON_MELEE_KNIFE_JAWBONE = new WeaponModel("WEAPON_MELEE_KNIFE_JAWBONE");
@@ -147,6 +148,7 @@ const WEAPON_MELEE_KNIFE_HORROR = new WeaponModel("WEAPON_MELEE_KNIFE_HORROR");
147
148
  const WEAPON_MELEE_KNIFE_RUSTIC = new WeaponModel("WEAPON_MELEE_KNIFE_RUSTIC");
148
149
  const WEAPON_MELEE_LANTERN_HALLOWEEN = new WeaponModel("WEAPON_MELEE_LANTERN_HALLOWEEN");
149
150
  const WEAPONS_MAP = /* @__PURE__ */ new Map([
151
+ ["weapon_unarmed", WEAPON_UNARMED],
150
152
  ["weapon_melee_hatchet_meleeonly", WEAPON_MELEE_HATCHET_MELEEONLY],
151
153
  ["weapon_melee_knife_miner", WEAPON_MELEE_KNIFE_MINER],
152
154
  ["weapon_melee_knife_jawbone", WEAPON_MELEE_KNIFE_JAWBONE],
@@ -437,6 +439,7 @@ export {
437
439
  WEAPON_THROWN_THROWING_KNIVES_JAVIER,
438
440
  WEAPON_THROWN_TOMAHAWK,
439
441
  WEAPON_THROWN_TOMAHAWK_ANCIENT,
442
+ WEAPON_UNARMED,
440
443
  WEAPON_WOLF,
441
444
  WEAPON_WOLF_MEDIUM,
442
445
  WEAPON_WOLF_SMALL
@@ -8,6 +8,7 @@ interface ParameterTypes {
8
8
  interface Parameter {
9
9
  name: string;
10
10
  type: keyof ParameterTypes;
11
+ defaultValue?: any;
11
12
  help?: string;
12
13
  optional?: boolean;
13
14
  }
@@ -18,6 +19,27 @@ type MappedParameters<T extends Parameter[]> = {
18
19
  raw: string;
19
20
  };
20
21
  type CommandHandler<T extends Parameter[]> = (args: MappedParameters<T>) => void | Promise<void>;
22
+ /**
23
+ * ```typescript
24
+ * new Command(["do", "deleteobjects"], async ({source, radius}) => {
25
+ * const entities = Prop.AllProps();
26
+ * const ply = new Player(source);
27
+ * const pos = ply.Ped.Position
28
+ * for (const ent of entities) {
29
+ * // if they're outside of the range of our specified radius just continue to next
30
+ * if (ent.Position.distance(pos) > radius) continue;
31
+ * ent.delete();
32
+ * }
33
+ * }, "Deletes all objects in the specified range", [
34
+ * {
35
+ * name: "radius",
36
+ * type: "number",
37
+ * help: "The radius to delete the entities in",
38
+ * defaultValue: 5.0
39
+ * }
40
+ * ] as const, "group.moderator")
41
+ * ```
42
+ */
21
43
  export declare class Command<T extends Parameter[] = Parameter[]> {
22
44
  #private;
23
45
  readonly name: string | string[];
package/common/Command.js CHANGED
@@ -49,7 +49,9 @@ class Command {
49
49
  if (params) {
50
50
  for (const parameter of params) {
51
51
  if (parameter.type) {
52
- parameter.help = parameter.help ? `${parameter.help} (type: ${parameter.type})` : `(type: ${parameter.type})`;
52
+ const defaultString = parameter.defaultValue !== void 0 ? `[default: ${parameter.defaultValue}]` : "";
53
+ const typeString = `[type: ${parameter.type}] ${defaultString}`;
54
+ parameter.help = parameter.help ? `${parameter.help} ${typeString}` : `${typeString}`;
53
55
  }
54
56
  }
55
57
  }
@@ -87,26 +89,36 @@ class Command {
87
89
  const result = this.params.every((param, index) => {
88
90
  const arg = args[index];
89
91
  let value = arg;
90
- switch (param.type) {
91
- case "number":
92
- value = +arg;
93
- break;
94
- case "string":
95
- value = !Number(arg) ? arg : false;
96
- break;
97
- case "playerId":
98
- $SERVER: {
99
- value = arg === "me" ? source2 : +arg;
100
- if (!value || !DoesPlayerExist(value.toString())) value = void 0;
101
- }
102
- $CLIENT: {
103
- value = arg === "me" ? GetPlayerServerId(PlayerId()) : +arg;
104
- if (!value || GetPlayerFromServerId(value) === -1) value = void 0;
105
- }
106
- break;
107
- case "longString":
108
- value = raw.substring(raw.indexOf(arg));
109
- break;
92
+ const hasDefaultValue = param.defaultValue !== void 0;
93
+ const hasArg = typeof arg === "string";
94
+ if (!hasArg && hasDefaultValue) {
95
+ value = param.defaultValue;
96
+ } else {
97
+ switch (param.type) {
98
+ case "number":
99
+ if (hasDefaultValue && !hasArg) {
100
+ value = param.defaultValue;
101
+ } else {
102
+ value = +arg;
103
+ }
104
+ break;
105
+ case "string":
106
+ value = !Number(arg) ? arg : false;
107
+ break;
108
+ case "playerId":
109
+ $SERVER: {
110
+ value = arg === "me" ? source2 : +arg;
111
+ if (!value || !DoesPlayerExist(value.toString())) value = void 0;
112
+ }
113
+ $CLIENT: {
114
+ value = arg === "me" ? GetPlayerServerId(PlayerId()) : +arg;
115
+ if (!value || GetPlayerFromServerId(value) === -1) value = void 0;
116
+ }
117
+ break;
118
+ case "longString":
119
+ value = raw.substring(raw.indexOf(arg));
120
+ break;
121
+ }
110
122
  }
111
123
  if (value === void 0 && (!param.optional || param.optional && arg)) {
112
124
  return Citizen.trace(
@@ -15,8 +15,20 @@ function Exports(exportName) {
15
15
  throw new Error("Exports does not work on private methods, please mark the method as public");
16
16
  }
17
17
  context.addInitializer(function() {
18
- exports(exportName, (...args) => {
19
- return originalMethod.call(this, ...args);
18
+ exports(exportName, async (...args) => {
19
+ try {
20
+ return await originalMethod.call(this, ...args);
21
+ } catch (err) {
22
+ REMOVE_EVENT_LOG: {
23
+ if (!GlobalData.EnablePrettyPrint) return;
24
+ console.error("------- EXPORT ERROR --------");
25
+ console.error(`Call to ${exportName} errored`);
26
+ console.error(`Data: ${JSON.stringify(args)}`);
27
+ console.error(`Error: ${err}`);
28
+ console.error("------- END EXPORT ERROR --------");
29
+ }
30
+ throw err;
31
+ }
20
32
  });
21
33
  });
22
34
  }, "actualDecorator");
@@ -28,9 +40,9 @@ function Event(eventName) {
28
40
  throw new Error("Event does not work on private methods, please mark the method as public");
29
41
  }
30
42
  context.addInitializer(function() {
31
- on(eventName, (...args) => {
43
+ on(eventName, async (...args) => {
32
44
  try {
33
- return originalMethod.call(this, ...args);
45
+ return await originalMethod.call(this, ...args);
34
46
  } catch (e) {
35
47
  REMOVE_EVENT_LOG: {
36
48
  if (!GlobalData.EnablePrettyPrint) return;
@@ -52,7 +64,7 @@ function NetEvent(eventName, remoteOnly = true) {
52
64
  throw new Error("NetEvent does not work on private methods, please mark the method as public");
53
65
  }
54
66
  context.addInitializer(function() {
55
- onNet(eventName, (...args) => {
67
+ onNet(eventName, async (...args) => {
56
68
  const src = source;
57
69
  try {
58
70
  $CLIENT: {
@@ -60,7 +72,7 @@ function NetEvent(eventName, remoteOnly = true) {
60
72
  return;
61
73
  }
62
74
  }
63
- return originalMethod.call(this, ...args);
75
+ return await originalMethod.call(this, ...args);
64
76
  } catch (e) {
65
77
  REMOVE_NET_EVENT_LOG: {
66
78
  if (!GlobalData.EnablePrettyPrint) return;
package/entities/Ped.d.ts CHANGED
@@ -1,8 +1,9 @@
1
1
  import type { Vector3 } from "../common/utils/Vector";
2
2
  import { Tasks } from "../Task";
3
+ import { WeaponAttachPoints } from "../enums/WeaponAttachPoints";
3
4
  import { ItemAddReason } from "../inventory/InventoryTypes";
4
5
  import type { AmmoModel } from "../models/AmmoModel";
5
- import type { WeaponModel } from "../models/WeaponModel";
6
+ import { WeaponModel } from "../models/WeaponModel";
6
7
  import { Attributes } from "../Attribute";
7
8
  import type { KnockOffVehicle, TamingState, eDamageCleanliness } from "../enums/Ped";
8
9
  import type { VehicleSeat } from "../enums/VehicleSeat";
@@ -205,4 +206,8 @@ export declare class Ped extends BaseEntity {
205
206
  disableAmmoForWeapon(weapon: WeaponModel, ammo: AmmoModel): void;
206
207
  get HasPistol(): boolean;
207
208
  get HasRepeater(): boolean;
209
+ get CurrentWeapon(): WeaponModel;
210
+ giveWeapon(weapon: WeaponModel, ammoCount: number, forceInHand?: boolean, forceInHolster?: boolean, attachPoint?: WeaponAttachPoints | undefined, allowMultipleCopies?: boolean, p7?: number, p8?: number, addReason?: ItemAddReason, ignoreUnlocks?: boolean, permanentDegradation?: number, p12?: boolean): Promise<void>;
211
+ setCurrentWeapon(weapon: WeaponModel, equipNow?: boolean, attachPoint?: WeaponAttachPoints, p4?: boolean, p5?: boolean): void;
212
+ holsterWeapon(): void;
208
213
  }
package/entities/Ped.js CHANGED
@@ -1,7 +1,9 @@
1
1
  var __defProp = Object.defineProperty;
2
2
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
3
  import { Tasks } from "../Task";
4
+ import { WeaponAttachPoints } from "../enums/WeaponAttachPoints";
4
5
  import { ItemAddReason } from "../inventory/InventoryTypes";
6
+ import { WeaponModel } from "../models/WeaponModel";
5
7
  import { _N } from "../utils/Native";
6
8
  import { Attributes } from "../Attribute";
7
9
  import { BaseEntity } from "./BaseEntity";
@@ -441,6 +443,36 @@ class Ped extends BaseEntity {
441
443
  get HasRepeater() {
442
444
  return Citizen.invokeNative("0x495A04CAEC263AF8", this.handle);
443
445
  }
446
+ get CurrentWeapon() {
447
+ const weapon = Citizen.invokeNative("0x8425C5F057012DAB", this.handle);
448
+ return new WeaponModel(weapon);
449
+ }
450
+ async giveWeapon(weapon, ammoCount, forceInHand = true, forceInHolster = false, attachPoint = void 0, allowMultipleCopies = false, p7 = 0.5, p8 = 1, addReason = ItemAddReason.Default, ignoreUnlocks = true, permanentDegradation = 0.5, p12 = false) {
451
+ await weapon.request();
452
+ attachPoint = attachPoint ?? weapon.DefaultAttachPoint;
453
+ Citizen.invokeNative(
454
+ "0x5E3BDDBCB83F3D84",
455
+ this.handle,
456
+ weapon.Hash,
457
+ ammoCount,
458
+ forceInHand,
459
+ forceInHolster,
460
+ attachPoint,
461
+ allowMultipleCopies,
462
+ p7,
463
+ p8,
464
+ addReason,
465
+ ignoreUnlocks,
466
+ permanentDegradation,
467
+ p12
468
+ );
469
+ }
470
+ setCurrentWeapon(weapon, equipNow = true, attachPoint = WeaponAttachPoints.HandPrimary, p4 = false, p5 = false) {
471
+ Citizen.invokeNative("0xADF692B254977C0C", this.handle, weapon.Hash, equipNow, attachPoint, p4, p5);
472
+ }
473
+ holsterWeapon() {
474
+ Citizen.invokeNative("0x94A3C1B804D291EC", this.handle, true, true, true, true);
475
+ }
444
476
  }
445
477
  export {
446
478
  Ped
@@ -0,0 +1,35 @@
1
+ export declare enum WeaponAttachPoints {
2
+ HandPrimary = 0,
3
+ HandSecondary = 1,
4
+ PistolR = 2,
5
+ MAX_HAND_ATTACH_POINTS = 2,
6
+ PistolLeft = 3,
7
+ Knife = 4,
8
+ Lasso = 5,
9
+ Thrower = 6,
10
+ Bow = 7,
11
+ BowAlternative = 8,
12
+ Rifle = 9,
13
+ RifleAlternative = 10,
14
+ Lantern = 11,
15
+ TempLantern = 12,
16
+ Melee = 13,
17
+ MAX_SYNCED_WEAPON_ATTACH_POINTS = 13,
18
+ Hip = 14,
19
+ Boot = 15,
20
+ Back = 16,
21
+ Front = 18,
22
+ ShoulderSling = 19,
23
+ LeftBreast = 20,
24
+ RightBreast = 21,
25
+ LeftArmpit = 22,
26
+ RightArmpit = 23,
27
+ LeftArmpitRifle = 24,
28
+ Satchel = 25,
29
+ LeftArmPitBow = 26,
30
+ RightHandExtra = 27,
31
+ LeftHandExtra = 28,
32
+ RightHandAux = 29,
33
+ MAX_WEAPON_ATTACH_POINTS = 29,
34
+ WEAPON_ATTACH_POINT_INVALID = -1
35
+ }
@@ -0,0 +1,39 @@
1
+ var WeaponAttachPoints = /* @__PURE__ */ ((WeaponAttachPoints2) => {
2
+ WeaponAttachPoints2[WeaponAttachPoints2["HandPrimary"] = 0] = "HandPrimary";
3
+ WeaponAttachPoints2[WeaponAttachPoints2["HandSecondary"] = 1] = "HandSecondary";
4
+ WeaponAttachPoints2[WeaponAttachPoints2["PistolR"] = 2] = "PistolR";
5
+ WeaponAttachPoints2[WeaponAttachPoints2["MAX_HAND_ATTACH_POINTS"] = 2] = "MAX_HAND_ATTACH_POINTS";
6
+ WeaponAttachPoints2[WeaponAttachPoints2["PistolLeft"] = 3] = "PistolLeft";
7
+ WeaponAttachPoints2[WeaponAttachPoints2["Knife"] = 4] = "Knife";
8
+ WeaponAttachPoints2[WeaponAttachPoints2["Lasso"] = 5] = "Lasso";
9
+ WeaponAttachPoints2[WeaponAttachPoints2["Thrower"] = 6] = "Thrower";
10
+ WeaponAttachPoints2[WeaponAttachPoints2["Bow"] = 7] = "Bow";
11
+ WeaponAttachPoints2[WeaponAttachPoints2["BowAlternative"] = 8] = "BowAlternative";
12
+ WeaponAttachPoints2[WeaponAttachPoints2["Rifle"] = 9] = "Rifle";
13
+ WeaponAttachPoints2[WeaponAttachPoints2["RifleAlternative"] = 10] = "RifleAlternative";
14
+ WeaponAttachPoints2[WeaponAttachPoints2["Lantern"] = 11] = "Lantern";
15
+ WeaponAttachPoints2[WeaponAttachPoints2["TempLantern"] = 12] = "TempLantern";
16
+ WeaponAttachPoints2[WeaponAttachPoints2["Melee"] = 13] = "Melee";
17
+ WeaponAttachPoints2[WeaponAttachPoints2["MAX_SYNCED_WEAPON_ATTACH_POINTS"] = 13] = "MAX_SYNCED_WEAPON_ATTACH_POINTS";
18
+ WeaponAttachPoints2[WeaponAttachPoints2["Hip"] = 14] = "Hip";
19
+ WeaponAttachPoints2[WeaponAttachPoints2["Boot"] = 15] = "Boot";
20
+ WeaponAttachPoints2[WeaponAttachPoints2["Back"] = 16] = "Back";
21
+ WeaponAttachPoints2[WeaponAttachPoints2["Front"] = 18] = "Front";
22
+ WeaponAttachPoints2[WeaponAttachPoints2["ShoulderSling"] = 19] = "ShoulderSling";
23
+ WeaponAttachPoints2[WeaponAttachPoints2["LeftBreast"] = 20] = "LeftBreast";
24
+ WeaponAttachPoints2[WeaponAttachPoints2["RightBreast"] = 21] = "RightBreast";
25
+ WeaponAttachPoints2[WeaponAttachPoints2["LeftArmpit"] = 22] = "LeftArmpit";
26
+ WeaponAttachPoints2[WeaponAttachPoints2["RightArmpit"] = 23] = "RightArmpit";
27
+ WeaponAttachPoints2[WeaponAttachPoints2["LeftArmpitRifle"] = 24] = "LeftArmpitRifle";
28
+ WeaponAttachPoints2[WeaponAttachPoints2["Satchel"] = 25] = "Satchel";
29
+ WeaponAttachPoints2[WeaponAttachPoints2["LeftArmPitBow"] = 26] = "LeftArmPitBow";
30
+ WeaponAttachPoints2[WeaponAttachPoints2["RightHandExtra"] = 27] = "RightHandExtra";
31
+ WeaponAttachPoints2[WeaponAttachPoints2["LeftHandExtra"] = 28] = "LeftHandExtra";
32
+ WeaponAttachPoints2[WeaponAttachPoints2["RightHandAux"] = 29] = "RightHandAux";
33
+ WeaponAttachPoints2[WeaponAttachPoints2["MAX_WEAPON_ATTACH_POINTS"] = 29] = "MAX_WEAPON_ATTACH_POINTS";
34
+ WeaponAttachPoints2[WeaponAttachPoints2["WEAPON_ATTACH_POINT_INVALID"] = -1] = "WEAPON_ATTACH_POINT_INVALID";
35
+ return WeaponAttachPoints2;
36
+ })(WeaponAttachPoints || {});
37
+ export {
38
+ WeaponAttachPoints
39
+ };
package/index.d.ts CHANGED
@@ -35,6 +35,7 @@ export * from "./enums/Ped";
35
35
  export * from "./enums/RawKeys";
36
36
  export * from "./enums/Relationship";
37
37
  export * from "./enums/VehicleSeat";
38
+ export * from "./enums/WeaponAttachPoints";
38
39
  export * from "./entities/BaseEntity";
39
40
  export * from "./entities/Entity";
40
41
  export * from "./entities/HorsePeltEntries";
package/index.js CHANGED
@@ -35,6 +35,7 @@ export * from "./enums/Ped";
35
35
  export * from "./enums/RawKeys";
36
36
  export * from "./enums/Relationship";
37
37
  export * from "./enums/VehicleSeat";
38
+ export * from "./enums/WeaponAttachPoints";
38
39
  export * from "./entities/BaseEntity";
39
40
  export * from "./entities/Entity";
40
41
  export * from "./entities/HorsePeltEntries";
@@ -1,3 +1,7 @@
1
1
  import { Model } from "../Model";
2
+ import type { WeaponAttachPoints } from "../enums/WeaponAttachPoints";
2
3
  export declare class WeaponModel extends Model {
4
+ requestModel(): void;
5
+ markAsNoLongerNeeded(): void;
6
+ get DefaultAttachPoint(): WeaponAttachPoints;
3
7
  }
@@ -5,6 +5,17 @@ class WeaponModel extends Model {
5
5
  static {
6
6
  __name(this, "WeaponModel");
7
7
  }
8
+ requestModel() {
9
+ Citizen.invokeNative("0x72D4CB5DB927009C", this.hash, 0, true);
10
+ this.requestCount++;
11
+ }
12
+ markAsNoLongerNeeded() {
13
+ Citizen.invokeNative("0xC3896D03E2852236", this.hash);
14
+ this.requestCount--;
15
+ }
16
+ get DefaultAttachPoint() {
17
+ return Citizen.invokeNative("0x65DC4AC5B96614CB", this.hash, Citizen.resultAsInteger());
18
+ }
8
19
  }
9
20
  export {
10
21
  WeaponModel
package/package.json CHANGED
@@ -8,7 +8,7 @@
8
8
  ],
9
9
  "license": "MIT",
10
10
  "type": "module",
11
- "version": "0.0.98",
11
+ "version": "0.0.100",
12
12
  "repository": {
13
13
  "type": "git",
14
14
  "url": "https://github.com/nativewrappers/nativewrappers.git"