forked from soler91/Anti-Bodyblock
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
102 lines (91 loc) · 2.98 KB
/
index.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
module.exports = function antiBodyBlock(mod) {
let timerInterval = null;
let partyMembers = [];
let enabled = true;
mod.game.initialize('me');
mod.game.initialize('party');
const removeUser = (e) => {
if (!partyMembers.length) { return; }
let idx = partyMembers.findIndex((x) => x.playerId === e.playerId && x.serverId === e.serverId);
if (idx > -1) { partyMembers.splice(idx, 1); }
};
mod.game.party.on('leave', () => {
partyMembers = [];
});
mod.game.party.on('member_kick', removeUser);
mod.game.party.on('member_leave', removeUser);
/*mod.hook('S_PARTY_INFO', 2, (event) => {
console.log('S_PARTY_INFO > gameId: ' + event.gameId + ', partyId: ' + event.partyId + ', raid: ' + event.raid);
});*/
const removeBodyBlock = () => {
if (!partyMembers.length) { return; }
if (!enabled) { return; }
if (mod.game.me.inDungeon && mod.game.party.inParty) {
partyMembers.forEach((mem) => {
if (mem.online) {
if (mem.gameId == 0) { return; }
//console.log('abb > gameId: ' + mem.gameId + ', partyId: ' + mem.partyId);
mod.send('S_PARTY_INFO', 2, {
gameId: mem.gameId,
partyId: mem.partyId,
raid: true,
});
}
});
}
};
mod.hook('S_LOGIN', 15, (event) => {
partyMembers = [];
mod.clearAllIntervals();
timerInterval = mod.setInterval(removeBodyBlock, 5000);
});
mod.hook('S_PARTY_MEMBER_LIST', 9, (event) => {
if (event.raid) { return; }
let idx = -1, gId = -1n;
event.members.forEach((mem) => {
idx = partyMembers.findIndex((x) => x.playerId === mem.playerId && x.serverId === mem.serverId);
if (idx === -1) {
gId = mem.gameId;
if (gId === 0n) {
if (mod.game.me.playerId === mem.playerId && mod.game.me.serverId === mem.serverId) {
gId = mod.game.me.gameId;
}
}
partyMembers.push({
gameId: gId,
playerId: mem.playerId,
serverId: mem.serverId,
online: mem.online,
partyId: event.id,
});
}
});
});
mod.hook('S_SPAWN_USER', 17, (event) => {
let n = partyMembers.length;
if (!n) { return; }
for (let i = 0; i < n; i++) {
if (partyMembers[i].playerId === event.playerId && partyMembers[i].serverId === event.serverId) {
partyMembers[i].gameId = event.gameId;
partyMembers[i].online = true;
}
}
});
mod.hook('S_LOGOUT_PARTY_MEMBER', 1, (event) => {
let n = partyMembers.length;
if (!n) { return; }
for (let i = 0; i < n; i++) {
if (partyMembers[i].playerId === event.playerId && partyMembers[i].serverId === event.serverId) {
partyMembers[i].online = false;
}
}
});
mod.command.add('abb', () => {
enabled = !enabled;
mod.clearAllIntervals();
if (enabled) {
timerInterval = mod.setInterval(removeBodyBlock, 5000);
}
mod.command.message('Anti-bodyblock: ' + (enabled ? 'enabled.' : 'disabled.'));
});
};