Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local component = require("component")
- local nav = component.navigation
- local directions = { north = 2, south = 3, west = 4, east = 5 }
- local robot = require("robot")
- local sides = require("sides")
- local invControl = component.inventory_controller
- function distanceFrom(waypointName)
- local waypoints = nav.findWaypoints(20)
- for i = 1,#waypoints do
- wp = waypoints[i]
- if wp.label:find(waypointName) then
- return table.unpack(wp.position)
- end
- end
- end
- function goToWaypoint(waypointName)
- x, y, z = distanceFrom(waypointName)
- if (x > 0) then
- local direction = nav.getFacing()
- if (direction == directions.south) then
- robot.turnLeft()
- end
- if (direction == directions.north) then
- robot.turnRight()
- end
- if (direction == directions.west) then
- robot.turnAround()
- end
- while x > 0 do
- if (robot.forward() == true) then
- x = x - 1
- end
- end
- end
- if (z > 0) then
- local direction = nav.getFacing()
- if (direction == directions.west) then
- robot.turnLeft()
- end
- if (direction == directions.east) then
- robot.turnRight()
- end
- if (direction == directions.north) then
- robot.turnAround()
- end
- while z > 0 do
- if (robot.forward() == true) then
- z = z - 1
- end
- end
- end
- end
- function goHome()
- goToWaypoint("Charger")
- end
- function faceNorth(direction)
- if (direction == directions.east) then
- robot.turnLeft()
- end
- if (direction == directions.west) then
- robot.turnRight()
- end
- if (direction == directions.south) then
- robot.turnAround()
- end
- end
- function harvest()
- local direction = nav.getFacing()
- local notEnd = true
- while notEnd do
- local direction = nav.getFacing()
- faceNorth(direction)
- if (direction ~= directions.south) then
- robot.forward()
- end
- robot.forward()
- robot.forward()
- if (direction == directions.south) then
- robot.turnLeft()
- else
- faceNorth(direction)
- end
- for i = 1, 9 do
- robot.useDown()
- if (robot.forward() ~= true) then
- i = i - 1
- end
- end
- local x, y, z = distanceFrom("Path End")
- if (x + y + z == 0) then
- notEnd = false
- end
- end
- end
- --[[
- function sprinkle()
- goToWaypoint("Center")
- robot.select(1)
- for i = 1, 100 do
- robot.place()
- os.sleep(1/20)
- end
- end
- ]]--
- function deposit()
- local slot = 1
- for i = 1, 16 do
- robot.select(i)
- while (invControl.dropIntoSlot(sides.top, slot) == false)
- and (invControl.getStackInInternalSlot() ~= nil) do
- slot = slot + 1
- end
- end
- end
- while true do
- goHome()
- harvest()
- goHome()
- deposit()
- os.sleep(120)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement