index.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. const Command = require('command');
  2. module.exports = function boxOpener(dispatch){
  3. const command = Command(dispatch)
  4. let cid = null,
  5. enabled = false,
  6. location = null,
  7. timer = null,
  8. scanning = false;
  9. boxId = 166901, // MWA box as default.
  10. inventory = null;
  11. command.add('getbox', () => {
  12. scanning = true;
  13. command.message('Please open the box you wish to set.');
  14. });
  15. command.add('openbox', () => {
  16. if(!enabled){
  17. command.message('Opening selected box, use the same command to stop.');
  18. timer = setInterval(openBox,200)
  19. }
  20. });
  21. command.add('stopbox', () => {
  22. clearInterval(timer)
  23. enabled = false
  24. inventory = null
  25. command.message('Box opener stopped.')
  26. });
  27. dispatch.hook('S_LOGIN', 1, event =>{cid = event.cid});
  28. dispatch.hook('C_PLAYER_LOCATION', 1, event =>{location = event});
  29. dispatch.hook('S_INVEN', 4, event =>{ //Change this to 5 if EU
  30. if(!enabled) return
  31. if(event.first) inventory = []
  32. else if(!inventory) return
  33. for(let item of event.items) inventory.push(item)
  34. if(!event.more) {
  35. let box = false
  36. for(let item of inventory) {
  37. if(item.slot < 40) continue
  38. if(item.item == boxId) box = true
  39. }
  40. if(!box) stop()
  41. inventory = null
  42. }
  43. });
  44. dispatch.hook('C_USE_ITEM', 1, event =>{
  45. if(!scanning) return
  46. if(scanning){
  47. boxId = event.item;
  48. command.message('Box set to: '+boxId+' If this is not a box try again.');
  49. scanning = false;
  50. }
  51. });
  52. function openBox() {
  53. dispatch.toServer('C_USE_ITEM', 1, {
  54. ownerId: cid,
  55. item: boxId,
  56. id: 0,
  57. unk1: 0,
  58. unk2: 0,
  59. unk3: 0,
  60. unk4: 1,
  61. unk5: 0,
  62. unk6: 0,
  63. unk7: 0,
  64. x: location.x1,
  65. y: location.y1,
  66. z: location.z1,
  67. w: location.w,
  68. unk8: 0,
  69. unk9: 0,
  70. unk10: 0,
  71. unk11: 1
  72. })
  73. dispatch.toServer('C_GACHA_TRY', 1,{
  74. id:385851
  75. })
  76. }
  77. function stop() {
  78. clearInterval(timer)
  79. enabled = false
  80. inventory = null
  81. command.message('Box opener stopped.')
  82. }
  83. }