I know there is some coding issues in the x,z part but this thing just goes up!
Spoiler
tArgs = { ... }
local function numbering(_table)
for i = 1, #_table do
_table[i] = tonumber(_table[i])
end
end
local function checkArg()
if #tArgs > 3 then
print('Too much arguments! Try using "goto <number> <number> <number>"')
return false
elseif #tArgs == nil then
print('You MUST have 3 argument" Try using "goto <number> <number> <number>"')
return false
elseif type(tArgs[1]) ~= "number" or type(tArgs[2]) ~= "number" or type(tArgs[3]) ~= "number" then
print('You enterend an invalid argument type! Use only numbers!' )
return false
else
return true
end
end
local function turn(n)
for i= 1, n do
turtle.turnRight()
end
end
local function walkDetect()
while turtle.detect() do
turtle.dig()
end
turtle.forward()
end
local function goTo(x,y,z)
local cx, cy, cz = gps.locate(2) --get current pos
local dx, dy, dz = math.abs(cx) - math.abs(x), math.abs(cy) - math.abs(y), math.abs(cz) - math.abs(z) -- the actual distance to "walk"
turtle.forward()
local chx, chy, chz = gps.locate(2) --check which way to turn
local dchx, dchy, dchz = math.abs(chx) - math.abs(x), math.abs(chy) - math.abs(y), math.abs(chz) - math.abs(z)
if dchx > dx then --walk in the xCoord
turn(2)
local wx = dx + 1
for i = 1,wx do
walkDetect()
end
elseif dchx < dx then
local wx = dx - 1
for i = 1,wx do
walkDetect()
end
end
if dchz > dz then --walk in the zCoord
turn(2)
local wz = dz + 1
for i = 1,wz do
walkDetect()
end
elseif dchx < dx then
local wz = dz - 1
for i = 1,wz do
walkDetect()
end
end
if y > cy then
local wy = y - cy
for i = 1,wy do
while turtle.detectDown() do
turtle.digDown()
end
turtle.down()
end
elseif y < cy then
local wy = cy-y
for i = 1, wy do
while turtle.detectUp() do
turtle.digUp()
end
turtle.up()
end
end
end
numbering(tArgs)
if checkArg() then
goTo(tArgs[1],tArgs[2],tArgs[3])
end