BruceWplays

goto silent old V4

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