Advertisement
TheIncgi

pickItem 1.14+

Aug 13th, 2019
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.00 KB | None | 0 0
  1. --attempts to pick an item from your inventory
  2. --if it exists it is picked from hotbar or moved to the prefered slot
  3. --slot number is returned or false if none found
  4. function pickItem(id, optHotbarSlot)
  5.               local inv = openInventory()
  6.               local map = inv.mapping[inv.getType()]
  7.               local optHotbarSlot = optHotbarSlot or 1
  8.               --scan hotbar first
  9.               for i, j in pairs(map.hotbar) do
  10.                       local item = inv.getSlot( j )
  11.                       if item and item.id == id then
  12.                               setHotbar( i )
  13.                               return j
  14.                       end
  15.               end
  16.  
  17.               local scanOrder = {
  18.                       "main", "contents", "output"
  19.               }
  20.               for _,iType in pairs(scanOrder)do
  21.                       --scan player inventory
  22.                       if map[scanOrder] then
  23.                               for i, j in pairs(map[scanOrder])do
  24.                                       local item = inv.getSlot(j)
  25.                                       if item and item.id == id then
  26.                                               local p = map.hotbar[optHotbarSlot]
  27.                                               inv.click( j ) --pickup
  28.                                               waitTick()
  29.                                               inv.click( p ) --place/swap
  30.                                               waitTick()
  31.                                               if inv.getHeld() then --place if swaped
  32.                                                     inv.click( j )
  33.                                                     waitTick()
  34.                                               end
  35.                                               --TODO close inventory maybe
  36.                                       return optHotbarSlot
  37.                                       end
  38.                               end
  39.                       end
  40.               end
  41.  
  42.               return false
  43. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement