@nativewrappers/server 0.0.166 → 0.0.168
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/PlayerList.d.ts +13 -0
- package/PlayerList.js +27 -0
- package/entities/Player.d.ts +15 -1
- package/entities/Player.js +21 -2
- package/game/generateHash.d.ts +4 -0
- package/game/generateHash.js +9 -0
- package/index.d.ts +2 -0
- package/index.js +2 -0
- package/package.json +1 -1
package/PlayerList.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Player } from "./entities/Player";
|
|
2
|
+
export type PlayerMap = Map<number, Player>;
|
|
3
|
+
/**
|
|
4
|
+
* A static helper class that will automatically handle adding/removing players from
|
|
5
|
+
* a shared player map.
|
|
6
|
+
*
|
|
7
|
+
* This should be preferred over using constant calls to `getPlayers` since it will
|
|
8
|
+
* have marginally less overhead
|
|
9
|
+
*/
|
|
10
|
+
export declare class PlayerList {
|
|
11
|
+
private static playerMap;
|
|
12
|
+
static get AllPlayers(): Readonly<PlayerMap>;
|
|
13
|
+
}
|
package/PlayerList.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
import { Player } from "./entities/Player";
|
|
4
|
+
class PlayerList {
|
|
5
|
+
static {
|
|
6
|
+
__name(this, "PlayerList");
|
|
7
|
+
}
|
|
8
|
+
static playerMap = /* @__PURE__ */ new Map();
|
|
9
|
+
static {
|
|
10
|
+
for (const srcStr of getPlayers()) {
|
|
11
|
+
const src = parseInt(srcStr, 10);
|
|
12
|
+
PlayerList.playerMap.set(src, new Player(src));
|
|
13
|
+
}
|
|
14
|
+
on("playerJoining", () => {
|
|
15
|
+
PlayerList.playerMap.set(source, new Player(source));
|
|
16
|
+
});
|
|
17
|
+
on("playerDropped", () => {
|
|
18
|
+
PlayerList.playerMap.delete(source);
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
static get AllPlayers() {
|
|
22
|
+
return PlayerList.playerMap;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
export {
|
|
26
|
+
PlayerList
|
|
27
|
+
};
|
package/entities/Player.d.ts
CHANGED
|
@@ -4,10 +4,17 @@ import { Ped } from "./Ped";
|
|
|
4
4
|
export declare class Player {
|
|
5
5
|
private readonly source;
|
|
6
6
|
protected type: ClassTypes;
|
|
7
|
+
protected ped: Ped | null;
|
|
7
8
|
constructor(source: any);
|
|
8
9
|
static fromServerId(serverId: number): Player | null;
|
|
9
10
|
/**
|
|
10
11
|
* Get an interable list of players currently on the server
|
|
12
|
+
*
|
|
13
|
+
* You should generally prefer to use {@see PlayerList} for this if you're
|
|
14
|
+
* frequently doing this call, since it has less overhead, as it doesn't have
|
|
15
|
+
* to iterate over the entire player list every time, and it doesn't have to
|
|
16
|
+
* create a new player object
|
|
17
|
+
*
|
|
11
18
|
* @returns Iterable list of Players.
|
|
12
19
|
*/
|
|
13
20
|
static AllPlayers(): IterableIterator<Player>;
|
|
@@ -23,7 +30,14 @@ export declare class Player {
|
|
|
23
30
|
* Returns the player source casted as a string
|
|
24
31
|
*/
|
|
25
32
|
get Src(): string;
|
|
26
|
-
|
|
33
|
+
/**
|
|
34
|
+
* Gets the players ped, this is only ever set once, so subsequent calls will be
|
|
35
|
+
* cached
|
|
36
|
+
*
|
|
37
|
+
* Due to the fact that the ped doesn't exist at `playerJoining` this can be
|
|
38
|
+
* `null`
|
|
39
|
+
*/
|
|
40
|
+
get Ped(): Ped | null;
|
|
27
41
|
get Tokens(): string[];
|
|
28
42
|
get Identifiers(): string[];
|
|
29
43
|
get Endpoint(): string;
|
package/entities/Player.js
CHANGED
|
@@ -13,6 +13,7 @@ class Player {
|
|
|
13
13
|
__name(this, "Player");
|
|
14
14
|
}
|
|
15
15
|
type = ClassTypes.Player;
|
|
16
|
+
ped = null;
|
|
16
17
|
static fromServerId(serverId) {
|
|
17
18
|
if (!DoesPlayerExist(serverId)) {
|
|
18
19
|
return null;
|
|
@@ -21,6 +22,12 @@ class Player {
|
|
|
21
22
|
}
|
|
22
23
|
/**
|
|
23
24
|
* Get an interable list of players currently on the server
|
|
25
|
+
*
|
|
26
|
+
* You should generally prefer to use {@see PlayerList} for this if you're
|
|
27
|
+
* frequently doing this call, since it has less overhead, as it doesn't have
|
|
28
|
+
* to iterate over the entire player list every time, and it doesn't have to
|
|
29
|
+
* create a new player object
|
|
30
|
+
*
|
|
24
31
|
* @returns Iterable list of Players.
|
|
25
32
|
*/
|
|
26
33
|
static *AllPlayers() {
|
|
@@ -51,9 +58,21 @@ class Player {
|
|
|
51
58
|
get Src() {
|
|
52
59
|
return this.source;
|
|
53
60
|
}
|
|
61
|
+
/**
|
|
62
|
+
* Gets the players ped, this is only ever set once, so subsequent calls will be
|
|
63
|
+
* cached
|
|
64
|
+
*
|
|
65
|
+
* Due to the fact that the ped doesn't exist at `playerJoining` this can be
|
|
66
|
+
* `null`
|
|
67
|
+
*/
|
|
54
68
|
get Ped() {
|
|
55
|
-
|
|
56
|
-
|
|
69
|
+
if (!this.ped) {
|
|
70
|
+
const ped = GetPlayerPed(this.source);
|
|
71
|
+
if (ped !== 0) {
|
|
72
|
+
this.ped = new Ped(GetPlayerPed(this.source));
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return this.ped;
|
|
57
76
|
}
|
|
58
77
|
get Tokens() {
|
|
59
78
|
return getPlayerTokens(this.source);
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
function generateHash(str) {
|
|
4
|
+
return GetHashKey(str) & 4294967295;
|
|
5
|
+
}
|
|
6
|
+
__name(generateHash, "generateHash");
|
|
7
|
+
export {
|
|
8
|
+
generateHash
|
|
9
|
+
};
|
package/index.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
export * from "./Game";
|
|
2
|
+
export * from "./PlayerList";
|
|
2
3
|
export * from "./utils/waitForEntityToExist";
|
|
3
4
|
export * from "./type/Anticheat";
|
|
4
5
|
export * from "./type/Hash";
|
|
6
|
+
export * from "./game/generateHash";
|
|
5
7
|
export * from "./enum/OrphanMode";
|
|
6
8
|
export * from "./enum/PopulationType";
|
|
7
9
|
export * from "./enum/VehicleLockStatus";
|
package/index.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
export * from "./Game";
|
|
2
|
+
export * from "./PlayerList";
|
|
2
3
|
export * from "./utils/waitForEntityToExist";
|
|
3
4
|
export * from "./type/Anticheat";
|
|
4
5
|
export * from "./type/Hash";
|
|
6
|
+
export * from "./game/generateHash";
|
|
5
7
|
export * from "./enum/OrphanMode";
|
|
6
8
|
export * from "./enum/PopulationType";
|
|
7
9
|
export * from "./enum/VehicleLockStatus";
|