BruceWplays

goto silent old V2

Sep 7th, 2022
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local tArgs = {...}
  2. local face = 0
  3. local r = 1
  4. local tturned = 0
  5. rednet.open("left")
  6. local cx,cy,cz = gps.locate(2,false)
  7. if #tArgs ~= 3 then
  8.   print("Incorrect usage of Function.")
  9.   --print("goto <x> <y> <z>")
  10. else
  11. local gx = tonumber(tArgs[1])
  12. local gy = tonumber(tArgs[2])
  13. local gz = tonumber(tArgs[3])
  14. local x
  15. local y
  16. local z
  17.  
  18. function tturnup()
  19. tturned = tturned + 1
  20. if tturned > 10 then
  21. os.reboot()
  22. end
  23. end
  24.  
  25. function PL()
  26.   --print("Going to:")
  27.   --write(gx) write(" ") write(gy) write(" ") print(gz)
  28.   end
  29. function c_face()
  30. if face >= 5 then
  31.   face = 1
  32. elseif face <= 0 then
  33.   face = 4
  34. end
  35. end
  36. function get_Face()
  37. while turtle.forward() == false do
  38.    if turtle.up() == false then
  39.         --turtle.digUp()
  40.    end
  41.   end
  42.  
  43. nx,ny,nz = gps.locate(3,false)
  44. if nx > cx then
  45.   face = 1
  46. end
  47. if nx < cx then
  48.   face = 3
  49. end
  50. if nz > cz then
  51.   face = 2
  52. end
  53. if nz < cz then
  54.   face = 4
  55. end
  56. end
  57. function calc()
  58. x = nx - gx
  59. y = ny - gy
  60. z = nz - gz
  61. end
  62. function setDir(dir)
  63. while dir ~= face do
  64.   c_face()
  65.     if face >= dir then
  66.         turtle.turnLeft()
  67.         face = face - 1
  68.         tturnup()
  69.     end
  70.     if face < dir then
  71.         turtle.turnRight()
  72.         face = face + 1
  73.         tturnup()
  74.     end
  75.   c_face()
  76.   end
  77. end
  78. function f()
  79. while not turtle.forward() do
  80.     tturned = 0
  81.    if not turtle.up()  then
  82.         --turtle.digUp()
  83.    end
  84.    y = y + 1
  85.   end
  86. end
  87. function go()
  88. if x < 0 then
  89.   setDir(1)
  90.   while x ~= 0 do
  91.    f()
  92.    x = x + 1
  93.   end
  94. end
  95. if x > 0 then
  96.   setDir(3)
  97.   while x ~= 0 do
  98.    f()
  99.    x = x - 1
  100.   end
  101. end
  102. if z < 0 then
  103.   setDir(2)
  104.   while z ~= 0 do
  105.    f()
  106.    z = z + 1
  107.   end
  108. end
  109. if z > 0 then
  110.   setDir(4)
  111.   while z ~= 0 do
  112.    f()
  113.    z = z - 1
  114.   end
  115. end
  116. while y < 0 do
  117.   if turtle.up() ~= true then
  118.    --turtle.digUp()
  119.   end
  120.   y = y + 1
  121. end
  122. while y > 0 do
  123.   if turtle.down() ~= true then
  124.    --turtle.digDown()
  125.   end
  126.   y = y - 1
  127. end
  128. end
  129.  
  130.  
  131.  
  132. tonumber(gx)
  133. tonumber(gy)
  134. tonumber(gz)
  135. PL()
  136. get_Face()
  137. calc()
  138. go()
  139.  
  140. end
  141.  
Add Comment
Please, Sign In to add comment