Advertisement
ZiegelMan

robot (ore processing)

May 14th, 2020
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.98 KB | None | 0 0
  1. local robot = require("robot")
  2. local component = require("component")
  3. local computer = require("computer")
  4. local ic = component.inventory_controller
  5. local last_level = math.floor(robot.level())
  6.  
  7. function Notifications(code)
  8.     Beep(3)
  9.     if code == 1 then print("Уровень повышен до " .. math.floor(robot.level()) .. "!") end
  10.     if code == 2 then print("Текущий уровень - " .. math.floor(robot.level()) .. "!") end
  11.     return 0
  12. end
  13.  
  14. function Check_level()
  15.     if math.floor(robot.level()) > last_level then
  16.         last_level = math.floor(robot.level())
  17.         Notifications(1)
  18.     end
  19.     return 0
  20. end
  21.  
  22. function Swing()  
  23.     if robot.detect() == true then
  24.         while (robot.swing() == 0) do computer.sleep(100) end
  25.     end
  26.     return 0
  27. end
  28.  
  29. function Beep(code)
  30.     if code == 1 then
  31.         computer.beep(800,0.1)
  32.         computer.beep(1000,0.1)
  33.         computer.beep(1200,0.2)
  34.     end
  35.     if code == 2 then
  36.         computer.beep(1000,0.2)
  37.         computer.beep(1000,0.2)
  38.     end
  39.     if code == 3 then
  40.         computer.beep(1000,0.2)
  41.     end
  42.     return 0
  43. end
  44.  
  45. function Get_things()
  46.     robot.select(1)
  47.     while true do
  48.         for i = 1, ic.getInventorySize(1) do
  49.             if ic.getStackInSlot(1, i) ~= nil then
  50.                 ic.suckFromSlot(1, i)
  51.                 return 0
  52.             end
  53.         end
  54.     end
  55. end
  56.  
  57. function Give_things_away()
  58.     for i = 1, robot.inventorySize() do
  59.         if robot.count(i) ~= 0 then
  60.             robot.select(i)
  61.             for j = 1, ic.getInventorySize(0) do
  62.                 if ic.getStackInSlot(0, j) == nil then
  63.                     ic.dropIntoSlot(0, j)
  64.                     break
  65.                 end
  66.             end
  67.         end
  68.     end
  69.     return 0
  70. end
  71.  
  72. function Break_the_block()
  73.     robot.select(1)
  74.     for i = 1, robot.count() do
  75.         while (robot.place() == 0) do computer.sleep(100) end
  76.         Swing()
  77.     end
  78.     return 0
  79. end
  80.  
  81. Beep(1)
  82. print("Вас приветствует " .. robot.name() .. "!")
  83. Notifications(2)
  84. Beep(2)
  85. while true do
  86.     Check_level()
  87.     Get_things()
  88.     Break_the_block()
  89.     Give_things_away()
  90. end
  91. --pastebin run 3NZwmg4S
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement