Spoiler
goto = function( ... )
term.clear() -- clear screen
term.setCursorPos(1,1)
-- Variables --
digIsPossible = true
runUp = 0
runDown = 0
args = { ... } -- get the arguments for the chordinates.
Facing = { -- just quick info. --
"North South East West",
" 2 0 3 1"
}
-- Waypoints --
Waypoint = { -- the ChargeCheck waypoint is working fine. (all in this table is actually working fine.)
["Home"] = {
["sPos"] = {wX = 801, wY = 68, wZ = -154},
["ePos"] = {wX = 801, wY = 63, wZ = -154}
},
["ChargePad1"] = {
["sPos"] = {wX = -290, wY = 80, wZ = 362},
["ePos"] = {wX = -290, wY = 77, wZ = 362}
},
["ChargePad2"] = {
["sPos"] = {wX = -289, wY = 80, wZ = 362},
["ePos"] = {wX = -289, wY = 77, wZ = 362}
},
["ChargePad3"] = {
["sPos"] = {wX = -289, wY = 80, wZ = 363},
["ePos"] = {wX = -289, wY = 77, wZ = 363}
},
["ChargePad4"] = {
["sPos"] = {wX = -290, wY = 80, wZ = 363},
["ePos"] = {wX = -290, wY = 77, wZ = 363}
},
["ChargeCheck"] = {
["sPos"] = {wX = -290, wY = 80, wZ = 362},
["ePos"] = {wX = -290, wY = 78, wZ = 362}
}
}
--[[ Call
xPos = Waypoint.Home.sPos.wX
--]]
printUsage = function() --Prints an usage, if choordinates, or input is defined wrong...
print("Usage: [X] [Y] [Z]")
print("\n"..Facing[1])
print(Facing[2])
end
refuel = function()
while turtle.getFuelLevel() < 100 do
term.setCursorPos(1,2)
term.clearLine()
term.setCursorPos(1,2)
print("Need fuel")
for itemSlots = 1, 16 do
turtle.select(itemSlots)
if turtle.refuel(1) then itemSlots = 16 end
end
sleep(0)
end
term.setCursorPos(1,2)
term.clearLine()
term.setCursorPos(1,2)
print("Refueled.")
end
up = function()
refuel()
while not turtle.up() do
if digIsPossible then
if not turtle.digUp() then turtle.attackUp() end
end
end
end
down = function()
refuel()
while not turtle.down() do
if digIsPossible then
if not turtle.digDown() then turtle.attackDown() end
end
end
end
fd = function()
refuel()
while not turtle.forward() do
if digIsPossible then
if not turtle.dig() then turtle.attack() end
else
refuel()
if up() then
runUp = runUp + 1
else down()
runDown = runDown + 1
end
end
end
while runUp > 0 do
refuel()
down()
runUp = runUp - 1
end
while runDown > 0 do
refuel()
up()
runDown = runDown - 1
end
end
bk = function()
refuel()
while not turtle.back() do
if digIsPossible then
turtle.turnRight()
turtle.turnRight()
if not turtle.dig() then turtle.attack() end
turtle.turnRight()
turtle.turnRight()
end
end
end
getLoc = function(_nWrit)
rednet.open("right")
x,y,z = gps.locate(10)
term.setCursorPos(1,1)
if not _nWrit then
print(x.." , "..y.." , "..z)
end
end
getDir = function()
getLoc()
curx, cury, curz = x, y, z
fd()
getLoc()
if curz > z then
dir = 0
dirN = "South"
elseif curz < z then
dir = 2
dirN = "North"
elseif curx < x then
dir = 1
dirN = "West"
elseif curx > x then
dir = 3
dirN = "East"
end
term.setCursorPos(1,2)
term.clearLine()
print(dir.." , "..dirN)
bk()
getLoc()
end
turn = function(d)
getDir()
term.setCursorPos(1,2)
term.clearLine()
term.setCursorPos(1,3)
term.clearLine()
term.setCursorPos(1,2)
print("Finding direction...")
print(dirN.." , "..d)
while dir ~= d do
turtle.turnRight()
dir = dir + 1
if dir == 4 then dir = 0 end
end
end
goto1 = function(gox,goy,goz) -- in this function it looks like it just
Xmove = function()
term.setCursorPos(1,2)
term.clearLine()
term.setCursorPos(1,3)
term.clearLine()
term.setCursorPos(1,2)
print("Moving in the X Axis.")
getLoc()
if gox > x then
turn(1)
for i = x, gox-1 do
fd()
x = x + 1
end
elseif gox < x then
turn(3)
for i = gox+1, x do
fd()
x = x - 1
end
end
end
Zmove = function()
term.setCursorPos(1,2)
term.clearLine()
term.setCursorPos(1,3)
term.clearLine()
term.setCursorPos(1,2)
print("Moving in the Z Axis.")
getLoc()
if goz > z then
turn(2)
for j = z, goz-1 do
fd()
z = z + 1
end
elseif goz < z then
turn(0)
for j = goz+1, z do
fd()
z = z - 1
end
end
end
Ymove = function()
term.setCursorPos(1,2)
term.clearLine()
term.setCursorPos(1,3)
term.clearLine()
term.setCursorPos(1,2)
print("Moving in the Y Axis.")
getLoc()
if goy > y then
for k = y, goy-1 do
up()
y = y + 1
end
elseif goy < y then
for k = goy+1, y do
down()
y = y - 1
end
end
end
getLoc()
if goy > y then
Ymove()
Xmove()
Zmove()
else
Xmove()
Zmove()
Ymove()
end
end
gpsRead = function()
try = 0
tArg = args
arg = #args
if arg == 3 then
getLoc()
goto1(tonumber(tArg[1]), tonumber(tArg[2]), tonumber(tArg[3]))
elseif arg == 1 and tArg[1] ~= "ChargeCheck" then
dest = Waypoint[tArg[1]].sPos
endDest = Waypoint[tArg[1]].ePos
goto1(dest.wX, dest.wY, dest.wZ)
goto1(endDest.wX, endDest.wY, endDest.wZ)
elseif arg == 1 and tArg[1] == "ChargeCheck" then
dest = Waypoint["ChargeCheck"].sPos
endDest = Waypoint["ChargeCheck"].ePos
goto1(dest.wX, dest.wY, dest.wZ)
goto1(endDest.wX, endDest.wY, endDest.wZ) -- here it quits? its just, like going around this if statement. how and why?
if turtle.detectDown() then -- it Does NOT reach this part.. i dont know why.. i dont see any "return false" or "return" in the goto1 function..
fd(1)
if turtle.detectDown() then
rt(1)
fd(1)
if turtle.detectDown() then
rt(1)
fd(1)
if not turtle.detectDown() then
goto("ChargePad4")
end
elseif not turtle.detectDown() then
goto("ChargePad3")
end
elseif not turtle.detectDown() then
goto("ChargePad2")
end
elseif not turtle.detectDown() then
goto("ChargePad1")
end
else
printUsage()
return false
end
end
-- main --
rednet.open("right")
term.clear()
term.setCursorPos(1,1)
gpsRead()
term.clear()
term.setCursorPos(1,1)
getLoc(1)
print("i moved to: ") -- this is what it returns, after the :
-- goto1(dest.wX, dest.wY, dest.wZ)
-- goto1(endDest.wX, endDest.wY, endDest.wZ)
-- and thats not good :(/>
print("X: "..x.." Y: "..y.." Z: "..z)
end