Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local component = require("component")
- local sides = require("sides")
- local robot = require("robot")
- local computer = require("computer")
- local turnRight = true
- local num1, num2 = 0, 0
- print("Set the X")
- local roomX = tonumber(io.read())
- print("Set the Y")
- local roomY = tonumber(io.read())
- print("Set the Z")
- local roomZ = tonumber(io.read())
- function digUp(roomZ)
- local var1, var2
- local i = 0
- while i ~= roomZ do
- os.sleep(0.5)
- var1, var2 = robot.detect()
- if var1 == true and var2 ~= "liquid" then
- repeat
- robot.swing()
- os.sleep(0.5)
- var1, var2 = robot.detect()
- until var2 == "liquid" or var1 == false
- end
- i = i + 1
- if i ~= roomZ then
- robot.up()
- end
- end
- while i ~= 0 do
- i = i - 1
- if i ~= 0 then
- robot.down()
- end
- end
- var1, var2 = robot.detect()
- if var1 == true and var2 ~= "liquid" then
- repeat
- robot.swing()
- os.sleep(0.5)
- var1, var2 = robot.detect()
- until var1 == false or var2 == "liquid"
- end
- end
- function digNL()
- if turnRight == true then
- robot.turnRight()
- digUp(roomZ)
- robot.forward()
- robot.turnRight()
- turnRight = false
- else
- robot.turnLeft()
- digUp(roomZ)
- robot.forward()
- robot.turnLeft()
- turnRight = true
- end
- end
- function turn()
- if turnRight == true then
- robot.turnLeft()
- else
- robot.turnRight()
- end
- end
- function returnHome()
- turn()
- local var3, var4 = robot.detect()
- while var3 == false or var4 == "liquid" do
- robot.forward()
- num1 = num1 + 1
- os.sleep(0.5)
- var3, var4 = robot.detect()
- end
- robot.turnLeft()
- var3, var4 = robot.detect()
- while var3 == false or var4 == "liquid" do
- robot.forward()
- num2 = num2 + 1
- os.sleep(0.5)
- var3, var4 = robot.detect()
- end
- end
- function returnWork()
- robot.turnAround()
- for i = 0, num2 - 1, 1 do
- robot.forward()
- end
- robot.turnRight()
- for i = 0, num1 - 1, 1 do
- robot.forward()
- end
- turn()
- end
- function checkStat()
- if robot.count(16) ~= 0 then
- matinance()
- end
- if computer.energy() <= 5000 then
- matinance()
- end
- end
- function storageLeft()
- robot.turnLeft()
- for i = 1, 3 , 1 do
- robot.forward()
- end
- robot.turnRight()
- end
- function fullInvDump()
- for i = 1, 16, 1 do
- robot.select(i)
- robot.drop()
- end
- local sum = 0
- for i = 1, 16, 1 do
- sum = sum + robot.count(i)
- end
- if sum ~= 0 then
- return false
- else
- robot.select(1)
- return true
- end
- end
- function storageDump()
- robot.turnLeft()
- for i = 1, 4 , 1 do
- robot.forward()
- end
- robot.turnRight()
- if fullInvDump() == false then
- robot.up()
- if fullInvDump() == false then
- storageLeft()
- if fullInvDump() == false then
- robot.down()
- end
- end
- end
- robot.turnRight()
- robot.down()
- for i = 1, 16, 1 do
- robot.forward()
- end
- robot.turnLeft()
- end
- function matinance()
- returnHome()
- repeat
- if computer.energy() <= 10000 then
- repeat
- os.sleep(15)
- until computer.energy() >= computer.maxEnergy() - 500
- elseif robot.count(16) ~= 0 then
- storageDump()
- end
- until computer.energy() > computer.maxEnergy() - 1000 and robot.count(16) == 0
- returnWork()
- end
- for i = 0, roomY - 1, 1 do
- for j = 0, roomX -1, 1 do
- digUp(roomZ)
- robot.forward()
- checkStat()
- end
- digNL()
- end
Advertisement
Add Comment
Please, Sign In to add comment