Lygre

Vslack

Mar 16th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.84 KB | None | 0 0
  1. _addon.name = 'Voidslacker'
  2. _addon.author = 'Lygre'
  3. _addon.commands = {'vs','voidslacker'}
  4. _addon.version = '1.0.0.1'
  5.  
  6. require('luau')
  7. require('pack')
  8. require('lists')
  9. require('logger')
  10. require('sets')
  11. files = require('files')
  12. extdata = require('extdata')
  13. packets = require('packets')
  14. require('chat')
  15. res = require('resources')
  16.  
  17. local pkt = {}
  18. local busy = false
  19. local settings = {enabled=false,loot_action=10}
  20.  
  21. windower.register_event('addon command', function(...)
  22.     local args = T{...}
  23.     local cmd = args[1]:lower()
  24.     args:remove(1)
  25.     if cmd == 'on' then
  26.         settings.enabled = true
  27.     elseif cmd == 'status' then
  28.         windower.add_to_chat(3, 'Enabled: '..tostring(settings.enabled))
  29.     elseif cmd == 'fix' then
  30.         pkt = validate()
  31.         if pkt then
  32.             busy = true
  33.             poke_npc(pkt['Target'],pkt['Target Index'])
  34.         end
  35.     elseif L{'loot','box'}:contains(cmd) then
  36.         local cmd = args[1]:lower()
  37.         args:remove(1)
  38.         if L{'obtain','get'}:contains(cmd) then
  39.             settings.loot_action = 10
  40.             windower.add_to_chat(3, 'Loot action: Obtain')
  41.         elseif L{'drop','relinquish'}:contains(cmd) then
  42.             settings.loot_action = 9
  43.             windower.add_to_chat(3, 'Loot action: relinquish')         
  44.         else
  45.             windower.add_to_chat(3, 'invalid selection, option')
  46.         end
  47.     end
  48. end)
  49.  
  50. -------------------------------------------------------
  51. --------------Identify Pyxis on Spawn------------------
  52. windower.register_event('incoming chunk', function(id,data)
  53.     if settings.enabled then
  54.         if id == 0x038 then
  55.             local packet = packets.parse('incoming',data)
  56.             local array = windower.ffxi.get_mob_array()
  57.             local walker = check_vwalker()
  58.             for k,v in pairs(array) do
  59.                 if packet['Mob'] == v.id and L{'Riftworn Pyxis'}:contains(array[k].name) and packet['Type'] == 'deru' and walker then
  60.                     print('Spawn',packet['Mob'],packet['Type'])
  61.                     pkt = validate()
  62.                     if pkt then
  63.                         busy = true
  64.                         coroutine.sleep(2)
  65.                         poke_npc(pkt['Target'],pkt['Target Index'])
  66.                     end
  67.                 end
  68.             end
  69.         end
  70.     end
  71.     if id == 0x034 then
  72.         --Packet reponse from poking Pyxis
  73.         if busy == true and pkt then
  74.             local packet = packets.parse('incoming',data)
  75.             --obtaining menu id for npc from packet
  76.                 pkt['Menu ID']=packet['Menu ID']
  77.                 windower.add_to_chat(3, pkt['Menu ID'])
  78.             local packet = packets.new('outgoing', 0x05B)
  79.             --injecting obtain all command to Pyxis and NPC release
  80.                 packet["Target"]=pkt['Target']
  81.                 packet["Option Index"]=settings.loot_action
  82.                 packet["_unknown1"]=0
  83.                 packet["Target Index"]=pkt['Target Index']
  84.                 packet["Automated Message"]=false
  85.                 packet["_unknown2"]=0
  86.                 packet["Zone"]=pkt['Zone']
  87.                 packet["Menu ID"]=pkt['Menu ID']
  88.                 packets.inject(packet)
  89.             local packet = packets.new('outgoing', 0x016, {
  90.             ["Target Index"]=pkt['me'],
  91.             })
  92.             packets.inject(packet)
  93.             busy = false
  94.             pkt = {}
  95.             return true
  96.         end
  97.     end
  98. end)
  99.  
  100. -------------------------------------------------------
  101. -----------Check for voidwalker status----------------
  102. ----Returns true if active, false otherwise-----------
  103. function check_vwalker()
  104.     local buffs = windower.ffxi.get_player().buffs
  105.  
  106.     for _,v in pairs(buffs) do
  107.         if v == 475 then
  108.             return true
  109.         end
  110.     end
  111.  
  112.     return false
  113. end
  114.  
  115. -------------------------------------------------------
  116. -----------Obtains player id, target id, index, and distance----------------
  117. ----returns result['me'] as player id-----------
  118. function validate()
  119.     local me,target_index,target_id,distance
  120.     local zone = windower.ffxi.get_info()['zone']
  121.     local result = {}
  122.     for i,v in pairs(windower.ffxi.get_mob_array()) do
  123.         if v['name'] == windower.ffxi.get_player().name then
  124.             result['me'] = i
  125.         -- elseif L{'Riftworn Pyxis','Planar Rift'}:contains(v['name']) then
  126.         elseif L{'Riftworn Pyxis'}:contains(v['name']) then
  127.             target_index = i
  128.             target_id = v['id']
  129.             -- result['Menu ID'] = valid_zones[zone].menu
  130.             distance = windower.ffxi.get_mob_by_id(target_id).distance
  131.         end
  132.     end
  133.     if math.sqrt(distance)<6 then
  134.         result['Target'] = target_id
  135.         -- result['Option Index'] = ite['Option']
  136.         -- result['_unknown1'] = ite['Index']
  137.         result['Target Index'] = target_index
  138.         result['Zone'] = zone
  139.     else
  140.         windower.add_to_chat(10,"Too far from npc")
  141.     end
  142.     return result
  143. end
  144.  
  145. ----0x027 contains rift info?
  146.  
  147. -------------------------------------------------------
  148. -----------Pokes given npc id & index----------------
  149. ----Injects an NPC interaction packet to which we receive another packet we can react to-----------
  150. function poke_npc(npc,target_index)
  151.     if npc and target_index then
  152.         local packet = packets.new('outgoing', 0x01A, {
  153.             ["Target"]=npc,
  154.             ["Target Index"]=target_index,
  155.             ["Category"]=0,
  156.             ["Param"]=0,
  157.             ["_unknown1"]=0})
  158.         packets.inject(packet)
  159.     end
  160. end
Add Comment
Please, Sign In to add comment