@nativewrappers/server 0.0.130 → 0.0.132

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/Game.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- import { Player } from "./entities/Player";
2
1
  export declare abstract class Game {
3
2
  static hashCache: Map<string, number>;
4
3
  /**
@@ -13,13 +12,7 @@ export declare abstract class Game {
13
12
  static get GameTime(): number;
14
13
  static get GameBuild(): number;
15
14
  static get GameName(): string;
16
- static registerCommand(name: string, handler: (player: Player, args: any[]) => void, restricted?: boolean): void;
17
15
  static get RegisteredCommands(): [{
18
16
  name: string;
19
17
  }];
20
- /**
21
- * Get an iterable list of players currently on the server.
22
- * @returns Iterable list of Player objects.
23
- */
24
- static PlayerList(): IterableIterator<Player>;
25
18
  }
package/Game.js CHANGED
@@ -1,5 +1,6 @@
1
1
  var __defProp = Object.defineProperty;
2
2
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+ import { Delay } from "./common/utils/Delay";
3
4
  import { Player } from "./entities/Player";
4
5
  class Game {
5
6
  static {
@@ -34,28 +35,9 @@ class Game {
34
35
  static get GameName() {
35
36
  return GetGameName();
36
37
  }
37
- static registerCommand(name, handler, restricted = false) {
38
- RegisterCommand(
39
- name,
40
- (source, args) => {
41
- const player = new Player(Number.parseInt(source));
42
- handler(player, args);
43
- },
44
- restricted
45
- );
46
- }
47
38
  static get RegisteredCommands() {
48
39
  return GetRegisteredCommands();
49
40
  }
50
- /**
51
- * Get an iterable list of players currently on the server.
52
- * @returns Iterable list of Player objects.
53
- */
54
- static *PlayerList() {
55
- for (const id of getPlayers()) {
56
- yield new Player(id);
57
- }
58
- }
59
41
  }
60
42
  export {
61
43
  Game
package/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from "./Game";
2
+ export * from "./utils/waitForEntityToExist";
2
3
  export * from "./type/Anticheat";
3
4
  export * from "./type/Hash";
4
5
  export * from "./enum/OrphanMode";
package/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from "./Game";
2
+ export * from "./utils/waitForEntityToExist";
2
3
  export * from "./type/Anticheat";
3
4
  export * from "./type/Hash";
4
5
  export * from "./enum/OrphanMode";
package/package.json CHANGED
@@ -8,7 +8,7 @@
8
8
  ],
9
9
  "license": "MIT",
10
10
  "type": "module",
11
- "version": "0.0.130",
11
+ "version": "0.0.132",
12
12
  "repository": {
13
13
  "type": "git",
14
14
  "url": "https://github.com/nativewrappers/nativewrappers.git"
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Waits for the specified {@param netId} to exist, useful for when you're creating an entity on the client
3
+ * ane sending it to the server, as it can "race" the net event, resulting in it never getting created.
4
+ * @param netId the network id of the entity to wait to exist
5
+ * @param [timeoutMs=1000] the amount of time to wait for the entity to exist before giving up
6
+ */
7
+ export declare function waitForEntityToExist(netId: number, timeoutMs?: number): Promise<number | null>;
@@ -0,0 +1,19 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+ import { Delay } from "../common/utils/Delay";
4
+ async function waitForEntityToExist(netId, timeoutMs = 1e3) {
5
+ const startTime = GetGameTimer();
6
+ const timeout = startTime + timeoutMs;
7
+ while (GetGameTimer() < timeout) {
8
+ const entity = NetworkGetEntityFromNetworkId(netId);
9
+ if (entity !== 0) {
10
+ return entity;
11
+ }
12
+ await Delay(0);
13
+ }
14
+ return null;
15
+ }
16
+ __name(waitForEntityToExist, "waitForEntityToExist");
17
+ export {
18
+ waitForEntityToExist
19
+ };