Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local tArgs = { ... }
- if #tArgs ~= 3 then
- print( "Usage: goto <cordinates>" )
- return
- end
- cid=os.getComputerID()
- x1 = tonumber(tArgs[1])
- y1 = 81+cid
- z1 = tonumber(tArgs[3])
- print("target: "..x1..", "..y1..", "..z1)
- ---- functions ----
- function locate()
- x, y, z = gps.locate()
- end
- function locate1()
- locate()
- x2=tonumber(x)
- y2=tonumber(y)
- z2=tonumber(z)
- e=0
- while turtle.detect() do
- turtle.turnRight()
- e=e+1
- if e > 3 then
- print("all sides blocked")
- return
- end
- end
- while not turtle.forward() do
- sleep(1)
- end
- locate()
- turtle.back()
- if z < z2 then
- f="north"
- elseif x > x2 then
- f="east"
- elseif z > z2 then
- f="south"
- elseif x < x2 then
- f="west"
- end
- end
- function facing(f1)
- -- locate1()
- print("facing actually to: "..f)
- print("turning facing to "..f1)
- if f1 == "north" then
- if f == "north" then
- elseif f == "east" then
- turtle.turnRight()
- turtle.turnRight()
- turtle.turnRight()
- elseif f == "south" then
- turtle.turnRight()
- turtle.turnRight()
- elseif f == "west" then
- turtle.turnRight()
- end
- f="north"
- end
- if f1 == "east" then
- if f == "north" then
- turtle.turnRight()
- elseif f == "east" then
- elseif f == "south" then
- turtle.turnRight()
- turtle.turnRight()
- turtle.turnRight()
- elseif f == "west" then
- turtle.turnRight()
- turtle.turnRight()
- end
- f="east"
- end
- if f1 == "south" then
- if f == "north" then
- turtle.turnRight()
- turtle.turnRight()
- elseif f == "east" then
- turtle.turnRight()
- elseif f == "south" then
- elseif f == "west" then
- turtle.turnRight()
- turtle.turnRight()
- turtle.turnRight()
- end
- f="south"
- end
- if f1 == "west" then
- if f == "north" then
- turtle.turnRight()
- turtle.turnRight()
- turtle.turnRight()
- elseif f == "east" then
- turtle.turnRight()
- turtle.turnRight()
- elseif f == "south" then
- turtle.turnRight()
- elseif f == "west" then
- end
- f="west"
- end
- end
- ---------------------------
- x=false
- y=false
- z=false
- locate()
- if x then
- print("position: "..x..", "..y..", "..z)
- x2=tonumber(x)
- y2=tonumber(y)
- z2=tonumber(z)
- e=0
- while turtle.detect() do
- turtle.turnRight()
- e=e+1
- if e > 3 then
- print("all sides blocked. couldn't determine")
- return
- end
- end
- while not turtle.forward() do
- sleep(1)
- end
- locate()
- turtle.back()
- if z < z2 then
- f="north"
- elseif x > x2 then
- f="east"
- elseif z > z2 then
- f="south"
- elseif x < x2 then
- f="west"
- end
- while y < 81+cid do
- while not turtle.up() do
- sleep(1)
- end
- y=y+1
- end
- locate()
- if x1 < x then
- f1="west"
- facing(f1)
- while x > x1 do
- while not turtle.forward() do
- sleep(0.5)
- end
- x=x-1
- end
- elseif x1 > x then
- f1="east"
- facing(f1)
- while x < x1 do
- while not turtle.forward() do
- sleep(0.5)
- end
- x=x+1
- end
- end
- if z1 > z then
- f1="south"
- facing(f1)
- while z < z1 do
- while not turtle.forward() do
- sleep(0.5)
- end
- z=z+1
- end
- elseif z1 < z then
- f1="north"
- facing(f1)
- while z > z1 do
- while not turtle.forward() do
- sleep(0.5)
- end
- z=z-1
- end
- end
- locate()
- print("position: "..x..", "..y..", "..z)
- while y > y1 do
- while not turtle.down() do
- sleep(0.5)
- end
- y=y-1
- end
- else
- print("location not found")
- end
Add Comment
Please, Sign In to add comment