-
-
Notifications
You must be signed in to change notification settings - Fork 38
/
wrapper.js
46 lines (35 loc) · 1.47 KB
/
wrapper.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
const log = require("simple-console-logger").getLogger("LiveMap Wrapper");
const EventsWrapper = (SocketController) => {
const setStaticData = (source, id) => {
SocketController.AddPlayerData(id, "identifer", id); // I miss spelt this previously..
SocketController.AddPlayerData(id, "name", GetPlayerName(source));
};
onNet("onResourceStart", (name) => {
if (name == GetCurrentResourceName()){
if (GetNumPlayerIndices() !== 0){
log.info("Players on the server... Initialising them");
for(let i = 0; i < GetNumPlayerIndices(); i++){
const id = GetPlayerIdentifier(GetPlayerFromIndex(i), 0);
setStaticData(GetPlayerFromIndex(i), id);
}
}
}
});
onNet("livemap:playerSpawned", () => {
setStaticData(source, GetPlayerIdentifier(source));
});
onNet("livemap:AddPlayerData", (k, d) => {
SocketController.AddPlayerData(GetPlayerIdentifier(source, 0), k, d);
});
onNet("livemap:UpdatePlayerData", (k, d) => {
SocketController.UpdatePlayerData(GetPlayerIdentifier(source, 0), k, d);
});
onNet("livemap:RemovePlayerData", (k) => {
SocketController.RemovePlayerData(GetPlayerIdentifier(source, 0), k);
});
onNet("livemap:RemovePlayer", () => {
SocketController.RemovePlayer(GetPlayerIdentifier(source, 0));
});
return {};
};
module.exports = EventsWrapper;