rollton

[OLD] Авто выставление схемы

Oct 9th, 2017
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.13 KB | None | 0 0
  1. pcall(function() computer,component = require("computer"),require("component") end)
  2.  
  3. function chekDatabase() for _ in component.list("database") do return false end return true end
  4. function printT(a) pcall(function() print(a) end) end
  5.  
  6. while chekDatabase() do printT("Отсутствует база данных") computer.beep(800,0.3) computer.pullSignal() end
  7.  
  8. for _, mod in component.list() do if mod ~= 'computer' then pcall(load(mod..' = component.proxy(component.list(\"'..mod..'\")())')) end end -- Подключаем все компоненты
  9.  
  10. inv = inventory_controller
  11. db = database
  12.  
  13. while not inv.getInventorySize(3) do printT("Отсутствует реактор перед роботом") computer.beep(800,0.3) end
  14. size = inv.getInventorySize(3)-4 -- Размер реактора. ( -4 , потому что есть скрытые слоты по углам, видимо реактор переделан от жидкостного реактора)
  15.  
  16. local maxSlot = inv.getInventorySize(1)
  17. if not maxSlot then
  18.     printT("Сундук сверху не найден")
  19.     computer.beep(800,0.3)
  20. end
  21.  
  22. for i = 1, size do
  23.     if not inv.getStackInSlot(3,i) then -- Если этот слот в реаакторе свободен
  24.         local item = db.get( i + ( math.ceil( i / (size/6) ) - 1 ) * ( 9 - (size/6) ) ) -- Функция для случая если слоты реактора не совпадают со слотами бд
  25.         if item then -- если слот в базе данных НЕ пуст
  26.             repeat
  27.                 local flag -- делаем флаг, для проверки. "Взят ли предмет из сундука"
  28.                 for j = 1, maxSlot do
  29.                     slot = inv.getStackInSlot(1,j)
  30.                     if slot and slot.name == item.name then -- Если предмет предмет похож на предмет из бд
  31.                         inv.suckFromSlot(1,j) -- забираем его из сундука
  32.                         flag = true
  33.                         break
  34.                     end
  35.                 end
  36.                 if not flag then printT(item.label.." не найден") computer.pullSignal(1) end
  37.             until flag
  38.         end
  39.         inv.dropIntoSlot(3,i)
  40.     end
  41. end
  42.  
  43. printT("Mission Complete")
Add Comment
Please, Sign In to add comment