BruceWplays

goto silent old (V1)

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