Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --> AWT
- rednet.open("left")
- orientation = 0
- function comeBack(xP, yP, zP) --> math time
- distanceX = 0
- distanceY = 0
- distanceZ = 0
- if (orientation > 0) then --> Figure out the orientation.
- while (orientation > 0) do
- orientation = orientation - 1
- turtle.turnRight()
- end
- elseif (orientation < 0) then
- while (orientation < 0) do
- orientation = orientation + 1
- turtle.turnLeft()
- end
- end
- x, y, z = gps.locate(5)
- function cdbtap(x1, x2, y1, y2, z1, z2) --> Calculate distance between player and turtle. ACTUAL GPS RESPONSE PASS IN AS -> = X2, Y2, Z2!!!! REMEMBER
- if (xP > x) then distanceX = xP - x else distanceX = x - xP end
- if (yP > y) then distanceY = yP - y else distanceY = y - yP end
- if (zP > z) then distanceZ = zP - z else distanceZ = z - zP end
- end
- cdbtap(xP, x, yP, y, zP, z)
- original_distance_from_player_x = distanceX
- original_distance_from_player_y = distanceY
- original_distance_from_player_z = distanceZ
- print(distanceX) print(distanceY) print(distanceZ)
- while not (distanceX == 0 and distanceZ == 0) do --> While it hasn't reached your x and z
- xx, yy, zz = gps.locate(1)
- if (xx == xP and zz == zP) then --> Double check to make sure ur not at the x and z. For some reason the while loop doesn't check it some times? idk why...
- break
- end
- if not (xx == xP and zz == zP) then --> If the turtle isn't at your coordinates then proceed to move it.
- if (turtle.forward()) then
- newX, newY, newZ = gps.locate(5)
- print(x, y, z)
- print(newX, distanceX, newY, distanceY, newZ, distanceZ) --> debug line
- if (xP > newX) then newX = xP - newX else newX = newX - xP end
- if (yP > newY) then newY = yP - newY else newY = newY - yP end
- if (zP > newZ) then newZ = zP - newZ else newZ = newZ - zP end
- if (newX < distanceX or newY < distanceY or newZ < distanceZ) then
- if not (distanceX == newX) then
- while not (newX == 0) do --> This makes the turtle MUCH MUCH MUCH faster at getting to you, because if the turtle moved in the right direction it loops in that direction.
- newX, newY, newZ = gps.locate()
- if (turtle.forward()) then
- newX, newY, newZ = gps.locate()
- if (xP > newX) then newX = xP - newX else newX = newX - xP end
- if (yP > newY) then newY = yP - newY else newY = newY - yP end
- if (zP > newZ) then newZ = zP - newZ else newZ = newZ - zP end
- else
- if not (turtle.up()) then for i = 0, 3, 1 do turtle.back() end turtle.up() end
- end
- end
- elseif not (distanceZ == newZ) then
- while not (newZ == 0) do
- newX, newY, newZ = gps.locate()
- if (turtle.forward()) then
- newX, newY, newZ = gps.locate()
- if (xP > newX) then newX = xP - newX else newX = newX - xP end
- if (yP > newY) then newY = yP - newY else newY = newY - yP end
- if (zP > newZ) then newZ = zP - newZ else newZ = newZ - zP end
- else
- if not (turtle.up()) then for i = 0, 3, 1 do turtle.back() end turtle.up() end
- end
- end
- end
- print("A few step closer...")
- distanceX = newX
- distanceY = newY
- distanceZ = newZ
- else
- turtle.back()
- end
- turtle.turnLeft() orientation = orientation - 1
- else --> For some reason when it hits a wall it cant move but this fixed it.
- if not (turtle.up()) then for i = 0, 3, 1 do turtle.back() end turtle.up() end
- end
- end
- end
- xxx, yyy, zzz = gps.locate(1)
- while not (yyy == yP + 1 or yyy == yP - 1 or yyy == yP) do --> If it reaches you're coordinates then it runs through this loop condition which checks if it's at your y coord and position the turtle correctly.
- if (yyy > yP) then distanceBetweenYVals = yyy - yP else distanceBetweenYVals = yP - yyy end
- if (turtle.up()) then
- yyy = yyy + 1
- if (yyy > yP) then distanceBetweenYVals2 = yyy - yP else distanceBetweenYVals2 = yP - yyy end
- if (distanceBetweenYVals2 > distanceBetweenYVals) then
- while not (yyy == yP + 1 or yyy == yP) do
- turtle.down()
- end
- end
- else
- turtle.down()
- yyy = yyy - 1
- if (yyy > yP) then distanceBetweenYVals2 = yyy - yP else distanceBetweenYVals2 = yP - yyy end
- if (distanceBetweenYVals2 < distanceBetweenYVals) then
- while not (yyy == yP + 1 or yyy == yP) do
- turtle.down()
- end
- end
- end
- end
- print("Done")
- end
- phoneID = 37 --> set phone id
- while (true) do --> Listen for commands
- id, message = rednet.receive("roombaNET-1")
- print(id)
- print(message)
- if (id == 37) then
- if (message == "comeback") then
- id, message = rednet.receive("roombaNET-1")
- if (id == 37) then
- x = tonumber(message)
- id, message = rednet.receive("roombaNET-1")
- if (id == 37) then
- y = tonumber(message)
- id, message = rednet.receive("roombaNET-1")
- if (id == 37) then
- z = tonumber(message) --> z = tonumber(message)
- print("why no work fucker???")
- comeBack(x, y, z)
- end
- end
- end
- end
- end
- end
Add Comment
Please, Sign In to add comment