forked from soler91/box-opener
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
98 lines (83 loc) · 1.97 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
const Command = require('command');
module.exports = function boxOpener(dispatch){
const command = Command(dispatch)
let cid = null,
enabled = false,
location = null,
timer = null,
scanning = false;
boxId = 166901, // MWA box as default.
inventory = null;
command.add('getbox', () => {
scanning = true;
command.message('Please open the box you wish to set.');
});
command.add('openbox', () => {
if(!enabled){
command.message('Opening selected box, use the same command to stop.');
timer = setInterval(openBox,200)
}
});
command.add('stopbox', () => {
clearInterval(timer)
enabled = false
inventory = null
command.message('Box opener stopped.')
});
dispatch.hook('S_LOGIN', 1, event =>{cid = event.cid});
dispatch.hook('C_PLAYER_LOCATION', 1, event =>{location = event});
dispatch.hook('S_INVEN', 5, event =>{
if(!enabled) return
if(event.first) inventory = []
else if(!inventory) return
for(let item of event.items) inventory.push(item)
if(!event.more) {
let box = false
for(let item of inventory) {
if(item.slot < 40) continue
if(item.item == boxId) box = true
}
if(!box) stop()
inventory = null
}
});
dispatch.hook('C_USE_ITEM', 1, event =>{
if(!scanning) return
if(scanning){
boxId = event.item;
command.message('Box set to: '+boxId+' If this is not a box try again.');
scanning = false;
}
});
function openBox() {
dispatch.toServer('C_USE_ITEM', 1, {
ownerId: cid,
item: boxId,
id: 0,
unk1: 0,
unk2: 0,
unk3: 0,
unk4: 1,
unk5: 0,
unk6: 0,
unk7: 0,
x: location.x1,
y: location.y1,
z: location.z1,
w: location.w,
unk8: 0,
unk9: 0,
unk10: 0,
unk11: 1
})
dispatch.toServer('C_GACHA_TRY', 1,{
id:385851
})
}
function stop() {
clearInterval(timer)
enabled = false
inventory = null
command.message('Box opener stopped.')
}
}