MegiRicky

BigCannonReloadGen4

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