RenKylo

Robot

Apr 28th, 2019
2,602
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --Created By RenKylo
  2. local robot = require("robot")
  3. local component = require("component")
  4. local inv = component.inventory_controller
  5. local inv_size = robot.inventorySize()
  6. --SETTINGS
  7. local MIN_TOOL_CHARGE = 0.3 --Минимальный заряд бура
  8. local CHARGING_TIME = 10 --Время зарядки
  9. --FUNCTIONS
  10. function charging_tool() --Перезарядка бура
  11.     if robot.durability() < MIN_TOOL_CHARGE then
  12.         robot.turnLeft()
  13.         inv.equip(1)
  14.         robot.drop(1)
  15.         os.sleep(CHARGING_TIME)
  16.         robot.suck(1)
  17.         inv.equip(1)
  18.         robot.turnRight()
  19.     end
  20. end
  21. function robot_action() --Основные действия
  22.     robot.select(1)
  23.     if robot.suck() then
  24.         size = robot.count(1)
  25.         robot.turnRight()
  26.         for i = 1, size do
  27.             robot.place()
  28.             robot.swing()
  29.         end
  30.         robot.turnRight()
  31.         for n = 1, inv_size do
  32.             robot.select(n)
  33.             if robot.drop() == false and n ~= 1 then
  34.                 break
  35.             end
  36.         end
  37.         robot.turnAround()
  38.     end
  39.     os.sleep(0.2)
  40. end
  41. while true do
  42.     if robot.durability() ~= nil then --Выполняется только если есть инструмент
  43.         robot.select(1)
  44.         charging_tool()
  45.         robot_action()
  46.     end
  47. end
Add Comment
Please, Sign In to add comment