Advertisement
Guest User

Untitled

a guest
Nov 26th, 2014
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.13 KB | None | 0 0
  1. require('functions')
  2. function find_usable_item(item_id)
  3. local items = windower.ffxi.get_items()
  4. local inventory_index,bag_id
  5. for i,v in pairs(items.temporary) do
  6. if v and v.id == item_id then
  7. inventory_index = i
  8. bag_id = 3
  9. break
  10. end
  11. end
  12.  
  13. -- Should I add some kind of filter for enchanted items?
  14. if not inventory_index then
  15. for i,v in pairs(items.inventory) do
  16. if v and v.id == item_id then
  17. inventory_index = i
  18. bag_id = 0
  19. break
  20. end
  21. end
  22. end
  23. if not inventory_index then
  24. for i,v in pairs(items.wardrobe) do
  25. if v and v.id == item_id then
  26. inventory_index = i
  27. bag_id = 8
  28. break
  29. end
  30. end
  31. end
  32. return inventory_index,bag_id
  33. end
  34. function assemble_menu_item_packet(target_id,target_index,item_id)
  35. local outstr = string.char(0x36,0x20,0,0)
  36. -- Target ID
  37. outstr = outstr..string.char( (target_id%256), math.floor(target_id/256)%256, math.floor( (target_id/65536)%256) , math.floor( (target_id/16777216)%256) )
  38. -- One unit traded
  39. outstr = outstr..string.char(1,0,0,0,0,0,0,0)..string.char(0,0,0,0,0,0,0,0)..string.char(0,0,0,0,0,0,0,0)..
  40. string.char(0,0,0,0,0,0,0,0)..string.char(0,0,0,0,0,0,0,0)
  41. -- Inventory Index for the one unit
  42. inventory_index,bag_id = find_usable_item(item_id)
  43. if inventory_index then
  44. outstr = outstr..string.char(inventory_index%256)
  45. else
  46. --debug_mode_chat('Proposed item: '..(res.items[item_id][language] or item_id)..' not found in inventory.')
  47. return
  48. end
  49. -- Nothing else being traded
  50. outstr = outstr..string.char(0,0,0,0,0,0,0,0,0)
  51. -- Target Index
  52. outstr = outstr..string.char( (target_index%256), math.floor(target_index/256)%256)
  53. -- Only one item being traded
  54. outstr = outstr..string.char(1,0,0,0)
  55. return outstr
  56. end
  57.  
  58. -- _addon.commands = {'keyboxes'}
  59. -- _global = {
  60. -- frames = 0
  61. -- }
  62.  
  63. -- windower.register_event('prerender',function()
  64. -- if (_global.frames % 5000 == 0) then
  65. -- local mob_array = windower.ffxi.get_mob_array()
  66. -- for str_index,mob_table in pairs(mob_array) do
  67. -- if mob_table.models[1] == 965 and mob_table.valid_target and mob_table.distance <= 50 and mob_table.name == 'Sturdy Pyxis' then
  68. -- windower.send_command('input /echo found a box')
  69. -- local textvar = assemble_menu_item_packet(mob_table.id,mob_table.index,2490)
  70. -- windower.packets.inject_outgoing(0x36,textvar)
  71. -- coroutine.sleep(5000)
  72. -- end
  73. -- end
  74. -- end
  75. -- end)
  76.  
  77. function runstuff()
  78. local mob_array = windower.ffxi.get_mob_array()
  79. for str_index,mob_table in pairs(mob_array) do
  80. if mob_table.models[1] == 965 and mob_table.valid_target and mob_table.distance <= 50 and mob_table.name == 'Sturdy Pyxis' then
  81. --windower.send_command('input /echo found a box')
  82. local textvar = assemble_menu_item_packet(mob_table.id,mob_table.index,2490)
  83. windower.packets.inject_outgoing(0x36,textvar)
  84. end
  85. end
  86. end
  87. runstuff:loop(1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement