-- ============================================ -- Rock5's tradeTo userfunction -- Version 1.0 -- solarstrike.net/phpBB3/viewtopic.php?p=59208 -- ============================================ -- -- Credit to Jandrana for initial version -- Requires addon curse.com/addons/rom/autotrade -- -- Format 1 : tradeTo("recipient", item) -- Format 2 : tradeTo("recipient", {item1, item2, item3}) -- Format 3 : tradeTo("recipient", "itemname" [,number]) -- Format 4 : tradeTo("recipient", itemid [,number]) -- Format 5 : tradeTo("recipient", {"itemname1", "itemname2", itemid1, itemid2}[, number]) function tradeTo(RecipientName,itemTable,_amount) if (type(itemTable) == "table" and itemTable.Id ~= nil) or type(itemTable) == "string" or type(itemTable) == "number" then itemTable = {itemTable} end if itemTable[1] and type(itemTable[1]) ~= "table" then -- List of Ids and Names -- Make table of items to send local idNameTable = itemTable local counter = 0 itemTable = {} for item = 61, 240, 1 do -- for each inventory local slotItem = inventory.BagSlot[item]; local slotNumber = slotItem.SlotNumber - 60 slotItem:update() if slotItem.Available and (table.contains(idNameTable,slotItem.Name) or table.contains(idNameTable,slotItem.Id)) then -- Check if split is necessary if _amount and (counter + slotItem.ItemCount > _amount) then -- split local emptyslot = inventory:findItem(0,"bags") if not emptyslot then error("Can't split stack for UMM_SendByNameOrId function. Inventory is full.") end local topickup = slotItem.ItemCount - (_amount - counter) RoMScript("SplitBagItem("..slotItem.BagId.." ,"..topickup..")") repeat yrest(500) until RoMScript("CursorHasItem()") RoMScript("PickupBagItem("..emptyslot.BagId..")") yrest(1500) slotItem:update() end -- Increment counter counter = counter + slotItem.ItemCount -- Add to table table.insert(itemTable, slotItem) -- Are we finished if _amount and counter >= _amount then break end end end end while itemTable and #itemTable > 0 do -- Lets trade local tradeIndex = 1; local Recipient = player:findNearestNameOrId(RecipientName) if Recipient then if distance(player, Recipient) > 60 then player:moveInRange(Recipient, 50, true) end repeat player:target(Recipient) yrest(500) RoMScript("RequestTrade('target')") yrest(500) -- Not sure how long the addon needs to react and accept the trade but it will try again until it answers until RoMScript("TradeFrame:IsVisible()") RoMScript("BagFrame:Show()"); yrest(500) repeat RoMScript("PickupBagItem("..tostring(itemTable[1].BagId)..")"); RoMScript("ClickTradeItem("..tostring(tradeIndex)..")"); table.remove(itemTable,1) yrest(200); tradeIndex = tradeIndex + 1; until tradeIndex > 8 or #itemTable == 0 repeat RoMScript("AcceptTrade('".. RecipientName .."')") yrest(500) -- Again not sure what pause is necessary for addon to react until not RoMScript("TradeFrame:IsVisible()") else break -- No recipient found end end end