MegiRicky

ReloadGen4

Aug 4th, 2024 (edited)
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.91 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.  
  71. --unloader
  72.  
  73. sleep(0.2)
  74.  
  75. --placing magazine
  76. router2.setOutput("left",true)
  77. router2.setOutput("front", true)
  78. sleep(0.2)
  79. router2.setOutput("front", false)
  80. router2.setOutput("left",false)
  81. print("waiting for magazine")
  82. sleep(0.2)
  83. repeat
  84. sleep(0.01)
  85. counter = counter + 1
  86. if counter > 500 then
  87. print("Magazine not detected, manually override required")
  88. io.read()
  89. counter = 0
  90. end
  91. until redstone.getInput("left")
  92. counter = 0
  93. --loading step 1
  94. sleep(0.5)
  95. router1.setOutput("front", true)
  96. sleep(0.4)
  97. router1.setOutput("front", false)
  98. repeat
  99. sleep(0.01)
  100. counter = counter + 0.01
  101. if counter > 10 then
  102. print("Jammed, manually override required")
  103. io.read()
  104. counter = 0
  105. end
  106. until not(redstone.getInput("left"))
  107. sleep(counter)
  108. sleep(1)
  109. counter = 0
  110. print("step 1 loaded")
  111. --loading step 2
  112. router2.setOutput("top",true)
  113. sleep(0.3)
  114. router2.setOutput("top",false)
  115. repeat
  116. sleep(0.01)
  117. counter = counter + 1
  118. if counter > 500 then
  119. print("Magazine not detected, manually override required")
  120. io.read()
  121. counter = 0
  122. end
  123. until redstone.getInput("left")
  124. counter = 0
  125. sleep(0.2)
  126. router1.setOutput("front", true)
  127. sleep(0.4)
  128. router1.setOutput("front", false)
  129. repeat
  130. sleep(0.01)
  131. counter = counter + 0.01
  132. if counter > 10 then
  133. print("Jammed, manually override required")
  134. io.read()
  135. counter = 0
  136. end
  137. until not(redstone.getInput("left"))
  138. sleep(counter)
  139. sleep(1)
  140. counter = 0
  141. print("step 2 loaded")
  142. --loading step 3
  143. router2.setOutput("top",true)
  144. sleep(0.2)
  145. router2.setOutput("top",false)
  146. repeat
  147. sleep(0.01)
  148. counter = counter + 1
  149. if counter > 500 then
  150. print("Magazine not detected, manually override required")
  151. io.read()
  152. counter = 0
  153. end
  154. until redstone.getInput("left")
  155. counter = 0
  156. sleep(0.1)
  157. router1.setOutput("front", true)
  158. sleep(0.3)
  159. router1.setOutput("front", false)
  160. repeat
  161. sleep(0.01)
  162. counter = counter + 0.01
  163. if counter > 10 then
  164. print("Jammed, manually override required")
  165. io.read()
  166. counter = 0
  167. end
  168. until not(redstone.getInput("left"))
  169. sleep(counter)
  170. sleep(1)
  171. counter = 0
  172. print("step 3 loaded")
  173. --loading step 4
  174. router2.setOutput("top",true)
  175. sleep(0.2)
  176. router2.setOutput("top",false)
  177. repeat
  178. sleep(0.01)
  179. counter = counter + 1
  180. if counter > 500 then
  181. print("Magazine not detected, manually override required")
  182. io.read()
  183. counter = 0
  184. end
  185. until redstone.getInput("left")
  186. counter = 0
  187. sleep(0.2)
  188. router1.setOutput("front", true)
  189. sleep(0.3)
  190. router1.setOutput("front", false)
  191. repeat
  192. sleep(0.01)
  193. counter = counter + 0.01
  194. if counter > 10 then
  195. print("Jammed, manually override required")
  196. io.read()
  197. counter = 0
  198. end
  199. until not(redstone.getInput("left"))
  200. sleep(counter)
  201. counter = 0
  202. print("step 4 loaded")
  203. sleep(1)
  204. --resetting piston
  205. router2.setOutput("front",true)
  206. sleep(0.2)
  207. router2.setOutput("front",false)
  208. router1.setOutput("back",true)
  209. sleep(0.2)
  210. router1.setOutput("back",false)
  211. sleep(0.5)
  212.  
  213.  
  214. router2.setOutput("back",true)
  215. sleep(0.2)
  216. router2.setOutput("back",false)
  217. sleep(0.5)
  218. redstone.setOutput("top",true)
  219. print("Ready to fire")
  220. end
  221. sleep(0.1)
  222.  
  223.  
  224.  
  225.  
  226. end
Advertisement
Add Comment
Please, Sign In to add comment