Advertisement
Zeroun_Scripts

OTCv8 Loot Sorting

Nov 22nd, 2020 (edited)
612
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.71 KB | None | 0 0
  1. macro(300, "Backpack Sorting", function()
  2.     local lootbpitems = {3349, 3425}
  3.     local mainBp = 5801
  4.     local lootBp = 2869
  5.    
  6.  
  7. --Don't edit below this line
  8.  
  9.     --If backpack is full, this will open next backpack of same type
  10.     --For every container open, get information on open containers
  11.     for i, container in pairs(getContainers()) do
  12.         --Get the IDs of every open container
  13.         containerItemId = container:getContainerItem():getId()
  14.         --If the containerItemID is equal to lootBp ID then
  15.         if containerItemId == lootBp then
  16.             --If the amount of items in the container is equal to the max capacity of the container then
  17.             if container:getItemsCount() == container:getCapacity() then
  18.                 --Search every item ID in the container
  19.                 for _, item in ipairs(container:getItems()) do
  20.                     --If one of the items in the container is equal to your backpack id, then
  21.                     if item:isContainer() then
  22.                         --Open up the backpack
  23.                         g_game.open(item, container)
  24.                     end
  25.                 end
  26.             end
  27.         end
  28.     end
  29.  
  30.     --For every container open, get information on open containers
  31.     for i, container in pairs(getContainers()) do
  32.         --Get the IDs of every open container
  33.         containerItemId = container:getContainerItem():getId()
  34.         --If the containerItemId is equal to mainBp ID then
  35.         if containerItemId == mainBp then
  36.             --For every item in you mainBP do
  37.             for j, item in ipairs(container:getItems()) do
  38.                 --Get item ID of every item in mainBP
  39.                 local itemValue = item:getId()
  40.                 --If you find an ID in your mainBP that matches lootbpitems then
  41.                 if table.find(lootbpitems, item:getId()) then
  42.                     local foundItem = item
  43.                     --loop through open containers to look for lootBp
  44.                     for i, depotcontainer in pairs(getContainers()) do
  45.                         containerItemId = depotcontainer:getContainerItem():getId()
  46.                         --If you find lootBP then
  47.                         if containerItemId == lootBp then
  48.                             --loop through the item IDs in your mainBP
  49.                             for l, depotbox in ipairs(depotcontainer:getItems()) do
  50.                                 --Move found item ID to 19th slot of loot backpack, this is to avoid moving items into backpack within lootbackpack
  51.                                 g_game.move(foundItem, depotcontainer:getSlotPosition(19), foundItem:getCount())  
  52.                                 return
  53.                             end
  54.                         end
  55.                     end
  56.                 end
  57.             end
  58.         end
  59.     end
  60.  
  61. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement