@nativewrappers/redm 0.0.94 → 0.0.96

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.
@@ -1,17 +1,31 @@
1
- import type { Ped } from "./Ped";
1
+ import { Ped } from "./Ped";
2
2
  export declare class Player {
3
3
  private handle;
4
+ static AllPlayers(excludeLocalPlayer?: boolean): IterableIterator<Player>;
4
5
  static fromPedHandle(handle: number): Player;
5
6
  /**
6
7
  * Gets the player from the specified {@param serverId}
7
8
  * @returns the player object, or null if the player didn't exist
8
9
  */
9
10
  static fromServerId(serverId: number): Player | null;
11
+ /**
12
+ * @param [minimumDistance=Number.MAX_VALUE] the minimum distance this should check
13
+ * @param [fromPlayer=GameConstants.Player] the player to get the distance from
14
+ * @returns the closest player from {@param fromPlayer} and the distance the player was
15
+ */
16
+ static getClosestPlayerPedWithDistance(minimumDistance?: number, fromPlayer?: Player): [Ped | null, number];
17
+ /**
18
+ * @param [minimumDistance=Number.MAX_VALUE] the minimum distance this should check
19
+ * @param [fromPlayer=GameConstants.Player] the player to get the distance from
20
+ * @returns the closest player from {@param fromPlayer} and the distance the player was
21
+ */
22
+ static getClosestPlayerPed(minimumDistance?: number, fromPlayer?: Player): Ped | null;
10
23
  /**
11
24
  * @param handle the player handle
12
25
  */
13
26
  constructor(handle: number);
14
27
  get Handle(): number;
28
+ get Ped(): Ped;
15
29
  /**
16
30
  * Adds the amount of stamina player has on the hud
17
31
  * @param amount the amount of upgrade to give 6 is half the bar while 12 is the full bar
@@ -2,6 +2,7 @@ var __defProp = Object.defineProperty;
2
2
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
3
  import { GameConstants } from "../GameConstants";
4
4
  import { _N } from "../utils/Native";
5
+ import { Ped } from "./Ped";
5
6
  const handleUpgrade = /* @__PURE__ */ __name((name, amount) => {
6
7
  const b1 = new ArrayBuffer(8 * 24);
7
8
  const a2 = new DataView(b1);
@@ -14,6 +15,14 @@ class Player {
14
15
  __name(this, "Player");
15
16
  }
16
17
  handle;
18
+ static *AllPlayers(excludeLocalPlayer = true) {
19
+ for (const ply of GetActivePlayers()) {
20
+ if (excludeLocalPlayer && ply === GameConstants.PlayerId) {
21
+ continue;
22
+ }
23
+ yield new Player(ply);
24
+ }
25
+ }
17
26
  static fromPedHandle(handle) {
18
27
  return new Player(NetworkGetPlayerIndexFromPed(handle));
19
28
  }
@@ -29,6 +38,34 @@ class Player {
29
38
  if (player === -1) return null;
30
39
  return new Player(player);
31
40
  }
41
+ /**
42
+ * @param [minimumDistance=Number.MAX_VALUE] the minimum distance this should check
43
+ * @param [fromPlayer=GameConstants.Player] the player to get the distance from
44
+ * @returns the closest player from {@param fromPlayer} and the distance the player was
45
+ */
46
+ static getClosestPlayerPedWithDistance(minimumDistance = Number.MAX_VALUE, fromPlayer = GameConstants.Player) {
47
+ const ped = fromPlayer.Ped;
48
+ const pos = ped.Position;
49
+ const data = [null, Number.MAX_VALUE];
50
+ for (const ply of Player.AllPlayers(true)) {
51
+ const tgtPed = ply.Ped;
52
+ const dist = pos.distance(tgtPed.Position);
53
+ if (dist < data[1] && dist < minimumDistance) {
54
+ data[0] = tgtPed;
55
+ data[1] = dist;
56
+ }
57
+ }
58
+ return data;
59
+ }
60
+ /**
61
+ * @param [minimumDistance=Number.MAX_VALUE] the minimum distance this should check
62
+ * @param [fromPlayer=GameConstants.Player] the player to get the distance from
63
+ * @returns the closest player from {@param fromPlayer} and the distance the player was
64
+ */
65
+ static getClosestPlayerPed(minimumDistance = Number.MAX_VALUE, fromPlayer = GameConstants.Player) {
66
+ const data = this.getClosestPlayerPedWithDistance(minimumDistance, fromPlayer);
67
+ return data[0];
68
+ }
32
69
  /**
33
70
  * @param handle the player handle
34
71
  */
@@ -38,6 +75,9 @@ class Player {
38
75
  get Handle() {
39
76
  return this.handle;
40
77
  }
78
+ get Ped() {
79
+ return new Ped(GetPlayerPed(this.handle));
80
+ }
41
81
  /**
42
82
  * Adds the amount of stamina player has on the hud
43
83
  * @param amount the amount of upgrade to give 6 is half the bar while 12 is the full bar
package/package.json CHANGED
@@ -8,7 +8,7 @@
8
8
  ],
9
9
  "license": "MIT",
10
10
  "type": "module",
11
- "version": "0.0.94",
11
+ "version": "0.0.96",
12
12
  "repository": {
13
13
  "type": "git",
14
14
  "url": "https://github.com/nativewrappers/nativewrappers.git"