bob558

Terminator

Oct 27th, 2016 (edited)
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.89 KB | None | 0 0
  1. -- терминатор для спавнера и лута. Проверка уровня робота
  2. -- слева зарядка, справа сундук
  3.  
  4.  
  5. local robot=require("robot")
  6. local sides = require("sides")
  7. local term = require("term")
  8. local comp = require("component")
  9. local event = require("event")
  10. local computer = require("computer")
  11.  
  12. slots=16--количество слотов у робота?
  13. slotstocheck=2--выгрузка если заполнены последние N слотов
  14.  
  15.  
  16. function check() return robot.count(slots-(slotstocheck-1)) ~= 0 end -- полный?
  17. function energy() return computer.energy()<((computer.maxEnergy()*10)/100) end  -- разрядился?
  18.  
  19.  
  20.  
  21. function unload() -- выгрузка
  22.   robot.turnRight()
  23.   for inv=1,slots do
  24.     robot.select(inv)
  25.       robot.drop()
  26.   end
  27.   robot.select(1)
  28.   robot.turnLeft()
  29.   b = robot.level() -- узнать уровень
  30.   print ("Уровень робота - ",(b))
  31. end
  32.  
  33. function charg()
  34.   if (energy()) then
  35.     if computer.energy()<((computer.maxEnergy()*10)/100) then
  36.       while computer.energy()<computer.maxEnergy()-20 do
  37.         computer.beep(2000, 5)
  38.         print(" Низкий уровень энергии." ,computer.energy())
  39.         --robot.turnLeft()
  40.         --robot.up()
  41.         robot.useDown()
  42.         --robot.down()
  43.         print("Заряжаюсь")
  44.           for i=1, 10 do
  45.             os.sleep(4)
  46.           end
  47.         --robot.up()
  48.         robot.useDown()
  49.         --robot.down()
  50.         --robot.turnRight()
  51.       end
  52.     end
  53.   end
  54. end
  55.  
  56.  
  57. -------- Тело программы --------
  58. while true do
  59.   -- проверка на сущность
  60.   --repeat
  61.   --a,t = robot.detect()
  62.   --print (a,t)
  63.   --until t == 'entity'
  64.     for sw=1, 5 do
  65.     robot.swing()
  66.     robot.suck()
  67.     end
  68. --
  69. if check() then unload() end
  70.   charg()
  71.  
  72. end
Add Comment
Please, Sign In to add comment