ErolDude

Gps builder

May 11th, 2013
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.09 KB | None | 0 0
  1. local tArgs = { ... }
  2. if #tArgs < 4 then
  3. print("Usage : satelite <x> <y> <z> <f>")
  4. return
  5. end
  6. local Xpos = tonumber(tArgs[1])
  7. local Ypos = tonumber(tArgs[2])
  8. local Zpos = tonumber(tArgs[3])
  9. local facing = tonumber(tArgs[4])
  10.  
  11. function buildUp(floppySlot)
  12. -- Put the disk drive
  13. turtle.select(3)
  14. turtle.place()
  15. -- Load disk into drive and write startup file
  16. turtle.select(floppySlot)
  17. turtle.drop()
  18. file = fs.open("disk/startup","w")
  19. file.writeLine("shell.run(\"gps\",\"host\","..Xpos..","..Ypos..","..Zpos..")")
  20. file.close()
  21. -- put the computer
  22. turtle.up()
  23. turtle.select(2)
  24. turtle.place()
  25. -- place the modem
  26. turtle.up()
  27. turtle.up()
  28. turtle.forward()
  29. turtle.select(4)
  30. turtle.placeDown()
  31. turtle.back()
  32. turtle.down()
  33. turtle.down()
  34. -- turn computer on
  35. computer = peripheral.wrap("front")
  36. sleep(0.5)
  37. if computer then
  38. computer.turnOn()
  39. end
  40. turtle.down()
  41. end
  42.  
  43. if type(Xpos) ~= "number" then
  44. print("x must be number")
  45. return
  46. end
  47. if type(Ypos) ~= "number" then
  48. print("y must be number")
  49. return
  50. end
  51. if type(Zpos) ~= "number" then
  52. print("z must be number")
  53. return
  54. end
  55. if type(facing) ~= "number" then
  56. print("facing must be number")
  57. return
  58. end
  59. print("Please fill up following slots")
  60. print("1 = Fuel")
  61. print("2 = Computer (4x)")
  62. print("3 = Disk drive (4x)")
  63. print("4 = Modem (4x)")
  64. print("5 - 8 = Floppy disk (4x)")
  65. print("Press any key to continue")
  66. while true do
  67. event, param1 = os.pullEvent()
  68. if event == "char" then
  69. break
  70. end
  71. end
  72. while turtle.getItemCount(1) > 0 do
  73. turtle.refuel()
  74. end
  75. print("Fuel level is "..turtle.getFuelLevel())
  76. print("Going up to 100 meter to build satelite")
  77. for height = 1, 100, 1 do
  78. turtle.up()
  79. end
  80. Ypos = Ypos + 101
  81. -- Go 10 forward to set the first computer
  82. for c = 1, 10, 1 do
  83. turtle.forward()
  84. end
  85. if facing == 0 then
  86. Zpos = Zpos + 11
  87. end
  88. if facing == 2 then
  89. Zpos = Zpos - 11
  90. end
  91. if facing == 1 then
  92. Xpos = Xpos - 11
  93. end
  94. if facing == 3 then
  95. Xpos = Xpos + 11
  96. end
  97. buildUp(5)
  98. -- Go back 20 and put the second computer
  99. turtle.turnRight()
  100. turtle.turnRight()
  101. if facing == 0 then
  102. facing = 2
  103. elseif facing == 1 then
  104. facing = 3
  105. elseif facing == 2 then
  106. facing = 0
  107. elseif facing == 3 then
  108. facing = 1
  109. end
  110. for c = 1, 20, 1 do
  111. turtle.forward()
  112. end
  113. if facing == 0 then
  114. Zpos = Zpos + 22
  115. end
  116. if facing == 2 then
  117. Zpos = Zpos - 22
  118. end
  119. if facing == 1 then
  120. Xpos = Xpos - 22
  121. end
  122. if facing == 3 then
  123. Xpos = Xpos + 22
  124. end
  125. buildUp(6)
  126. -- go 10 forward to the middle
  127. turtle.turnRight()
  128. turtle.turnRight()
  129. if facing == 0 then
  130. facing = 2
  131. elseif facing == 1 then
  132. facing = 3
  133. elseif facing == 2 then
  134. facing = 0
  135. elseif facing == 3 then
  136. facing = 1
  137. end
  138. for c = 1, 10, 1 do
  139. turtle.forward()
  140. end
  141. if facing == 0 then
  142. Zpos = Zpos + 11
  143. end
  144. if facing == 2 then
  145. Zpos = Zpos - 11
  146. end
  147. if facing == 1 then
  148. Xpos = Xpos - 11
  149. end
  150. if facing == 3 then
  151. Xpos = Xpos + 11
  152. end
  153. -- and 10 more up
  154. for c = 1, 10, 1 do
  155. turtle.up()
  156. end
  157. Ypos = Ypos + 10
  158. -- turn 90 degree to setup the second row
  159. turtle.turnRight()
  160. facing = facing + 1
  161. if facing == 4 then
  162. facing = 0
  163. end
  164. -- Go 10 forward to set the third computer
  165. for c = 1, 10, 1 do
  166. turtle.forward()
  167. end
  168. if facing == 0 then
  169. Zpos = Zpos + 11
  170. end
  171. if facing == 2 then
  172. Zpos = Zpos - 11
  173. end
  174. if facing == 1 then
  175. Xpos = Xpos - 11
  176. end
  177. if facing == 3 then
  178. Xpos = Xpos + 11
  179. end
  180. buildUp(7)
  181. -- Go back 20 and put the last computer
  182. turtle.turnRight()
  183. turtle.turnRight()
  184. if facing == 0 then
  185. facing = 2
  186. elseif facing == 1 then
  187. facing = 3
  188. elseif facing == 2 then
  189. facing = 0
  190. elseif facing == 3 then
  191. facing = 1
  192. end
  193. for c = 1, 20, 1 do
  194. turtle.forward()
  195. end
  196. if facing == 0 then
  197. Zpos = Zpos + 22
  198. end
  199. if facing == 2 then
  200. Zpos = Zpos - 22
  201. end
  202. if facing == 1 then
  203. Xpos = Xpos - 22
  204. end
  205. if facing == 3 then
  206. Xpos = Xpos + 22
  207. end
  208. buildUp(8)
  209. -- go 10 forward to the middle
  210. turtle.turnRight()
  211. turtle.turnRight()
  212. for c = 1, 10, 1 do
  213. turtle.forward()
  214. end
  215. -- and back to earth
  216. while not turtle.detectDown() do
  217. turtle.down()
  218. end
Add Comment
Please, Sign In to add comment