@nativewrappers/fivem 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.
@@ -10,8 +10,21 @@ export declare class Player {
10
10
  private stateBagCookies;
11
11
  private source;
12
12
  private type;
13
+ static AllPlayers(excludeLocalPlayer?: boolean): IterableIterator<Player>;
13
14
  static fromPedHandle(handle: number): Player;
14
15
  static fromServerId(serverId: number): Player;
16
+ /**
17
+ * @param [minimumDistance=Number.MAX_VALUE] the minimum distance this should check
18
+ * @param [fromPlayer=GameConstants.Player] the player to get the distance from
19
+ * @returns the closest player from {@param fromPlayer} and the distance the player was
20
+ */
21
+ static getClosestPlayerPedWithDistance(minimumDistance?: number, fromPlayer?: Player): [Ped | null, number];
22
+ /**
23
+ * @param [minimumDistance=Number.MAX_VALUE] the minimum distance this should check
24
+ * @param [fromPlayer=GameConstants.Player] the player to get the distance from
25
+ * @returns the closest player from {@param fromPlayer} and the distance the player was
26
+ */
27
+ static getClosestPlayerPed(minimumDistance?: number, fromPlayer?: Player): Ped | null;
15
28
  /**
16
29
  * @param handle the player handle, or if on the server, their source.
17
30
  */
package/models/Player.js CHANGED
@@ -2,6 +2,7 @@ var __defProp = Object.defineProperty;
2
2
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
3
  import { ClassTypes } from "../common/utils/ClassTypes";
4
4
  import { Color } from "../common/utils/Color";
5
+ import { GameConstants } from "../GameConstants";
5
6
  import { Model } from "../Model";
6
7
  import { GetEntityClassFromId } from "../utils/GetEntityFromEntityIds";
7
8
  import cfx, {} from "../cfx";
@@ -16,12 +17,48 @@ class Player {
16
17
  stateBagCookies = [];
17
18
  source;
18
19
  type = ClassTypes.Player;
20
+ static *AllPlayers(excludeLocalPlayer = true) {
21
+ for (const ply of GetActivePlayers()) {
22
+ if (excludeLocalPlayer && ply === GameConstants.PlayerId) {
23
+ continue;
24
+ }
25
+ yield new Player(ply);
26
+ }
27
+ }
19
28
  static fromPedHandle(handle) {
20
29
  return new Player(NetworkGetPlayerIndexFromPed(handle));
21
30
  }
22
31
  static fromServerId(serverId) {
23
32
  return new Player(GetPlayerFromServerId(serverId));
24
33
  }
34
+ /**
35
+ * @param [minimumDistance=Number.MAX_VALUE] the minimum distance this should check
36
+ * @param [fromPlayer=GameConstants.Player] the player to get the distance from
37
+ * @returns the closest player from {@param fromPlayer} and the distance the player was
38
+ */
39
+ static getClosestPlayerPedWithDistance(minimumDistance = Number.MAX_VALUE, fromPlayer = GameConstants.Player) {
40
+ const ped = fromPlayer.Ped;
41
+ const pos = ped.Position;
42
+ const data = [null, Number.MAX_VALUE];
43
+ for (const ply of Player.AllPlayers(true)) {
44
+ const tgtPed = ply.Ped;
45
+ const dist = pos.distance(tgtPed.Position);
46
+ if (dist < data[1] && dist < minimumDistance) {
47
+ data[0] = tgtPed;
48
+ data[1] = dist;
49
+ }
50
+ }
51
+ return data;
52
+ }
53
+ /**
54
+ * @param [minimumDistance=Number.MAX_VALUE] the minimum distance this should check
55
+ * @param [fromPlayer=GameConstants.Player] the player to get the distance from
56
+ * @returns the closest player from {@param fromPlayer} and the distance the player was
57
+ */
58
+ static getClosestPlayerPed(minimumDistance = Number.MAX_VALUE, fromPlayer = GameConstants.Player) {
59
+ const data = this.getClosestPlayerPedWithDistance(minimumDistance, fromPlayer);
60
+ return data[0];
61
+ }
25
62
  /**
26
63
  * @param handle the player handle, or if on the server, their source.
27
64
  */
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"