willisshek

[Minecraft] Deploy Signal Repeater

Oct 14th, 2017
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.87 KB | None | 0 0
  1. --
  2. --Signal Repeater deploy by WillisS
  3. --Using thw code from GPS Deploy by neonerZ v1.1
  4. --(http://youtube.com/neonerz)
  5. --
  6. --
  7. --
  8. --
  9. -- In order to use this script you need to setup
  10. -- either a mining turtle, or a standard turtle
  11. -- Slot 1 - Fuel
  12. -- Slot 2 - At least 1 computers
  13. -- Slot 3 - At least 1 modems
  14. -- Slot 4 - At lease 1 disk drive
  15. -- Slot 5 - 1 Disk
  16. --
  17. --
  18.  
  19.  
  20. -- How heigh up should the satellite be deployed?
  21. local height = 254
  22.  
  23.  
  24. local function printUsage()
  25. print("")
  26. print( "Usages:" )
  27. print( "deploySignalRepeater [current y] [height]" )
  28. end
  29.  
  30. -- confirm default height isn't set above 254
  31. -- Check to see if a minimum of 3 values were
  32. -- passed to the script
  33. local args = { ... }
  34.  
  35. if args[1] == "-u" then
  36. printUsage()
  37. elseif args[1] == nil then
  38. -- use gps
  39. rednet.open("right")
  40. local x, y, z = gps.locate()
  41. height = height - tonumber(y)
  42. else
  43. if args[2] ~= nil then
  44. height = tonumber(args[2])
  45. else
  46. height = height - tonumber(args[1])
  47. end
  48. end
  49.  
  50. if height > 254 then
  51. height = 254
  52. end
  53.  
  54. -- check if the script is running on a turtle
  55. -- (original code)
  56. if not turtle then
  57. print("")
  58. print("Error: not a turtle")
  59. return
  60. end
  61.  
  62. -- move functions
  63. -- (original code)
  64. local mov = {}
  65.  
  66. mov.forward = function ()
  67. while not turtle.forward() do
  68. sleep(1)
  69. end
  70. return true
  71. end
  72. mov.back = function ()
  73. while not turtle.back() do
  74. sleep(1)
  75. end
  76. return true
  77. end
  78. mov.up = function ()
  79. while not turtle.up() do
  80. sleep(1)
  81. end
  82. return true
  83. end
  84. mov.down = function ()
  85. while not turtle.down() do
  86. sleep(1)
  87. end
  88. return true
  89. end
  90. mov.place = function ()
  91. while not turtle.place() do
  92. sleep(1)
  93. end
  94. end
  95. mov.placeUp = function ()
  96. while not turtle.placeUp() do
  97. sleep(1)
  98. end
  99. end
  100.  
  101. local base = nil
  102.  
  103. -- Check if we have enough fuel
  104. -- we estimate the fuel usage ((height*2)+70) needed to
  105. -- complete the deoployment and then see if we have enough
  106. -- fuel loaded. If we don't, it checks the first slot for
  107. -- available fuel and tries to fill up on it. If it doesn't
  108. -- have enough fuel in there, it prompts the user for more
  109. -- fuel. It allows 30 seconds for the user to add fuel
  110. -- (trying to refuel and verify fuel level every second)
  111. -- and if it doesn't get it's fill within 30 seconds
  112. -- it exits with a message to the user
  113. -- neonerZ
  114. if type(turtle.getFuelLevel()) == "string" then
  115. print("No-fuel mode")
  116. else
  117. if turtle.getFuelLevel() < (tonumber(height)*2)+70 then
  118. while turtle.getFuelLevel() < (tonumber(height)*2)+70 do
  119. turtle.select(1)
  120. realcoal=(((tonumber(height)*2)+70)-turtle.getFuelLevel())/80
  121. if realcoal>=64 then
  122. coal=64
  123. else
  124. coal=math.ceil(realcoal)
  125. end
  126. if turtle.refuel(tonumber(coal)) == false then
  127. fuel=((tonumber(height)*2)+70)-turtle.getFuelLevel()
  128. print("")
  129. print("You ran out of fuel in slot 1")
  130. print("Please insert "..fuel.." fuel or "..realcoal.." coal to continue")
  131. print("Waiting 30 seconds for fuel or exiting")
  132. i=0
  133. while i<=30 do
  134. sleep(1)
  135. realcoal=(((tonumber(height)*2)+70)-turtle.getFuelLevel())/80
  136. if realcoal>=64 then
  137. coal=64
  138. else
  139. coal=math.ceil(realcoal)
  140. end
  141. turtle.refuel(tonumber(coal))
  142. if turtle.getFuelLevel() >= (tonumber(height)*2)+70 then
  143. print("")
  144. print("Turtle Fueled")
  145. i=31
  146. end
  147. if i==30 then
  148. fuel=((tonumber(height)*2)+70)-turtle.getFuelLevel()
  149. print("")
  150. print("Not enough fuel provided")
  151. print("Please provide "..fuel.." fuel or "..realcoal.." coal and try again")
  152. return
  153. end
  154. i=i+1
  155. end
  156. end
  157. end
  158. end
  159. end
  160.  
  161. -- check if the required quantity of items
  162. -- are in the appropriate spots. I'm sure
  163. -- there's a more elegant way of doing this.
  164. -- I don't believe there's a way to check if
  165. -- the items are correct without using compare
  166. monitor=0
  167. modem=0
  168. diskdrive=0
  169. disk=0
  170. print("")
  171. turtle.select(2)
  172. if turtle.getItemCount(2) < 1 then
  173. print("Please place at least 4 computers into slot two")
  174. monitor=1
  175. end
  176. turtle.select(3)
  177. if turtle.getItemCount(2) < 1 then
  178. print("Please place at least 4 modems into slot three")
  179. modem=1
  180. end
  181. turtle.select(4)
  182. if turtle.getItemCount(2) < 1 then
  183. print("Please place 1 disk drive into slot four")
  184. diskdrive=1
  185. end
  186. turtle.select(5)
  187. if turtle.getItemCount(2) < 1 then
  188. print("Please place 1 disk into slot five")
  189. disk=1
  190. end
  191.  
  192. if monitor == 1 or modem == 1 or diskdrive == 1 or disk == 1 then
  193. print("Please fix above issues to continue")
  194. return
  195. end
  196.  
  197. -- start the climb up to the correct ycord
  198. while not turtle.up() do
  199. term.clear()
  200. term.setCursorPos(1,1)
  201. term.write("Please get off me")
  202. end
  203. for i = 3,tonumber(height) do
  204. turtle.up()
  205. end
  206.  
  207. -- once at the correct height, deploy
  208. turtle.select(2)
  209. mov.placeUp()
  210. mov.down()
  211. turtle.select(3)
  212. mov.placeUp()
  213. mov.back()
  214. mov.up()
  215. turtle.select(4)
  216. mov.placeUp()
  217. turtle.select(5)
  218. turtle.dropUp()
  219.  
  220. -- make a custom disk that starts up the gps host application
  221. -- with the correct coordinates and copy it over. also makes
  222. -- makes it a startup script so the computers will
  223. -- start back up properly after chunk unloading
  224. fs.delete("disk/startup")
  225. file = fs.open("disk/startup","w")
  226. file.write([[
  227. fs.copy("disk/install","startup")
  228. fs.delete("disk/startup")
  229. print("sleep in 10")
  230. sleep(10)
  231. os.reboot()
  232. ]])
  233. file.close()
  234. file = fs.open("disk/install","w")
  235. file.write([[
  236. shell.run("repeat")
  237. ]])
  238. file.close()
  239. turtle.turnLeft()
  240. mov.forward()
  241. mov.up()
  242. turtle.turnRight()
  243. mov.forward()
  244. turtle.turnRight()
  245. peripheral.call("front","turnOn")
  246. turtle.turnRight()
  247. mov.forward()
  248. turtle.turnLeft()
  249. turtle.suck()
  250. turtle.select(3)
  251. turtle.dig()
  252.  
  253. -- goes back down. this is the original code
  254. mov.down()
  255. mov.down()
  256. mov.forward()
  257. turtle.turnLeft()
  258. mov.forward()
  259. while turtle.down() do
  260. end
  261. turtle = tMove
  262. print("")
  263. print("Finished")
Advertisement
Add Comment
Please, Sign In to add comment