Advertisement
rollton

Авто выставление схемы в реактор через робота

Oct 8th, 2017
642
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.20 KB | None | 0 0
  1. local computer, component = computer or require"computer", component or require"component"
  2.  
  3. print = print or function()end
  4.  
  5. while not component.list("database")() do computer.beep(600,0.4) computer.pullSignal(6) print("Отсутствует база данных") end
  6.  
  7. local inv = component.proxy(component.list("inventory_controller")())
  8. local db = component.proxy(component.list("database")())
  9. local r = component.proxy(component.list("robot")())
  10.  
  11. local maxSlot = inv.getInventorySize(1) or 1
  12.  
  13. local maxSlotRobot = 1
  14. pcall( function() local i = 0 while true do i = i + 1 r.count(i*16) maxSlotRobot = i*16 end end )
  15.  
  16. function poisc(item)
  17.     for i = 1, maxSlotRobot do
  18.         if r.count(i) > 0 and item == inv.getStackInInternalSlot(i).name then
  19.             r.select(i)
  20.             return true
  21.         end
  22.     end
  23. end
  24.  
  25. function itemsChest()
  26.     local items = {}
  27.     for j = 1, maxSlot do
  28.         local slot = inv.getStackInSlot(1,j)
  29.         if slot then
  30.             if not items[slot.name] then items[slot.name] = {} end
  31.             table.insert(items[slot.name], j)
  32.         end
  33.     end
  34.     return items
  35. end
  36.  
  37. local slots = itemsChest()
  38.  
  39. for i = 1, maxSlotRobot do -- Защита, от случайной загрузки предмета (если в выделеном слоте лежит предмет)
  40.     if r.count(i) == 0 then
  41.         r.select(i)
  42.         break
  43.     end
  44. end
  45. r.drop(1)
  46.  
  47. local size = inv.getInventorySize(3)-4 -- Размер реактора. ( -4 , потому что есть скрытые слоты по углам )
  48. for i = 1, size do
  49.     if not inv.getStackInSlot(3,i) then
  50.         local itemDB = db.get( i + ( math.ceil( i / (size/6) ) - 1 ) * ( 9 - (size/6) ) ) -- для случая если слоты реактора не совпадают со слотами бд
  51.         if itemDB then
  52.             repeat
  53.                 local item = slots[itemDB.name]
  54.                 if item and #item ~= 0 and inv.suckFromSlot(1,item[#item]) then
  55.                     item[#item] = nil
  56.                     break
  57.                 else
  58.                     if maxSlotRobot and poisc(itemDB.name) then break end
  59.                     print(itemDB.label.." не найден")
  60.                     computer.pullSignal(1)
  61.                     computer.beep(800,0.4)
  62.                     slots = itemsChest()
  63.                 end
  64.             until false
  65.         end
  66.         inv.dropIntoSlot(3,i)
  67.     end
  68. end
  69. r.select(1)
  70.  
  71. print(" Mission Completed! \n    respect +")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement