soccer16x

Script 1

Sep 7th, 2012
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.12 KB | None | 0 0
  1. local tArgs = {...}
  2. local x = tonumber(tArgs[1])
  3. local y = tonumber(tArgs[2])
  4. local z = tonumber(tArgs[3])
  5. local curx, cury, curz, dir
  6.  
  7. function getPos()
  8. return gps.locate(3)
  9. end
  10.  
  11. function getDir()
  12. local dir, x, y, z
  13. x, y, z = getPos()
  14. --print("Old: "..x..","..y..","..z.."
  15. while not turtle.forward() do
  16. while not turtle.up() do
  17. turtle.digUp()
  18. end
  19. end
  20. nx, ny, nz = getPos()
  21. --print ("New: "..nx..","..ny..","..nz.."
  22. if (x == nx) then
  23. if (nz > z) then
  24. dir = 2
  25. else
  26. dir = 0
  27. end
  28. else
  29. if (nx > x) then
  30. dir = 3
  31. else
  32. dir = 1
  33. end
  34. end
  35. return dir
  36. end
  37.  
  38. function setDir(toDir)
  39. while toDir ~= dir do
  40. turtle.turnleft()
  41. if dir == 3 then
  42. dir=0
  43. else
  44. dir=dir+1
  45. end
  46. end
  47. end
  48.  
  49. function moveX()
  50. distx = x - curx
  51. --print(distx)
  52. if (x > crux) then
  53. setDir(3)
  54. else
  55. setDir(1)
  56. end
  57. distx = math.abs(distx)
  58. --print(distx)
  59.  
  60. for i = 1, distx do
  61. while not turtle.forward() do
  62. while not turtle.up() do
  63. turtle.digUp()
  64. end
  65. end
  66. end
  67. end
  68.  
  69. function moveZ()
  70. distz = z - curz
  71. if (z < curz) then
  72. setDir(0)
  73. else
  74. setDir(2)
  75. end
  76. distz = math.abs(distz)
  77. --print(distz)
  78.  
  79. for i = 1, distz do
  80. while not turtle.forward() do
  81. while not turtle.up() do
  82. turtle.digUp()
  83. end
  84. end
  85. end
  86. end
  87.  
  88. function moveY()
  89. disty = y - cury
  90. disty = math.abs(disty)
  91. if (y < cury) then
  92. for i = 1, disty do
  93. while not turtle.down() do
  94. turtle.digDown()
  95. end
  96. end
  97. else
  98. for i = 1,disty do
  99. while not turtle.up() do
  100. turtle.digup()
  101. end
  102. end
  103. end
  104.  
  105. end
  106.  
  107. --=====================--
  108. if not x or not y or not z then
  109. print("Must supply X Y Z")
  110. exit()
  111. end
  112.  
  113. rednet.open("right")
  114. --print (x..","..y..","..z)
  115. dir = getDir()
  116. curx, cury, curz = getPos()
  117. distx = x - curx
  118. disty = y - cury
  119. distz = z - curz
  120. --print ("Current: "..curx..","..cury..","..curz..")
  121. --print ("Distance" "..distx..","..disty..","..distz..")
  122.  
  123. moveX()
  124. curx, cury, curz = getPos()
  125. moveZ()
  126. curx, cury, curz = getPos()
  127. moveY()
  128. curx, cury, curz = getPos()
  129. print ("Current:","..curx..","..cury..","..curz.." )
  130. rednet.close("right")
Advertisement
Add Comment
Please, Sign In to add comment