Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local tArgs = {...}
- if #tArgs ~= 7 then
- print("Not enough Arguments")
- error()
- end
- if tArgs[4] ~= "north" or tArgs[4] ~= "east" or tArgs[4] ~= "south" or tArgs[4] ~= "west" then
- print("Argument 4 must be = north, east, south or west.")
- error()
- end
- local cDir = tArgs[4]
- local cX = tonumber(tArgs[1])
- local cY = tonumber(tArgs[2])
- local cZ = tonumber(tArgs[3])
- function turnRight()
- if cDir == "north" then
- cDir = "east"
- elseif cDir == "east" then
- cDir = "south"
- elseif cDir == "south" then
- cDir = "west"
- elseif cDir == "west" then
- cDir = "north"
- else
- print("Error!!")
- error()
- end
- turtle.turnRight()
- end
- function turnLeft()
- if cDir == "north" then
- cDir = "west"
- elseif cDir == "east" then
- cDir = "north"
- elseif cDir == "south" then
- cDir = "east"
- elseif cDir == "west" then
- cDir = "south"
- else
- print("Error!!")
- error()
- end
- turtle.turnLeft()
- end
- function turnTo(dir)
- if cDir ~= dir then
- repeat
- turnRight()
- until cDir == dir
- end
- end
- function moveForward()
- if cDir == "north" then
- cZ = cZ-1
- elseif cDir == "east" then
- cX = cX+1
- elseif cDir == "south" then
- cZ = cZ+1
- elseif cDir == "west" then
- cX = cX-1
- else
- print("Error!!")
- error()
- end
- while not turtle.forward() do
- turtle.dig()
- end
- end
- function moveUp()
- cY = cY+1
- while not turtle.up() do
- turtle.digUp()
- end
- end
- function moveDown()
- cY = cY-1
- while not turtle.down() do
- turtle.digDown()
- end
- end
- function moveToX(x)
- if cX < x then
- turnTo("east")
- repeat
- moveForward()
- until cX == x
- elseif cX > x then
- turnTo("west")
- repeat
- moveForward()
- until cX == x
- else
- --print("already there")
- end
- end
- function moveToZ(z)
- if cZ < z then
- turnTo("south")
- repeat
- moveForward()
- until cZ == z
- elseif cZ > z then
- turnTo("north")
- repeat
- moveForward()
- until cZ == z
- else
- --print("already there")
- end
- end
- function moveToY(y)
- if cY < y then
- repeat
- moveUp()
- until cY == y
- elseif cY > y then
- repeat
- moveDown()
- until cY == y
- else
- --print("already there")
- end
- end
- function goTo(x, y, z)
- moveToX(x)
- moveToY(y)
- moveToZ(z)
- turnTo("north")
- end
- goTo(tonumber(tArgs[5]), tonumber(tArgs[6]), tonumber(tArgs[7]))
Add Comment
Please, Sign In to add comment