Advertisement
BruceWplays

goto silent V3

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