@nativewrappers/fivem 0.0.136 → 0.0.138

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/Pickup.d.ts +4 -0
  2. package/Pickup.js +6 -0
  3. package/World.d.ts +21 -4
  4. package/World.js +22 -18
  5. package/common/BaseScript.d.ts +2 -0
  6. package/common/BaseScript.js +10 -0
  7. package/common/Command.js +6 -4
  8. package/common/GlobalData.d.ts +10 -0
  9. package/common/GlobalData.js +18 -0
  10. package/common/collections/CircularBuffer.d.ts +18 -0
  11. package/common/collections/CircularBuffer.js +92 -0
  12. package/common/collections/Stack.d.ts +9 -0
  13. package/common/collections/Stack.js +0 -0
  14. package/common/decors/Events.js +12 -4
  15. package/common/decors/Exports.js +3 -1
  16. package/common/decors/Resources.d.ts +10 -2
  17. package/common/decors/Resources.js +35 -10
  18. package/common/decors/Ticks.js +11 -2
  19. package/common/net/NetworkedMap.d.ts +2 -2
  20. package/common/net/NetworkedMap.js +13 -1
  21. package/common-game/entities/CommonBaseEntityBone.d.ts +4 -4
  22. package/common-game/entities/CommonBaseEntityBone.js +11 -7
  23. package/common-game/entities/CommonBaseEntityBoneCollection.d.ts +1 -0
  24. package/common-game/entities/CommonEntityBone.d.ts +1 -1
  25. package/common-game/entities/CommonEntityBone.js +2 -2
  26. package/common-game/entities/CommonEntityBoneCollection.d.ts +3 -0
  27. package/common-game/entities/CommonEntityBoneCollection.js +6 -0
  28. package/common-game/entities/CommonPedBone.d.ts +1 -1
  29. package/common-game/entities/CommonPedBone.js +2 -2
  30. package/common-game/entities/CommonPedBoneCollection.d.ts +4 -1
  31. package/common-game/entities/CommonPedBoneCollection.js +8 -2
  32. package/index.d.ts +4 -0
  33. package/index.js +4 -0
  34. package/package.json +1 -1
  35. package/world/getGamePool.d.ts +14 -0
  36. package/world/getGamePool.js +30 -0
package/Pickup.d.ts CHANGED
@@ -2,6 +2,10 @@ import { Vector3 } from "./common/utils/Vector";
2
2
  export declare class Pickup {
3
3
  private handle;
4
4
  constructor(handle: number);
5
+ /**
6
+ * @returns `true` if the current entity is networked, false otherwise
7
+ */
8
+ get IsNetworked(): boolean;
5
9
  get Position(): Vector3;
6
10
  get IsCollected(): boolean;
7
11
  delete(): void;
package/Pickup.js CHANGED
@@ -9,6 +9,12 @@ class Pickup {
9
9
  constructor(handle) {
10
10
  this.handle = handle;
11
11
  }
12
+ /**
13
+ * @returns `true` if the current entity is networked, false otherwise
14
+ */
15
+ get IsNetworked() {
16
+ return NetworkGetEntityIsNetworked(this.handle);
17
+ }
12
18
  get Position() {
13
19
  return Vector3.fromArray(GetPickupCoords(this.handle));
14
20
  }
package/World.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { Color } from "./common/utils/Color";
2
- import { Vector3 } from "./common/utils/Vector";
2
+ import { Vector3, Vector4 } from "./common/utils/Vector";
3
3
  import { Blip } from "./Blip";
4
4
  import { Camera } from "./Camera";
5
5
  import { Model } from "./Model";
@@ -178,18 +178,35 @@ export declare abstract class World {
178
178
  * Create a ped at a desired location.
179
179
  *
180
180
  * ```typescript
181
- * const position = new Vector3(-802.311, 175.056, 72.8446);
181
+ * const position = new Vector3(-802.31, 175.06, 72.84);
182
182
  * const model = new Model("a_f_m_beach_01");
183
183
  * const myPed = await World.createPed(model, position);
184
184
  * ```
185
185
  *
186
186
  * @param model Ped model to be spawned.
187
187
  * @param position World position (coordinates) of Ped spawn.
188
- * @param heading Heading of Ped when spawning.
189
- * @param shouldNetwork if the created ped should be networked to other clients
188
+ * @param [heading=0] Heading of Ped when spawning.
189
+ * @param [shouldNetwork=false] if the created ped should be networked to other clients
190
+ * @param [pinToScript=true] if the ped should be pinned to the script.
190
191
  * @returns Ped object.
191
192
  */
192
193
  static createPed(model: Model, position: Vector3, heading?: number, shouldNetwork?: boolean, pinToScript?: boolean): Promise<Ped | null>;
194
+ /**
195
+ * Create a ped at a desired location.
196
+ *
197
+ * ```typescript
198
+ * const position = new Vector4(-802.31, 175.05, 72.84, 122.75);
199
+ * const model = new Model("a_f_m_beach_01");
200
+ * const myPed = await World.createPed(model, position);
201
+ * ```
202
+ *
203
+ * @param model Ped model to be spawned.
204
+ * @param position World position (coordinates) of Ped spawn, note that the `w` section of Vector4 is used for heading.
205
+ * @param [shouldNetwork=false] if the created ped should be networked to other clients
206
+ * @param [pinToScript=true] if the ped should be pinned to the script.
207
+ * @returns Ped object.
208
+ */
209
+ static createPed(model: Model, position: Vector4, shouldNetwork?: boolean, pinToScript?: boolean): Promise<Ped | null>;
193
210
  /**
194
211
  * Created a ped in the specified vehicle
195
212
  *
package/World.js CHANGED
@@ -1,7 +1,7 @@
1
1
  var __defProp = Object.defineProperty;
2
2
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
3
  import { Delay } from "./common/utils/Delay";
4
- import { Vector3 } from "./common/utils/Vector";
4
+ import { Vector3, Vector4 } from "./common/utils/Vector";
5
5
  import { Blip } from "./Blip";
6
6
  import { Camera } from "./Camera";
7
7
  import { GameplayCamera } from "./GameplayCamera";
@@ -322,26 +322,30 @@ class World {
322
322
  )
323
323
  );
324
324
  }
325
- /**
326
- * Create a ped at a desired location.
327
- *
328
- * ```typescript
329
- * const position = new Vector3(-802.311, 175.056, 72.8446);
330
- * const model = new Model("a_f_m_beach_01");
331
- * const myPed = await World.createPed(model, position);
332
- * ```
333
- *
334
- * @param model Ped model to be spawned.
335
- * @param position World position (coordinates) of Ped spawn.
336
- * @param heading Heading of Ped when spawning.
337
- * @param shouldNetwork if the created ped should be networked to other clients
338
- * @returns Ped object.
339
- */
340
- static async createPed(model, position, heading = 0, shouldNetwork = true, pinToScript = true) {
325
+ static async createPed(model, position, headingOrNetwork, shouldNetworkOrPin, pinToScript) {
341
326
  if (!model.IsPed || !await model.request(1e3)) {
342
327
  return null;
343
328
  }
344
- const ped = CreatePed(-1, model.Hash, position.x, position.y, position.z, heading, shouldNetwork, pinToScript);
329
+ if (position instanceof Vector4) {
330
+ const shouldNetwork2 = headingOrNetwork ?? false;
331
+ const pinToScriptValue2 = shouldNetworkOrPin ?? true;
332
+ const ped2 = CreatePed(
333
+ -1,
334
+ model.Hash,
335
+ position.x,
336
+ position.y,
337
+ position.z,
338
+ position.w,
339
+ shouldNetwork2,
340
+ pinToScriptValue2
341
+ );
342
+ model.markAsNoLongerNeeded();
343
+ return Ped.fromHandle(ped2);
344
+ }
345
+ const heading = headingOrNetwork ?? 0;
346
+ const shouldNetwork = shouldNetworkOrPin ?? false;
347
+ const pinToScriptValue = pinToScript ?? true;
348
+ const ped = CreatePed(-1, model.Hash, position.x, position.y, position.z, heading, shouldNetwork, pinToScriptValue);
345
349
  model.markAsNoLongerNeeded();
346
350
  return Ped.fromHandle(ped);
347
351
  }
@@ -0,0 +1,2 @@
1
+ export declare abstract class BaseScript {
2
+ }
@@ -0,0 +1,10 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+ class BaseScript {
4
+ static {
5
+ __name(this, "BaseScript");
6
+ }
7
+ }
8
+ export {
9
+ BaseScript
10
+ };
package/common/Command.js CHANGED
@@ -14,6 +14,9 @@ function registerCommand(name, commandHandler, restricted = true) {
14
14
  }
15
15
  RegisterCommand(name, commandHandler, GlobalData.IS_CLIENT ? false : !!restricted);
16
16
  $SERVER: {
17
+ $CLIENT: {
18
+ if (GlobalData.IS_CLIENT) return;
19
+ }
17
20
  const ace = `command.${name}`;
18
21
  if (typeof restricted === "string") {
19
22
  if (IsPrincipalAceAllowed(restricted, ace)) return;
@@ -59,13 +62,12 @@ class Command {
59
62
  const names = Array.isArray(name) ? name : [name];
60
63
  for (const name2 of names) {
61
64
  const commandObj = { ...this, name: `/${name2}` };
62
- $SERVER: {
65
+ if (GlobalData.IS_CLIENT) {
66
+ emit("chat:addSuggestion", commandObj);
67
+ } else {
63
68
  commands.push(commandObj);
64
69
  emitNet("chat:addSuggestions", -1, commandObj);
65
70
  }
66
- $CLIENT: {
67
- emit("chat:addSuggestion", commandObj);
68
- }
69
71
  }
70
72
  }, 100);
71
73
  }
@@ -1,3 +1,12 @@
1
+ export declare enum ErrorType {
2
+ Event = 0,
3
+ NetEvent = 1,
4
+ Export = 2,
5
+ Nui = 3,
6
+ Tick = 4,
7
+ Immediate = 5
8
+ }
9
+ export type NativeWrapperErrorType = (type: ErrorType, err: Error) => void;
1
10
  export declare class GlobalData {
2
11
  static CurrentResource: string;
3
12
  static GameName: string;
@@ -9,4 +18,5 @@ export declare class GlobalData {
9
18
  static NetworkTick: number | null;
10
19
  static NetworkedTicks: any[];
11
20
  static EnablePrettyPrint: boolean;
21
+ static OnError: (type: ErrorType, err: Error) => void;
12
22
  }
@@ -1,5 +1,16 @@
1
1
  var __defProp = Object.defineProperty;
2
2
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+ var ErrorType = /* @__PURE__ */ ((ErrorType2) => {
4
+ ErrorType2[ErrorType2["Event"] = 0] = "Event";
5
+ ErrorType2[ErrorType2["NetEvent"] = 1] = "NetEvent";
6
+ ErrorType2[ErrorType2["Export"] = 2] = "Export";
7
+ ErrorType2[ErrorType2["Nui"] = 3] = "Nui";
8
+ ErrorType2[ErrorType2["Tick"] = 4] = "Tick";
9
+ ErrorType2[ErrorType2["Immediate"] = 5] = "Immediate";
10
+ return ErrorType2;
11
+ })(ErrorType || {});
12
+ globalThis.OnError = (type, err) => {
13
+ };
3
14
  class GlobalData {
4
15
  static {
5
16
  __name(this, "GlobalData");
@@ -14,7 +25,14 @@ class GlobalData {
14
25
  static NetworkTick = null;
15
26
  static NetworkedTicks = [];
16
27
  static EnablePrettyPrint = true;
28
+ /*
29
+ * Called when one of the decors errors
30
+ */
31
+ static OnError = /* @__PURE__ */ __name((type, err) => {
32
+ globalThis.OnError(type, err);
33
+ }, "OnError");
17
34
  }
18
35
  export {
36
+ ErrorType,
19
37
  GlobalData
20
38
  };
@@ -0,0 +1,18 @@
1
+ export declare class CircularBuffer<T> {
2
+ private buffer;
3
+ private tail;
4
+ private count;
5
+ private max_size;
6
+ constructor(max_size: number);
7
+ push(item: T): void;
8
+ pop(): T | undefined;
9
+ peek(): T | undefined;
10
+ [Symbol.iterator](): Iterator<T>;
11
+ for_each(callback: (item: T, index: number) => void): void;
12
+ average(this: CircularBuffer<number>): number;
13
+ is_empty(): boolean;
14
+ is_full(): boolean;
15
+ size(): number;
16
+ capacity(): number;
17
+ clear(): void;
18
+ }
@@ -0,0 +1,92 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+ class CircularBuffer {
4
+ static {
5
+ __name(this, "CircularBuffer");
6
+ }
7
+ buffer;
8
+ tail = 0;
9
+ count = 0;
10
+ max_size;
11
+ constructor(max_size) {
12
+ if (max_size <= 0) {
13
+ throw new Error("Buffer size must be greater than 0");
14
+ }
15
+ this.max_size = max_size;
16
+ this.buffer = new Array(max_size);
17
+ }
18
+ push(item) {
19
+ this.buffer[this.tail] = item;
20
+ this.tail++;
21
+ if (this.tail >= this.max_size) {
22
+ this.tail = 0;
23
+ }
24
+ if (this.count < this.max_size) {
25
+ this.count++;
26
+ }
27
+ }
28
+ pop() {
29
+ if (this.is_empty()) {
30
+ return void 0;
31
+ }
32
+ this.tail--;
33
+ if (this.tail < 0) {
34
+ this.tail = this.max_size - 1;
35
+ }
36
+ const item = this.buffer[this.tail];
37
+ this.buffer[this.tail] = void 0;
38
+ this.count--;
39
+ return item;
40
+ }
41
+ peek() {
42
+ if (this.is_empty()) {
43
+ return void 0;
44
+ }
45
+ let peek_index = this.tail - 1;
46
+ if (peek_index < 0) {
47
+ peek_index = this.max_size - 1;
48
+ }
49
+ return this.buffer[peek_index];
50
+ }
51
+ *[Symbol.iterator]() {
52
+ for (let i = 0; i < this.count; i++) {
53
+ yield this.buffer[i];
54
+ }
55
+ }
56
+ for_each(callback) {
57
+ let i = 0;
58
+ for (const item of this) {
59
+ callback(item, i++);
60
+ }
61
+ }
62
+ average() {
63
+ if (this.is_empty()) {
64
+ return 0;
65
+ }
66
+ let sum = 0;
67
+ for (const item of this) {
68
+ sum += item;
69
+ }
70
+ return sum / this.count;
71
+ }
72
+ is_empty() {
73
+ return this.count === 0;
74
+ }
75
+ is_full() {
76
+ return this.count === this.max_size;
77
+ }
78
+ size() {
79
+ return this.count;
80
+ }
81
+ capacity() {
82
+ return this.max_size;
83
+ }
84
+ clear() {
85
+ this.buffer = new Array(this.max_size);
86
+ this.tail = 0;
87
+ this.count = 0;
88
+ }
89
+ }
90
+ export {
91
+ CircularBuffer
92
+ };
@@ -0,0 +1,9 @@
1
+ declare class Stack<T> {
2
+ private items;
3
+ push(item: T): void;
4
+ pop(): T | undefined;
5
+ peek(): T | undefined;
6
+ is_empty(): boolean;
7
+ size(): number;
8
+ clear(): void;
9
+ }
File without changes
@@ -1,6 +1,6 @@
1
1
  var __defProp = Object.defineProperty;
2
2
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
- import { GlobalData } from "../GlobalData";
3
+ import { ErrorType, GlobalData } from "../GlobalData";
4
4
  const DisablePrettyPrint = /* @__PURE__ */ __name(() => GlobalData.EnablePrettyPrint = false, "DisablePrettyPrint");
5
5
  const AsyncFunction = (async () => {
6
6
  }).constructor;
@@ -14,12 +14,13 @@ function OnEvent(eventName) {
14
14
  try {
15
15
  return await originalMethod.call(this, ...args);
16
16
  } catch (e) {
17
+ GlobalData.OnError(ErrorType.Event, e);
17
18
  REMOVE_EVENT_LOG: {
18
19
  if (!GlobalData.EnablePrettyPrint) return;
19
20
  console.error("------- EVENT ERROR --------");
20
21
  console.error(`Call to ${eventName} errored`);
21
22
  console.error(`Data: ${JSON.stringify(args)}`);
22
- console.error(`Error: ${e}`);
23
+ globalThis.printError("event", e);
23
24
  console.error("------- END EVENT ERROR --------");
24
25
  }
25
26
  }
@@ -62,13 +63,14 @@ function OnNetEvent(eventName, remoteOnly = true) {
62
63
  }
63
64
  return await originalMethod.call(this, ...args);
64
65
  } catch (e) {
66
+ GlobalData.OnError(ErrorType.NetEvent, e);
65
67
  REMOVE_NET_EVENT_LOG: {
66
68
  if (!GlobalData.EnablePrettyPrint) return;
67
69
  console.error("------- NET EVENT ERROR --------");
68
70
  console.error(`Call to ${eventName} errored`);
69
71
  console.error(`Caller: ${src}`);
70
72
  console.error(`Data: ${JSON.stringify(args)}`);
71
- console.error(`Error: ${e}`);
73
+ globalThis.printError("net event", e);
72
74
  console.error("------- END NET EVENT ERROR --------");
73
75
  }
74
76
  }
@@ -90,7 +92,13 @@ function OnNuiEvent(eventName, dontErrorWhenCbIsntInvoked = false) {
90
92
  wasInvoked = true;
91
93
  cb(args);
92
94
  }, "cbWrapper");
93
- const retData = await originalMethod.call(this, data, cbWrapper);
95
+ let retData;
96
+ try {
97
+ retData = await originalMethod.call(this, data, cbWrapper);
98
+ } catch (e) {
99
+ GlobalData.OnError(ErrorType.Nui, e);
100
+ return;
101
+ }
94
102
  if (!wasInvoked && !retData) {
95
103
  if (dontErrorWhenCbIsntInvoked) return;
96
104
  throw new Error(
@@ -1,6 +1,6 @@
1
1
  var __defProp = Object.defineProperty;
2
2
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
- import { GlobalData } from "../GlobalData";
3
+ import { ErrorType, GlobalData } from "../GlobalData";
4
4
  const AsyncFunction = (async () => {
5
5
  }).constructor;
6
6
  function Exports(exportName) {
@@ -15,6 +15,7 @@ function Exports(exportName) {
15
15
  try {
16
16
  return await originalMethod.call(this, ...args);
17
17
  } catch (err) {
18
+ GlobalData.OnError(ErrorType.Export, err);
18
19
  REMOVE_EVENT_LOG: {
19
20
  if (!GlobalData.EnablePrettyPrint) return;
20
21
  console.error("------- EXPORT ERROR --------");
@@ -31,6 +32,7 @@ function Exports(exportName) {
31
32
  try {
32
33
  return originalMethod.call(this, ...args);
33
34
  } catch (err) {
35
+ GlobalData.OnError(ErrorType.Export, err);
34
36
  REMOVE_EVENT_LOG: {
35
37
  if (!GlobalData.EnablePrettyPrint) return;
36
38
  console.error("------- EXPORT ERROR --------");
@@ -1,8 +1,16 @@
1
+ type ResourceName = string;
2
+ type ResourceOrGlobal = ResourceName | "global";
3
+ export declare const EnsureResourceWrapperInit: () => void;
1
4
  /**
2
5
  * Called whenever the specified resource is started, this will be called once on once on resource start if the resource is started.
6
+ * NOTE: If you want to listen to *all* resource start/stop events you should send
7
+ * {@link resource} as "global"
3
8
  */
4
- export declare function OnResourceStart(resource?: string): (originalMethod: any, context: ClassMethodDecoratorContext) => void;
9
+ export declare function OnResourceStart(resource?: ResourceOrGlobal): (originalMethod: any, context: ClassMethodDecoratorContext) => void;
5
10
  /**
6
11
  * Called whenever the specified resource is stopped.
12
+ * NOTE: If you want to listen to *all* resource start/stop events you should send
13
+ * {@link resource} as "global"
7
14
  */
8
- export declare function OnResourceStop(resource?: string): (originalMethod: any, context: ClassMethodDecoratorContext) => void;
15
+ export declare function OnResourceStop(resource?: ResourceOrGlobal): (originalMethod: any, context: ClassMethodDecoratorContext) => void;
16
+ export {};
@@ -7,6 +7,10 @@ class ResourceWrapper {
7
7
  }
8
8
  #on_resource_start = /* @__PURE__ */ new Map();
9
9
  #on_resource_stop = /* @__PURE__ */ new Map();
10
+ // used for global resource/start/stops, callers have to define their listener
11
+ // as "global"
12
+ #global_on_resource_start = [];
13
+ #global_on_resource_stop = [];
10
14
  #add_or_init(resource_fn_map, resource_name, fn) {
11
15
  const fn_array = resource_fn_map.get(resource_name);
12
16
  if (fn_array) {
@@ -21,7 +25,11 @@ class ResourceWrapper {
21
25
  * @param fn The function to call
22
26
  */
23
27
  add_to_resource_start(resource_name, fn) {
24
- this.#add_or_init(this.#on_resource_start, resource_name, fn);
28
+ if (resource_name === "global") {
29
+ this.#global_on_resource_start.push(fn);
30
+ } else {
31
+ this.#add_or_init(this.#on_resource_start, resource_name, fn);
32
+ }
25
33
  }
26
34
  /**
27
35
  * Adds a function to get called whenever a resource is stopped
@@ -29,31 +37,47 @@ class ResourceWrapper {
29
37
  * @param fn The function to call
30
38
  */
31
39
  add_to_resource_stop(resource_name, fn) {
32
- this.#add_or_init(this.#on_resource_stop, resource_name, fn);
40
+ if (resource_name === "global") {
41
+ this.#global_on_resource_stop.push(fn);
42
+ } else {
43
+ this.#add_or_init(this.#on_resource_stop, resource_name, fn);
44
+ }
33
45
  }
34
- #call_for_resource(resource_fn_map, resource_name) {
46
+ #call_for_resource(resource_fn_map, global_array, resource_name) {
35
47
  const functions = resource_fn_map.get(resource_name);
36
48
  if (functions) {
37
49
  for (const fn of functions) {
38
- fn();
50
+ try {
51
+ fn(resource_name);
52
+ } catch (e) {
53
+ }
54
+ }
55
+ }
56
+ for (const fn of global_array) {
57
+ try {
58
+ fn(resource_name);
59
+ } catch (e) {
39
60
  }
40
61
  }
41
62
  }
42
63
  @Event("onResourceStart")
43
64
  on_resource_start(resource_name) {
44
- this.#call_for_resource(this.#on_resource_start, resource_name);
65
+ this.#call_for_resource(this.#on_resource_start, this.#global_on_resource_start, resource_name);
45
66
  }
46
67
  @Event("onResourceStop")
47
68
  on_resource_stop(resource_name) {
48
- this.#call_for_resource(this.#on_resource_stop, resource_name);
69
+ this.#call_for_resource(this.#on_resource_stop, this.#global_on_resource_stop, resource_name);
49
70
  }
50
71
  }
51
- if (!globalThis.RESOURCE_WRAPPER) {
52
- globalThis.RESOURCE_WRAPPER = new ResourceWrapper();
53
- }
72
+ const EnsureResourceWrapperInit = /* @__PURE__ */ __name(() => {
73
+ if (!globalThis.RESOURCE_WRAPPER) {
74
+ globalThis.RESOURCE_WRAPPER = new ResourceWrapper();
75
+ }
76
+ }, "EnsureResourceWrapperInit");
77
+ EnsureResourceWrapperInit();
54
78
  const RESOURCE_WRAPPER = globalThis.RESOURCE_WRAPPER;
55
79
  const onResourceStart = /* @__PURE__ */ __name((resource, originalMethod) => {
56
- if (GetResourceState(resource) === "started") {
80
+ if (resource !== "global" && GetResourceState(resource) === "started") {
57
81
  setImmediate(() => originalMethod.call());
58
82
  }
59
83
  RESOURCE_WRAPPER.add_to_resource_start(resource, originalMethod);
@@ -89,6 +113,7 @@ function OnResourceStop(resource = GetCurrentResourceName()) {
89
113
  }
90
114
  __name(OnResourceStop, "OnResourceStop");
91
115
  export {
116
+ EnsureResourceWrapperInit,
92
117
  OnResourceStart,
93
118
  OnResourceStop
94
119
  };
@@ -1,5 +1,6 @@
1
1
  var __defProp = Object.defineProperty;
2
2
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+ import { ErrorType, GlobalData } from "../GlobalData";
3
4
  function SetTick() {
4
5
  return /* @__PURE__ */ __name(function actualDecorator(originalMethod, context) {
5
6
  if (context.private) {
@@ -7,7 +8,11 @@ function SetTick() {
7
8
  }
8
9
  context.addInitializer(function() {
9
10
  setTick(async () => {
10
- await originalMethod.call(this);
11
+ try {
12
+ await originalMethod.call(this);
13
+ } catch (e) {
14
+ GlobalData.OnError(ErrorType.Tick, e);
15
+ }
11
16
  });
12
17
  });
13
18
  }, "actualDecorator");
@@ -20,7 +25,11 @@ function SetImmediate() {
20
25
  }
21
26
  context.addInitializer(function() {
22
27
  setImmediate(async () => {
23
- await originalMethod.call(this);
28
+ try {
29
+ await originalMethod.call(this);
30
+ } catch (e) {
31
+ GlobalData.OnError(ErrorType.Immediate, e);
32
+ }
24
33
  });
25
34
  });
26
35
  }, "actualDecorator");
@@ -1,4 +1,4 @@
1
- type ChangeListener<V> = (value: V) => void;
1
+ type ChangeListener<V> = (value: V | undefined) => void;
2
2
  /**
3
3
  * not ready to be used just thoughts right now
4
4
  */
@@ -13,7 +13,7 @@ export declare class NetworkedMap<K, V> extends Map<K, V> {
13
13
  hasSubscriber(sub: number): boolean;
14
14
  subscriberCount(): number;
15
15
  private handleSync;
16
- listenForChange(key: K, fn: ChangeListener<V>): void;
16
+ listenForChange(key: K, fn: ChangeListener<V | undefined>): void;
17
17
  set(key: K, value: V): this;
18
18
  clear(): void;
19
19
  delete(key: K): boolean;
@@ -76,7 +76,10 @@ class NetworkedMap extends Map {
76
76
  console.error(`[NetworkedMap:resync] Tried to call resync on a source that wasn't already subscribed`);
77
77
  return;
78
78
  }
79
- const packed_data = msgpack_pack([this.#syncName, [[4 /* Init */, this.size === 0 ? [] : Array.from(this)]]]);
79
+ const packed_data = msgpack_pack([
80
+ this.#syncName,
81
+ [[5 /* Resync */, this.size === 0 ? [] : Array.from(this)]]
82
+ ]);
80
83
  TriggerClientEventInternal(
81
84
  `${GlobalData.CurrentResource}:syncChanges`,
82
85
  source2,
@@ -115,6 +118,13 @@ class NetworkedMap extends Map {
115
118
  super.clear();
116
119
  continue;
117
120
  }
121
+ case 5 /* Resync */: {
122
+ for (const [, v] of this.#changeListeners) {
123
+ for (const fn of v) {
124
+ fn(void 0);
125
+ }
126
+ }
127
+ }
118
128
  case 4 /* Init */: {
119
129
  super.clear();
120
130
  const key_value = key;
@@ -134,6 +144,8 @@ class NetworkedMap extends Map {
134
144
  /*
135
145
  * Listens for the change on the specified key, it will get the resulting
136
146
  * value on the change
147
+ * NOTE: When the server calls `resync` this will get ran with `undefined` for
148
+ * every change listener.
137
149
  */
138
150
  listenForChange(key, fn) {
139
151
  const listener = this.#changeListeners.get(key);
@@ -1,9 +1,9 @@
1
1
  import { Vector3 } from "../../common/utils/Vector";
2
- import type { IHandle } from "./IHandle";
3
- export declare abstract class CommonBaseEntityBone {
2
+ import { IHandle } from "./IHandle";
3
+ export declare abstract class CommonBaseEntityBone extends IHandle {
4
4
  protected readonly owner: IHandle;
5
- protected readonly index: number;
6
- constructor(owner: IHandle, boneIndex?: number, boneName?: string);
5
+ constructor(owner: IHandle, boneInfo: number | string);
6
+ exists(): boolean;
7
7
  get Index(): number;
8
8
  get Owner(): IHandle;
9
9
  get Position(): Vector3;
@@ -1,30 +1,34 @@
1
1
  var __defProp = Object.defineProperty;
2
2
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
3
  import { Vector3 } from "../../common/utils/Vector";
4
- class CommonBaseEntityBone {
4
+ import { IHandle } from "./IHandle";
5
+ class CommonBaseEntityBone extends IHandle {
5
6
  static {
6
7
  __name(this, "CommonBaseEntityBone");
7
8
  }
8
9
  owner;
9
- index;
10
- constructor(owner, boneIndex, boneName) {
10
+ constructor(owner, boneInfo) {
11
+ super(typeof boneInfo === "number" ? boneInfo : GetEntityBoneIndexByName(owner.Handle, boneInfo));
11
12
  this.owner = owner;
12
- this.index = boneIndex ? boneIndex : GetEntityBoneIndexByName(this.owner.Handle, boneName ?? "");
13
+ }
14
+ // overwrite the `IHandle` exists function call
15
+ exists() {
16
+ return this.handle !== -1;
13
17
  }
14
18
  get Index() {
15
- return this.index;
19
+ return this.handle;
16
20
  }
17
21
  get Owner() {
18
22
  return this.owner;
19
23
  }
20
24
  get Position() {
21
- return Vector3.fromArray(GetWorldPositionOfEntityBone(this.owner.Handle, this.index));
25
+ return Vector3.fromArray(GetWorldPositionOfEntityBone(this.owner.Handle, this.handle));
22
26
  }
23
27
  // public get Rotation(): Vector3 {
24
28
  // return Vector3.fromArray(GetEntityBoneRotation(this.owner.Handle, this.index));
25
29
  // }
26
30
  get IsValid() {
27
- return this.owner.exists() && this.index !== -1;
31
+ return this.owner.exists() && this.handle !== -1;
28
32
  }
29
33
  }
30
34
  export {
@@ -5,5 +5,6 @@ export declare abstract class CommonBaseEntityBoneCollection {
5
5
  constructor(owner: IHandle);
6
6
  hasBone(name: string): boolean;
7
7
  abstract getBone(boneIndex?: number, boneName?: string): CommonBaseEntityBone;
8
+ abstract getBoneFromName(boneName: string): CommonBaseEntityBone;
8
9
  abstract get Core(): CommonBaseEntityBone;
9
10
  }
@@ -1,5 +1,5 @@
1
1
  import { CommonBaseEntityBone } from "./CommonBaseEntityBone";
2
2
  import type { IHandle } from "./IHandle";
3
3
  export declare class CommonEntityBone extends CommonBaseEntityBone {
4
- constructor(owner: IHandle, boneIndex?: number, boneName?: string);
4
+ constructor(owner: IHandle, boneIndexOrBoneName: number | string);
5
5
  }
@@ -5,8 +5,8 @@ class CommonEntityBone extends CommonBaseEntityBone {
5
5
  static {
6
6
  __name(this, "CommonEntityBone");
7
7
  }
8
- constructor(owner, boneIndex, boneName) {
9
- super(owner, boneIndex, boneName);
8
+ constructor(owner, boneIndexOrBoneName) {
9
+ super(owner, boneIndexOrBoneName);
10
10
  }
11
11
  }
12
12
  export {
@@ -1,8 +1,11 @@
1
+ import type { CommonBaseEntityBone } from "./CommonBaseEntityBone";
1
2
  import { CommonBaseEntityBoneCollection } from "./CommonBaseEntityBoneCollection";
2
3
  import { CommonEntityBone } from "./CommonEntityBone";
3
4
  import type { IHandle } from "./IHandle";
4
5
  export declare class CommonEntityBoneCollection extends CommonBaseEntityBoneCollection {
5
6
  constructor(owner: IHandle);
7
+ getBoneFromName(boneName: string): CommonBaseEntityBone;
8
+ getBoneFromIndex(boneIndex: number): CommonBaseEntityBone;
6
9
  getBone(boneIndex: number): CommonEntityBone;
7
10
  getBone(boneName: string): CommonEntityBone;
8
11
  get Core(): CommonEntityBone;
@@ -9,6 +9,12 @@ class CommonEntityBoneCollection extends CommonBaseEntityBoneCollection {
9
9
  constructor(owner) {
10
10
  super(owner);
11
11
  }
12
+ getBoneFromName(boneName) {
13
+ return new CommonEntityBone(this.owner, GetEntityBoneIndexByName(this.owner.Handle, boneName));
14
+ }
15
+ getBoneFromIndex(boneIndex) {
16
+ return new CommonEntityBone(this.owner, boneIndex);
17
+ }
12
18
  getBone(bone) {
13
19
  return new CommonEntityBone(
14
20
  this.owner,
@@ -1,6 +1,6 @@
1
1
  import { CommonBaseEntityBone } from "./CommonBaseEntityBone";
2
2
  import type { IHandle } from "./IHandle";
3
3
  export declare class CommonPedBone extends CommonBaseEntityBone {
4
- constructor(owner: IHandle, boneId: number);
4
+ constructor(owner: IHandle, boneIndex: number);
5
5
  get IsValid(): boolean;
6
6
  }
@@ -5,8 +5,8 @@ class CommonPedBone extends CommonBaseEntityBone {
5
5
  static {
6
6
  __name(this, "CommonPedBone");
7
7
  }
8
- constructor(owner, boneId) {
9
- super(owner, GetPedBoneIndex(owner.Handle, Number(boneId)));
8
+ constructor(owner, boneIndex) {
9
+ super(owner, boneIndex);
10
10
  }
11
11
  get IsValid() {
12
12
  return this.Owner.exists() && this.Index !== -1;
@@ -6,5 +6,8 @@ export declare class CommonPedBoneCollection extends CommonBaseEntityBoneCollect
6
6
  get Core(): CommonPedBone;
7
7
  get LastDamaged(): CommonPedBone;
8
8
  clearLastDamaged(): void;
9
- getBone(boneIndex?: number, boneName?: string): CommonPedBone;
9
+ getBoneFromId(boneId: number): CommonPedBone;
10
+ getBoneFromName(boneName: string): CommonPedBone;
11
+ getBone(boneIndex: number): CommonPedBone;
12
+ getBone(boneName: string): CommonPedBone;
10
13
  }
@@ -19,10 +19,16 @@ class CommonPedBoneCollection extends CommonBaseEntityBoneCollection {
19
19
  clearLastDamaged() {
20
20
  ClearPedLastDamageBone(this.owner.Handle);
21
21
  }
22
- getBone(boneIndex, boneName) {
22
+ getBoneFromId(boneId) {
23
+ return new CommonPedBone(this.owner, GetPedBoneIndex(this.owner.Handle, boneId));
24
+ }
25
+ getBoneFromName(boneName) {
26
+ return new CommonPedBone(this.owner, GetEntityBoneIndexByName(this.owner.Handle, boneName));
27
+ }
28
+ getBone(bone) {
23
29
  return new CommonPedBone(
24
30
  this.owner,
25
- boneIndex ? boneIndex : GetEntityBoneIndexByName(this.owner.Handle, boneName ?? "")
31
+ typeof bone === "number" ? bone : GetEntityBoneIndexByName(this.owner.Handle, bone ?? "")
26
32
  );
27
33
  }
28
34
  }
package/index.d.ts CHANGED
@@ -16,6 +16,7 @@ export * from "./Rope";
16
16
  export * from "./TaskSequence";
17
17
  export * from "./Tasks";
18
18
  export * from "./World";
19
+ export * from "./world/getGamePool";
19
20
  export * from "./weaponComponent/ComponentAttachmentPoint";
20
21
  export * from "./weaponComponent/ComponentAttachmentPointByHash";
21
22
  export * from "./weaponComponent/ComponentDisplayNameByHash";
@@ -171,6 +172,7 @@ export * from "./common-game/definitions/index.d";
171
172
  export * from "./common-game/definitions/redm.d";
172
173
  export * from "./common-game/cfx/StateBagChangeHandler";
173
174
  export * from "./common-game/cfx/cfx";
175
+ export * from "./common/BaseScript";
174
176
  export * from "./common/Command";
175
177
  export * from "./common/Convar";
176
178
  export * from "./common/GlobalData";
@@ -197,5 +199,7 @@ export * from "./common/decors/Exports";
197
199
  export * from "./common/decors/Permissions";
198
200
  export * from "./common/decors/Resources";
199
201
  export * from "./common/decors/Ticks";
202
+ export * from "./common/collections/CircularBuffer";
203
+ export * from "./common/collections/Stack";
200
204
  export * from "./cfx/StateBagChangeHandler";
201
205
  export * from "./cfx/index";
package/index.js CHANGED
@@ -16,6 +16,7 @@ export * from "./Rope";
16
16
  export * from "./TaskSequence";
17
17
  export * from "./Tasks";
18
18
  export * from "./World";
19
+ export * from "./world/getGamePool";
19
20
  export * from "./weaponComponent/ComponentAttachmentPoint";
20
21
  export * from "./weaponComponent/ComponentAttachmentPointByHash";
21
22
  export * from "./weaponComponent/ComponentDisplayNameByHash";
@@ -171,6 +172,7 @@ export * from "./common-game/definitions/index.d";
171
172
  export * from "./common-game/definitions/redm.d";
172
173
  export * from "./common-game/cfx/StateBagChangeHandler";
173
174
  export * from "./common-game/cfx/cfx";
175
+ export * from "./common/BaseScript";
174
176
  export * from "./common/Command";
175
177
  export * from "./common/Convar";
176
178
  export * from "./common/GlobalData";
@@ -197,5 +199,7 @@ export * from "./common/decors/Exports";
197
199
  export * from "./common/decors/Permissions";
198
200
  export * from "./common/decors/Resources";
199
201
  export * from "./common/decors/Ticks";
202
+ export * from "./common/collections/CircularBuffer";
203
+ export * from "./common/collections/Stack";
200
204
  export * from "./cfx/StateBagChangeHandler";
201
205
  export * from "./cfx/index";
package/package.json CHANGED
@@ -8,7 +8,7 @@
8
8
  ],
9
9
  "license": "MIT",
10
10
  "type": "module",
11
- "version": "0.0.136",
11
+ "version": "0.0.138",
12
12
  "repository": {
13
13
  "type": "git",
14
14
  "url": "https://github.com/nativewrappers/nativewrappers.git"
@@ -0,0 +1,14 @@
1
+ import { Pickup } from "../Pickup";
2
+ import { Ped, Prop, Vehicle } from "../models";
3
+ declare const constructorMap: {
4
+ CObject: typeof Prop;
5
+ CPed: typeof Ped;
6
+ CVehicle: typeof Vehicle;
7
+ CPickup: typeof Pickup;
8
+ CNetObject: typeof Prop;
9
+ };
10
+ type PoolTypeMap = {
11
+ [K in keyof typeof constructorMap]: InstanceType<(typeof constructorMap)[K]>;
12
+ };
13
+ export declare function getGamePool<T extends keyof typeof constructorMap>(type: T, networkOnly?: boolean): PoolTypeMap[T][];
14
+ export {};
@@ -0,0 +1,30 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+ import { Pickup } from "../Pickup";
4
+ import { BaseEntity, Ped, Prop, Vehicle } from "../models";
5
+ const constructorMap = {
6
+ CObject: Prop,
7
+ CPed: Ped,
8
+ CVehicle: Vehicle,
9
+ CPickup: Pickup,
10
+ CNetObject: Prop
11
+ };
12
+ function getGamePool(type, networkOnly = false) {
13
+ const pool = GetGamePool(type);
14
+ const entityConstructor = constructorMap[type];
15
+ let poolMap = pool.map((v) => {
16
+ const p = new entityConstructor(v);
17
+ if (networkOnly && !p.IsNetworked) {
18
+ return null;
19
+ }
20
+ return p;
21
+ });
22
+ if (networkOnly) {
23
+ poolMap = poolMap.filter((v) => v !== null);
24
+ }
25
+ return poolMap;
26
+ }
27
+ __name(getGamePool, "getGamePool");
28
+ export {
29
+ getGamePool
30
+ };