mah17

Untitled

Mar 3rd, 2013
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.66 KB | None | 0 0
  1.  
  2.  
  3.  
  4. local tArgs = { ... }
  5.  
  6. local uY, count, tX, tY, tZ, face = 1, 1, tArgs[1], tArgs[2], tArgs[3], tArgs[4]
  7.  
  8. function faceSouth()
  9. tZ = tZ + 1
  10. if face == 'N' then
  11. turtle.turnLeft()
  12. turtle.turnLeft()
  13. elseif face == 'W' then
  14. turtle.turnLeft()
  15. elseif face == 'E' then
  16. turtle.turnRight()
  17. else
  18. faceUsage()
  19. return false
  20. end
  21. goToSky()
  22. end
  23.  
  24. function goToSky()
  25. while turtle.up() do
  26. uY = uY + 1
  27. end
  28. tY = tY + uY
  29. placeComputer()
  30. end
  31.  
  32. function goToGround()
  33. while turtle.down() do
  34. end
  35. end
  36.  
  37. function placeComputer()
  38. turtle.select(1)
  39. turtle.place()
  40. turtle.back()
  41. turtle.select(2)
  42. turtle.place()
  43. turtle.down()
  44. turtle.forward()
  45. turtle.select(4)
  46. turtle.place()
  47. turtle.select(3)
  48. turtle.drop()
  49. setComputer()
  50. end
  51.  
  52. function goToSouthPos()
  53. turtle.turnLeft()
  54. turtle.turnLeft()
  55. for i = 1, 4 do
  56. turtle.forward()
  57. tZ = tZ + 1
  58. end
  59. tZ = tZ + 2 -- + 2 to compensate for turtle pos before turning left and the pos the computer is placed
  60. placeComputer()
  61. end
  62.  
  63. function goToEastPos()
  64. turtle.down()
  65. turtle.down()
  66. turtle.down()
  67. tY = tY - 3
  68. for i = 1, 4 do
  69. turtle.forward()
  70. end
  71. tZ = tZ - 3
  72. turtle.turnRight()
  73. turtle.forward()
  74. turtle.forward()
  75. tX = tX + 3
  76. placeComputer()
  77. end
  78.  
  79. function goToWestPos()
  80. turtle.down()
  81. for i = 1, 6 do
  82. turtle.forward()
  83. tX = tX - 1
  84. end
  85. turtle.up()
  86. placeComputer()
  87. end
  88.  
  89. function setComputer()
  90. turtle.down()
  91. turtle.forward()
  92. turtle.forward()
  93. turtle.turnLeft()
  94. turtle.turnLeft()
  95. turtle.up()
  96. setUpDisk(tX,tY,tZ)
  97. turtle.up()
  98. peripheral.call("front", "turnOn")
  99. turtle.down()
  100. turtle.suck()
  101. turtle.dig()
  102. turtle.up()
  103. sleep(2)
  104. peripheral.call("front", "reboot")
  105. if count == 1 then
  106. count = count + 1
  107. goToSouthPos()
  108.  
  109. elseif count == 2 then
  110. count = count + 1
  111. goToEastPos()
  112.  
  113. elseif count == 3 then
  114. count = count + 1
  115. goToWestPos()
  116. elseif count == 4 then
  117. goToGround()
  118. end
  119. end
  120.  
  121. function setUpDisk(x,y,z)
  122. print("Computer number "..count)
  123. print("<x>"..x.." <y>"..y.." <z>"..z)
  124. local st = fs.open("disk/startup", "w")
  125. local gps_run = "shell.run('gps','host',"..x..","..y..","..z..")"
  126. st.writeLine("local startup = fs.open('startup', 'w')")
  127. st.writeLine("startup.writeLine(\""..gps_run.."\")")
  128. st.writeLine("startup.close()")
  129. st.close()
  130. end
  131.  
  132. function usage()
  133. print("usage:")
  134. print("setup_gps <x> <y> <z> <f>")
  135. end
  136.  
  137. function placingSetUp()
  138. print("---------------------------------------")
  139. print("Please place items in the following order:")
  140. print("Slot 1: 4x computers")
  141. print("Slot 2: 4x wirelesse modems")
  142. print("Slot 3: 1x floopy disk")
  143. print("Slot 4: 1x disk drive")
  144. print("---------------------------------------")
  145. end
  146.  
  147. function checkItems()
  148. if turtle.getItemCount(1) == 4
  149. and turtle.getItemCount(2) == 4
  150. and turtle.getItemCount(3) == 1
  151. and turtle.getItemCount(4) == 1
  152. then
  153. return true
  154. else
  155. placingSetUp()
  156. return false
  157. end
  158. end
  159.  
  160. function checkTurtleType()
  161.  
  162. turtle.select(4)
  163. turtle.place()
  164. if turtle.dig() then
  165. return true
  166. else
  167. print("You must use a mining turtle in order to run this program")
  168. return false
  169. end
  170. end
  171.  
  172. function faceUsage()
  173. print("-----------------")
  174. print("face parameter:")
  175. print("S if facing south")
  176. print("N if facing north")
  177. print("E if facing east")
  178. print("W if facing west")
  179. print("-----------------")
  180.  
  181. return false
  182. end
  183.  
  184. function checkArguments()
  185. if #tArgs ~= 4 then
  186. usage()
  187. return false
  188. elseif type(tonumber(tX)) ~= "number" then
  189. print("<x> has to be a number")
  190. return false
  191. elseif type(tonumber(tY)) ~= "number" then
  192. print("<y> has to be a number")
  193. return false
  194. elseif type(tonumber(tZ)) ~= "number" then
  195. print("<z> has to be a number")
  196. return false
  197. else
  198. return true
  199. end
  200. end
  201.  
  202. function checkFuel()
  203. if turtle.getFuelLevel() < 1000 then
  204. print("Not enough fuel")
  205. print("Fuel level has to be greater than 1000")
  206. return false
  207. else
  208. return true
  209. end
  210. end
  211.  
  212. function initialChecking()
  213. if tX == "help" then
  214. usage()
  215. placingSetUp()
  216. return false
  217. elseif checkTurtleType() == false
  218. or checkArguments() == false
  219. or checkFuel() == false
  220. or checkItems() == false
  221. then
  222. return false
  223. else
  224. return true
  225. end
  226. end
  227.  
  228. if initialChecking() == false then
  229. return false
  230. else
  231. faceSouth()
  232. end
Advertisement
Add Comment
Please, Sign In to add comment