gknova61

GPS Tower Builder

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