Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local tArgs = {...}
- xDest, yDest, zDest = tonumber(tArgs[1]), tonumber(tArgs[2]), tonumber(tArgs[3])
- direct = {}
- direct[0] = "south"
- direct[1] = "west"
- direct[2] = "north"
- direct[3] = "east"
- function direction()
- xPos, yPos, zPos = gps.locate()
- if not xPos or not yPos or not zPos then
- print("ERROR: GPS API REQUIRED")
- os.exit(goTo)
- end
- turtle.forward()
- xPos2, yPos2, zPos2 = gps.locate()
- turtle.back()
- if xPos ~= xPos2 then
- if xPos > xPos2 then
- fDir = 1
- else
- fDir = 3
- end
- else
- if zPos > zPos2 then
- fDir = 2
- else
- fDir = 0
- end
- end
- end
- function forward(num)
- if not num then
- num = 1
- end
- for i = 1, num do
- turtle.forward()
- if fDir == 0 then zPos = zPos + 1 end
- if fDir == 2 then zPos = zPos - 1 end
- if fDir == 1 then xPos = xPos - 1 end
- if fDir == 3 then xPos = xPos + 1 end
- end
- end
- function left(num)
- if not num then
- num = 1
- end
- for i = 1, num do
- turtle.turnLeft()
- fDir = fDir - 1
- if fDir < 0 then fDir = 3 end
- end
- end
- function right(num)
- if not num then
- num = 1
- end
- for i = 1, num do
- turtle.turnRight()
- fDir = fDir + 1
- if fDir > 3 then fDir = 0 end
- end
- end
- function up(num)
- if not num then
- num = 1
- end
- for i = 1, num do
- turtle.digUp()
- turtle.up()
- yPos = yPos + 1
- print(yPos)
- end
- end
- function down(num)
- if not num then
- num = 1
- end
- for i = 1, num do
- turtle.digDown()
- turtle.down()
- yPos = yPos - 1
- end
- end
- function goToX()
- if xDest < xPos then
- while fDir ~= 1 do
- left()
- end
- elseif xDest > xPos then
- while fDir ~= 3 do
- left()
- end
- end
- while xPos ~= xDest do
- turtle.dig()
- forward()
- end
- end
- function goToZ()
- if zDest < zPos then
- while fDir ~= 2 do
- left()
- end
- elseif zDest > zPos then
- while fDir ~= 0 do
- left()
- end
- end
- while zPos ~= zDest do
- turtle.dig()
- forward()
- end
- end
- function goToY()
- if yDest < yPos then
- while yDest ~= yPos do
- turtle.digDown()
- turtle.down()
- yPos = yPos - 1
- print(yPos)
- end
- elseif yDest > yPos then
- while yDest ~= yPos do
- turtle.digUp()
- turtle.up()
- yPos = yPos + 1
- print(yPos)
- end
- end
- end
- origin = {gps.locate()}
- distance = math.sqrt(math.abs(origin[1] - tArgs[1])^2 + math.abs(origin[2] - tArgs[2])^2 + math.abs(origin[3] - tArgs[3])^2)
- fuelReq = (math.abs(origin[1] - tArgs[1]) + math.abs(origin[2] - tArgs[2]) + math.abs(origin[3] - tArgs[3]))*2 + 100
- term.setBackgroundColor(colors.black)
- term.clear()
- term.setCursorPos(1, 1)
- print("Distance from Origin: " .. tostring(distance))
- print("WARNING: Fuel Required is an ESTIMATE and may not be enough, depending on how high the turtle is going. It is recommended to give the turtle extra fuel just in case.")
- local termX, termY = term.getCursorPos()
- term.setTextColor(colors.yellow)
- term.setCursorPos(1, termY)
- term.write("Approximate Fuel Required: " .. tostring(fuelReq))
- local w, h = term.getSize()
- while fuelReq > turtle.getFuelLevel() do
- term.setCursorPos(1, termY + 1)
- term.clearLine()
- printError("Current Fuel Level: " .. tostring(turtle.getFuelLevel()))
- term.setCursorPos(1, termY + 2)
- term.write("Insert fuel into slot 16")
- turtle.select(16)
- turtle.refuel(1)
- end
- term.setCursorPos(1, termY + 1)
- term.clearLine()
- term.setTextColor(colors.green)
- print("Current Fuel Level: " .. tostring(turtle.getFuelLevel()))
- term.setCursorPos(1, termY + 2)
- term.clearLine()
- term.setCursorPos(w/2 - 2, termY + 3)
- term.setBackgroundColor(colors.gray)
- term.setTextColor(colors.white)
- term.write("Ready")
- while true do
- local click = {os.pullEvent()}
- if click[1] == "mouse_click" and click[2] == 1 and click[3] >= w/2 - 2 and click[3] <= w/2 + 2 and click[4] == termY + 3 then
- term.setCursorPos(w/2 - 2, termY + 3)
- term.setBackgroundColor(colors.blue)
- term.write("Ready")
- sleep(.2)
- break
- end
- end
- term.setBackgroundColor(colors.black)
- term.clear()
- term.setCursorPos(1, 1)
- print("Traveling to destination...")
- direction()
- goToY()
- goToX()
- goToZ()
- local outpost = {
- [1] = {1, 1, 1, 1, 1},
- [2] = {1, 1, 1, 1, 1},
- [3] = {1, 1, 0, 1, 1},
- [4] = {1, 1, 1, 1, 1},
- [5] = {1, 1, 1, 1, 1}
- }
- local outpost2 = {
- [1] = {3, 0, 0, 0, 3},
- [2] = {0, 0, 2, 0, 0},
- [3] = {3, 0, 0, 0, 3}
- }
- print("Pinpointing building location...")
- while not turtle.digDown() do
- down()
- print(yPos)
- end
- up(21)
- left()
- forward(2)
- left()
- forward(2)
- left(2)
- --shell.run("go up 21 left forward 2 left forward 2 left 2")
- print("Constructing outpost...")
- local turn = "right"
- for i, v in pairs(outpost) do
- for k, e in pairs(v) do
- if e > 0 then
- turtle.select(e)
- turtle.placeDown()
- end
- if e == 0 then
- outpostLocation = {xPos, yPos, zPos}
- end
- if k < 5 then
- forward()
- end
- end
- if i < 5 then
- if turn == "right" then
- right()
- forward()
- right()
- turn = "left"
- elseif turn == "left" then
- left()
- forward()
- left()
- turn = "right"
- end
- end
- end
- left(2)
- up()
- --shell.run("go left 2 up")
- local turn = "right"
- for i, v in pairs(outpost2) do
- for k, e in pairs(v) do
- if e == 2 then
- turtle.down()
- turtle.select(e)
- turtle.placeDown()
- turtle.up()
- elseif e == 3 then
- turtle.select(e)
- turtle.placeDown()
- end
- if k < 5 then
- forward()
- end
- end
- if i < 3 then
- if turn == "right" then
- right()
- forward(2)
- right()
- turn = "left"
- elseif turn == "left" then
- left()
- forward(2)
- left()
- turn = "right"
- end
- end
- end
- forward()
- print("Traveling to origin...")
- xDest, yDest, zDest = origin[1], origin[2], origin[3]
- goToY()
- goToX()
- goToZ()
- print("Completed. New outpost at x: " .. tostring(outpostLocation[1]) .. " y: " .. tostring(outpostLocation[2]) .. " z: " .. tostring(outpostLocation[3]))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement