Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --- unload trade, load trader //trade alexandrite
- _addon = {'Trader'}
- _addon.commands = {'Trade'}
- require 'pack'
- require 'strings'
- require('logger')
- res_items = require('resources').items
- source_bag_id = 0
- dest_bag_id = 0
- item_id_raw = 0;
- item_id1 = 0
- item_id2 = 0
- ------------------------------------
- -- Get item id
- ------------------------------------
- function get_item_res(item)
- item = windower.convert_auto_trans(item)
- for k,v in pairs(res_items) do
- if v.en:lower() == item:lower() or v.enl:lower() == item:lower() then
- return v
- end
- end
- return nil
- end
- ------------------------------------
- -- Number to hex
- ------------------------------------
- function tohex(num)
- local hexstr = '0123456789abcdef'
- local s = ''
- while num > 0 do
- local mod = math.fmod(num, 16)
- s = string.sub(hexstr, mod+1, mod+1) .. s
- num = math.floor(num / 16)
- end
- if s == '' then s = '0' end
- return s
- end
- function ConfirmTrade()
- windower.packets.inject_outgoing(0x033,string.char(0x34,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x80,0x40))
- end
- function AcceptTrade()
- windower.packets.inject_outgoing(0x033,string.char(0x34,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x40))
- end
- ------------------------------------
- -- Trades items and accepts
- ------------------------------------
- function Trade()
- local trade_slot = 1
- local items = windower.ffxi.get_items()
- for k,v in pairs(items.inventory) do
- if type(v) == "table" and v.id == item_id_raw then
- local hex_string = tohex(v.count)
- if string.len(hex_string) == 7 then
- hex_string = "0"..hex_string
- elseif string.len(hex_string) == 6 then
- hex_string = "00"..hex_string
- elseif string.len(hex_string) == 5 then
- hex_string = "000"..hex_string
- elseif string.len(hex_string) == 4 then
- hex_string = "0000"..hex_string
- elseif string.len(hex_string) == 3 then
- hex_string = "00000"..hex_string
- elseif string.len(hex_string) == 2 then
- hex_string = "000000"..hex_string
- elseif string.len(hex_string) == 1 then
- hex_string = "0000000"..hex_string
- end
- local count1 = tonumber(string.sub(hex_string, 7, 8), 16)
- local count2 = tonumber(string.sub(hex_string, 5, 6), 16)
- local count3 = tonumber(string.sub(hex_string, 3, 4), 16)
- local count4 = tonumber(string.sub(hex_string, 1, 2), 16)
- windower.packets.inject_outgoing(0x034,string.char(0x34,0x00,0x00,0x00,count1,count2,count3,count4,item_id1,item_id2,v.slot,trade_slot))
- trade_slot = trade_slot + 1
- if trade_slot == 9 then
- ConfirmTrade()
- return
- end
- end
- end
- ConfirmTrade()
- end
- ------------------------------------
- -- Called on startup
- ------------------------------------
- windower.register_event('load',function ()
- end)
- ------------------------------------
- -- Called onan incoming packet
- ------------------------------------
- windower.register_event('incoming chunk', function(id,original,modified,injected,blocked)
- if id == 0x021 then
- AcceptTrade()
- end
- end)
- ------------------------------------
- -- Called when given the command
- ------------------------------------
- windower.register_event('addon command', function (...)
- args = {...};
- local item_name = table.concat(args, ' ',1,#args):lower()
- item_id_raw = get_item_res(item_name).id
- local hex_string = tohex(item_id_raw)
- if string.len(hex_string) == 3 then
- hex_string = "0"..hex_string
- elseif string.len(hex_string) == 2 then
- hex_string = "00"..hex_string
- elseif string.len(hex_string) == 1 then
- hex_string = "000"..hex_string
- end
- item_id1 = tonumber(string.sub(hex_string, 3, 4), 16)
- item_id2 = tonumber(string.sub(hex_string, 1, 2), 16)
- coroutine.schedule(Trade,0)
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement