MegiRicky

ReloadGen4

Dec 19th, 2024
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.84 KB | None | 0 0
  1. local router1ID="redrouter_0"
  2. local router2ID="redrouter_1"
  3. local counter = 0
  4.  
  5. router1 = peripheral.find(router1ID)
  6. router2 = peripheral.find(router2ID)
  7.  
  8. print("Connect router1 and press enter")
  9. io.read()
  10. router1 = peripheral.find("redrouter")
  11. if not router1 then
  12. error("no router 1")
  13. end
  14. print("Disconnect router1 and connect router 2 and press enter")
  15. io.read()
  16. router2 = peripheral.find("redrouter")
  17. if not router2 then
  18. error("no router2")
  19. end
  20.  
  21. print("Connect router1 and router 2 and press enter")
  22. io.read()
  23.  
  24. if not router1 then
  25. error("no router 1")
  26. end
  27. if not router2 then
  28. error("no router2")
  29. end
  30.  
  31. router1.setOutput("top",false)
  32. router1.setOutput("left",false)
  33. router1.setOutput("front",false)
  34. router2.setOutput("top",false)
  35. router2.setOutput("front",false)
  36. router2.setOutput("left",false)
  37. while true do
  38. if redstone.getAnalogInput("bottom")==15 then
  39. redstone.setOutput("top",false)
  40. redstone.setOutput("left",false)
  41. redstone.setOutput("right",false)
  42. redstone.setOutput("front",false)
  43. router1.setOutput("top",false)
  44. router1.setOutput("left",false)
  45. router1.setOutput("front",false)
  46. router2.setOutput("top",false)
  47. router2.setOutput("front",false)
  48. router2.setOutput("left",false)
  49. end
  50. if redstone.getAnalogInput("front")==15 then
  51.  
  52. --mianhub
  53. redstone.setOutput("top", false)
  54. print("Removing screw")
  55. sleep(0.2)
  56. router1.setOutput("back", true)
  57. sleep(0.2)
  58. router1.setOutput("back", false)
  59. --[[repeat
  60. sleep(0.01)
  61. counter = counter + 1
  62. if counter > 500 then
  63. print("fail to remove screw, manually override required")
  64. io.read()
  65. counter = 0
  66. end
  67. until not(redstone.getInput("left"))]]
  68. counter = 0
  69. print("Screw removed")
  70. sleep(0.2)
  71.  
  72. --[[unloader
  73. router1.setOutput("left", true)
  74. sleep(0.2)
  75. router1.setOutput("left", false)
  76. sleep(0.5)
  77. router1.setOutput("front", true)
  78. sleep(0.5)
  79. router1.setOutput("front", false)
  80. print("removing empty cartridge")
  81. repeat
  82. sleep(0.01)
  83. counter = counter + 1
  84. if counter > 500 then
  85. print("fail to remove empty cratrige, manually override required, enter -1 if it is normal")
  86. read = io.read()
  87. counter = 0
  88.  
  89. end
  90. until (redstone.getInput("left") or read == "-1")
  91. counter = 0
  92.  
  93. router1.setOutput("top", true)
  94. sleep(1)
  95. router1.setOutput("top", false)
  96. sleep(0.2)
  97. print("cannon unloaded")]]
  98.  
  99. --placing magazine
  100. router2.setOutput("left",true)
  101. router2.setOutput("front", true)
  102. sleep(0.2)
  103. router2.setOutput("front", false)
  104. router2.setOutput("left",false)
  105. print("waiting for magazine")
  106. sleep(0.4)
  107. --[[repeat
  108. sleep(0.01)
  109. counter = counter + 1
  110. if counter > 500 then
  111. print("Magazine not detected, manually override required")
  112. io.read()
  113. counter = 0
  114. end
  115. until redstone.getInput("left")]]
  116. counter = 0
  117. --loading step 1
  118. sleep(0.5)
  119. router1.setOutput("front", true)
  120. sleep(0.4)
  121. router1.setOutput("front", false)
  122. --[[repeat
  123. sleep(0.01)
  124. counter = counter + 0.01
  125. if counter > 10 then
  126. print("Jammed, manually override required")
  127. io.read()
  128. counter = 0
  129. end
  130. until not(redstone.getInput("left"))
  131. sleep(counter)]]
  132. sleep(1)
  133. counter = 0
  134. print("step 1 loaded")
  135. --loading step 2
  136. router2.setOutput("top",true)
  137. sleep(0.3)
  138. router2.setOutput("top",false)
  139. --[[repeat
  140. sleep(0.01)
  141. counter = counter + 1
  142. if counter > 500 then
  143. print("Magazine not detected, manually override required")
  144. io.read()
  145. counter = 0
  146. end
  147. until redstone.getInput("left")
  148. counter = 0]]
  149. sleep(0.2)
  150. router1.setOutput("front", true)
  151. sleep(0.4)
  152. router1.setOutput("front", false)
  153. --[[repeat
  154. sleep(0.01)
  155. counter = counter + 0.01
  156. if counter > 10 then
  157. print("Jammed, manually override required")
  158. io.read()
  159. counter = 0
  160. end
  161. until not(redstone.getInput("left"))
  162. sleep(counter)]]
  163. sleep(1)
  164. counter = 0
  165. print("step 2 loaded")
  166. --loading step 3
  167. router2.setOutput("top",true)
  168. sleep(0.2)
  169. router2.setOutput("top",false)
  170. --[[repeat
  171. sleep(0.01)
  172. counter = counter + 1
  173. if counter > 500 then
  174. print("Magazine not detected, manually override required")
  175. io.read()
  176. counter = 0
  177. end
  178. until redstone.getInput("left")]]
  179. counter = 0
  180. sleep(0.1)
  181. router1.setOutput("front", true)
  182. sleep(0.3)
  183. router1.setOutput("front", false)
  184. --[[repeat
  185. sleep(0.01)
  186. counter = counter + 0.01
  187. if counter > 10 then
  188. print("Jammed, manually override required")
  189. io.read()
  190. counter = 0
  191. end
  192. until not(redstone.getInput("left"))
  193. sleep(counter)]]
  194. sleep(1)
  195. counter = 0
  196. print("step 3 loaded")
  197. --loading step 4
  198. router2.setOutput("top",true)
  199. sleep(0.2)
  200. router2.setOutput("top",false)
  201. --[[repeat
  202. sleep(0.01)
  203. counter = counter + 1
  204. if counter > 500 then
  205. print("Magazine not detected, manually override required")
  206. io.read()
  207. counter = 0
  208. end
  209. until redstone.getInput("left")]]
  210. counter = 0
  211. sleep(0.2)
  212. router1.setOutput("front", true)
  213. sleep(0.3)
  214. router1.setOutput("front", false)
  215. --[[repeat
  216. sleep(0.01)
  217. counter = counter + 0.01
  218. if counter > 10 then
  219. print("Jammed, manually override required")
  220. io.read()
  221. counter = 0
  222. end
  223. until not(redstone.getInput("left"))
  224. sleep(counter)]]
  225. counter = 0
  226. print("step 4 loaded")
  227. sleep(1.5)
  228. --resetting piston
  229. router2.setOutput("front",true)
  230. sleep(0.2)
  231. router2.setOutput("front",false)
  232. router1.setOutput("back",true)
  233. sleep(0.2)
  234. router1.setOutput("back",false)
  235. sleep(0.5)
  236.  
  237. router2.setOutput("back",true)
  238. sleep(0.2)
  239. router2.setOutput("back",false)
  240. sleep(0.5)
  241. redstone.setOutput("top",true)
  242. print("Ready to fire")
  243. end
  244. sleep(0.1)
  245. end
Advertisement
Add Comment
Please, Sign In to add comment