Not a member of Pastebin yet?
                        Sign Up,
                        it unlocks many cool features!                    
                - print("Where Am I - Coordinates for turtles. Type help() for help.")
 - print("Also, do NOT use the normal turtle.forward and such functions, as that will mess up the internal coordinates of the turtle.")
 - if fs.exists("coords") then
 - local file = fs.open("coords", "r")
 - X = file.readLine()
 - Y = file.readLine()
 - Z = file.readLine()
 - face = file.readLine()
 - file.close()
 - X = tonumber(X)
 - Y = tonumber(Y)
 - Z = tonumber(Z)
 - face = tonumber(face)
 - print("Initialized settings.")
 - end
 - if fs.exists("waypoints") then
 - local file = fs.open("waypoints", "r")
 - waypoints = {}
 - local line = file.readLine()
 - while line do
 - table.insert(waypoints, line)
 - line = file.readLine()
 - end
 - print("Waypoints Initilialized.")
 - end
 - function help(page)
 - if type(page) == "nil" then
 - page = 1
 - end
 - Page = tonumber(page)
 - if type(Page) ~= "number" then
 - error("Bad argument: Number expected, got "..page.."!")
 - elseif Page > 6 or Page < 1 then
 - error("Bad argument: Integer expected between 1 and 4, got "..Page.."!")
 - end
 - if Page == 1 then
 - print("---------------Help menu---------------")
 - print("----------Viewing Page 1 of 6----------")
 - print("help(page)")
 - print("-Shows these help text pages.")
 - print("-Perameraters: Takes the page number you whish to view help on.")
 - print("turtle.setCoords(x,y,z,dir)")
 - print("-Will set the coords of the turtle.")
 - print("-Perameraters: Integers for X,Y and Z, and the initial direction the turtle is facing.")
 - elseif Page == 2 then
 - print("---------------Help Menu---------------")
 - print("----------Viewing Page 2 of 6----------")
 - print("turtle.getCoords()")
 - print("-Prints the current coordinates of the turtle.")
 - print("turtle.move(dir, amount)")
 - print("-Moves turtle in indicated direction.")
 - print("-Perameraters: The direction the turtle should move, and how many blocks that way. Takes 'front', 'down', 'forward', 'back', 'left', and 'right' as arguments.")
 - elseif Page == 3 then
 - print("---------------Help Menu---------------")
 - print("----------Viewing Page 3 of 6----------")
 - print("turtle.turn(string direction)")
 - print("-Turn the turtle in the specified direction.")
 - print("-Perameraters: The direction the turtle should turn. (left, right, or back)")
 - elseif Page == 4 then
 - print("-----Help Menu-Viewing Page 4 of 6-----")
 - print("setWaypoint(X,Y,Z,name,)")
 - print("-Sets a named waypoint for the turtle at the indicated location. Also, if specified, will make the turtle go to height. Useful if the waypoint is under something.")
 - print("-Perameraters: Takes Integers for X, Y, and Z. Takes a name for the waypoint. Will also take an integer for the height the turtle should reach before going.")
 - elseif Page == 5 then
 - print("---------------Help Menu---------------")
 - print("----------Viewing Page 5 of 6----------")
 - print("deleteWaypoint(name)")
 - print("-Deletes the specified waypoint.")
 - print("-Perameraters: Takes the name of the waypoint that should be deleted.")
 - print("listWaypoints()")
 - print("Lists all the available waypoints.")
 - print("turtle.gotoWaypoint(name)")
 - elseif Page == 6 then
 - print("---------------Help Menu---------------")
 - print("----------Viewing Page 6 of 6----------")
 - print("-Has the turtle go to the waypoint.")
 - print("-Perameraters: Takes the name of the waypoint the turtle should go to.")
 - print("Coordinates are saved as follows: X coord: X, Y coord: Y, Z coord: Z, Direction: face")
 - end
 - end
 - local function reinitialize()
 - file = fs.open("coords", "w")
 - file.writeLine(X)
 - file.writeLine(Y)
 - file.writeLine(Z)
 - file.writeLine(face)
 - file.close()
 - end
 - function turtle.setCoords(x,y,z,dir)
 - X = x
 - Y = y
 - Z = z
 - face = string.lower(dir)
 - if face == "north" then
 - face = 0
 - elseif face == "south" then
 - face = 2
 - elseif face == "east" then
 - face = 3
 - elseif face == "west" then
 - face = 1
 - else
 - face = 0
 - end
 - while type(X) ~= "number" do
 - print("X is not a number.")
 - X = tonumber(read())
 - end
 - while type(Y) ~= "number" do
 - print("Y is not a number.")
 - Y = tonumber(read())
 - end
 - while type(Z) ~= "number" do
 - print("Z is not a number.")
 - Z = tonumber(read())
 - end
 - reinitialize()
 - end
 - function turtle.getCoords()
 - print("X: "..X)
 - print("Y: "..Y)
 - print("Z: "..Z)
 - if face == 0 then
 - print("facing: north")
 - elseif face == 1 then
 - print("facing: west")
 - elseif face == 2 then
 - print("facing: south")
 - else
 - print("facing: east")
 - end
 - end
 - function turtle.turn(dir)
 - if dir == "left" then
 - turtle.turnLeft()
 - face = ((face + 1) + 4) % 4
 - elseif dir == "right" then
 - turtle.turnRight()
 - face = ((face - 1) + 4) % 4
 - elseif dir == "back" then
 - turtle.turnLeft()
 - turtle.turnLeft()
 - face = ((face + 2) + 4) % 4
 - end
 - reinitialize()
 - end
 - function turtle.move(dir,a)
 - if a == nil then
 - a = 1
 - end
 - if dir == "up" then
 - for i=1,a do
 - if turtle.up() then
 - Y = Y + 1
 - end
 - end
 - elseif dir == "down" then
 - for i=1,a do
 - if turtle.down() then
 - Y = Y - 1
 - end
 - end
 - elseif dir == "forward" then
 - for i=1,a do
 - if turtle.forward() then
 - if face == 0 then
 - Z = Z - 1
 - elseif face == 2 then
 - Z = Z + 1
 - elseif face == 1 then
 - X = X - 1
 - elseif face == 3 then
 - X = X + 1
 - end
 - end
 - end
 - elseif dir == "back" then
 - for i=1,a do
 - if turtle.back() then
 - if face == 0 then
 - Z = Z + 1
 - elseif face == 2 then
 - Z = Z - 1
 - elseif face == 1 then
 - X = X + 1
 - elseif face == 3 then
 - X = X - 1
 - end
 - end
 - end
 - elseif dir == "left" then
 - for i=1,a do
 - if turtle.turnLeft() then
 - face = ((face + 1) + 4) % 4
 - end
 - if turtle.forward() then
 - if face == 0 then
 - Z = Z - 1
 - elseif face == 2 then
 - Z = Z + 1
 - elseif face == 1 then
 - X = X - 1
 - elseif face == 3 then
 - X = X + 1
 - end
 - end
 - if turtle.turnRight() then
 - face = ((face - 1) + 4) % 4
 - end
 - end
 - elseif dir == "right" then
 - for i=1,a do
 - if turtle.turnRight() then
 - face = ((face - 1) + 4) % 4
 - end
 - if turtle.forward() then
 - if face == 0 then
 - Z = Z - 1
 - elseif face == 2 then
 - Z = Z + 1
 - elseif face == 1 then
 - X = X - 1
 - elseif face == 3 then
 - X = X + 1
 - end
 - end
 - if turtle.turnLeft() then
 - face = ((face + 1) + 4) % 4
 - end
 - end
 - end
 - reinitialize()
 - end
 - function setWaypoint(x,y,z,name,yLimit)
 - if waypoints == nil then
 - waypoints = {}
 - end
 - if yLimit == nil then
 - yLimit = 256
 - end
 - table.insert(waypoints,name)
 - local x = tonumber(x)
 - local y = tonumber(y)
 - local z = tonumber(z)
 - local yLimit = tonumber(yLimit)
 - while type(x) ~= "number" do
 - print("X is not an integer")
 - x = tonumber(read())
 - end
 - while type(y) ~= "number" do
 - print("Y is not an integer")
 - y = tonumber(read())
 - end
 - while type(z) ~= "number" do
 - print("Z is not an integer")
 - z = tonumber(read)
 - end
 - while type(yLimit) ~= "number" do
 - print("The Y Limit is not an integer")
 - yLimit = tonumber(read())
 - end
 - table.insert(waypoints,x)
 - table.insert(waypoints,y)
 - table.insert(waypoints,z)
 - table.insert(waypoints,yLimit)
 - file = fs.open("waypoints", "a")
 - file.writeLine(name)
 - file.writeLine(x)
 - file.writeLine(y)
 - file.writeLine(z)
 - file.writeLine(yLimit)
 - file.close()
 - end
 - function deleteWaypoint(name)
 - for i=#waypoints,1,-1 do
 - if waypoints[i] == name then
 - table.remove(waypoints, i)
 - table.remove(waypoints, i)
 - table.remove(waypoints, i)
 - table.remove(waypoints, i)
 - table.remove(waypoints, i)
 - local file = fs.open("waypoints", "w")
 - for key,value in pairs(waypoints) do
 - file.writeLine(value)
 - end
 - file.close()
 - end
 - end
 - end
 - function listWaypoints()
 - for i=1,#waypoints do
 - if type(tonumber(waypoints[i])) == "nil" then
 - print(waypoints[i])
 - end
 - end
 - end
 - function turtle.gotoWaypoint(name)
 - local turtleGo = false
 - for key,value in pairs(waypoints) do
 - if value == name then
 - gotoX = waypoints[key + 1]
 - gotoY = waypoints[key + 2]
 - gotoZ = waypoints[key + 3]
 - yLimit = waypoints[key + 4]
 - gotoX = tonumber(gotoX)
 - gotoY = tonumber(gotoY)
 - gotoZ = tonumber(gotoZ)
 - yLimit = tonumber(yLimit)
 - turtleGo = true
 - end
 - end
 - if turtleGo == false then
 - error("Bad argument: Expected listed waypoint, got "..name.."!")
 - end
 - while (((gotoX ~= X) or (gotoY ~= Y)) or (gotoZ ~= Z)) and turtleGo do
 - if yLimit > Y then
 - local skyDif = yLimit - Y
 - turtle.move("up",skyDif)
 - elseif yLimit < Y then
 - local skyDif = Y - yLimit
 - turtle.move("down",skyDif)
 - end
 - while gotoX ~= X do
 - if gotoX > X then
 - local Xdif = gotoX - X
 - if face == 0 then
 - turtle.turn("right")
 - elseif face == 1 then
 - turtle.turn("back")
 - elseif face == 2 then
 - turtle.turn("left")
 - end
 - turtle.move("forward",Xdif)
 - else
 - local Xdif = X - gotoX
 - if face == 0 then
 - turtle.turn("left")
 - elseif face == 3 then
 - turtle.turn("back")
 - elseif face == 2 then
 - turtle.turn("right")
 - end
 - turtle.move("forward",Xdif)
 - end
 - end
 - while gotoZ ~= Z do
 - if gotoZ > Z then
 - local Zdif = gotoZ - Z
 - if face == 0 then
 - turtle.turn("back")
 - elseif face == 1 then
 - turtle.turn("left")
 - elseif face == 3 then
 - turtle.turn("right")
 - end
 - turtle.move("forward",Zdif)
 - else
 - local Zdif = Z - gotoZ
 - if face == 1 then
 - turtle.turn("right")
 - elseif face == 2 then
 - turtle.turn("back")
 - elseif face == 3 then
 - turtle.turn("left")
 - end
 - turtle.move("forward",Zdif)
 - end
 - end
 - while gotoY ~= Y do
 - if gotoY < Y then
 - local Ydif = Y - gotoY
 - turtle.move("down",Ydif)
 - elseif gotoY > Y then
 - local Ydif = gotoY - Y
 - turtle.move("up",Ydif)
 - end
 - end
 - end
 - end
 
Advertisement
 
                    Add Comment                
                
                        Please, Sign In to add comment