Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local rocket_drawer = peripheral.wrap("functionalstorage:oak_4_0")
- local warhead_drawer = peripheral.wrap("functionalstorage:oak_4_1")
- local controller = peripheral.find("mekmissiles:missile_silo")
- local message_display = peripheral.wrap("monitor_1")
- local rocket_relay = peripheral.wrap("redstone_relay_5")
- local small_warhead_relay = peripheral.wrap("redstone_relay_7")
- local medium_warhead_relay = peripheral.wrap("redstone_relay_6")
- local large_warhead_relay = peripheral.wrap("redstone_relay_9")
- local huge_warhead_relay = peripheral.wrap("redstone_relay_8")
- local engine_item = "mekmissiles:rocket_engine"
- local body_item = "mekmissiles:rocket_body"
- local nose_item = "mekmissiles:rocket_nose_cone"
- local small_warhead = "mnwe:industrial_bomb"
- local medium_warhead = "mnwe:nuclear_bomb"
- local large_warhead = "mnwe:hydrogen_bomb"
- local huge_warhead = "mnwe:antimatter_bomb"
- function display_message(message, wait)
- if message_display then
- message_display.clear()
- message_display.setCursorPos(1, 1)
- message_display.write(message)
- else
- print("W: No message display found")
- print(message)
- end
- if wait then
- message_display.setCursorPos(1, 2)
- message_display.write("Press any button to continue...")
- os.pullEvent("redstone")
- os.sleep(1.1)
- end
- end
- if not rocket_drawer then
- display_message("No rocket parts storage drawer found")
- return
- end
- if not warhead_drawer then
- display_message("No warhead storage drawer found")
- return
- end
- if not controller then
- display_message("No missile silo controller found")
- return
- end
- ::begin::
- controller.pushItems(peripheral.getName(warhead_drawer), 4)
- controller.pushItems(peripheral.getName(rocket_drawer), 3)
- controller.pushItems(peripheral.getName(rocket_drawer), 2)
- controller.pushItems(peripheral.getName(rocket_drawer), 1)
- -- Wait for redstone signal to start assembly
- display_message("Rocket assembly system ready.")
- os.pullEvent("redstone")
- local relay_states = {
- rocket_relay.getInput("back"),
- small_warhead_relay.getInput("back"),
- medium_warhead_relay.getInput("back"),
- large_warhead_relay.getInput("back"),
- huge_warhead_relay.getInput("back")
- }
- if relay_states[2] or relay_states[3] or relay_states[4] or relay_states[5] then
- display_message("Please assemble the rocket first, then select the warhead type.")
- goto begin
- end
- local engine_slot = nil
- local body_slot = nil
- local nose_slot = nil
- local small_warhead_slot = nil
- local medium_warhead_slot = nil
- local large_warhead_slot = nil
- local huge_warhead_slot = nil
- for i = 1, rocket_drawer.size() do
- local item = rocket_drawer.getItemDetail(i)
- if item then
- if item.name == engine_item then
- engine_slot = i
- elseif item.name == body_item then
- body_slot = i
- elseif item.name == nose_item then
- nose_slot = i
- end
- end
- end
- for i = 1, warhead_drawer.size() do
- local item = warhead_drawer.getItemDetail(i)
- if item then
- if item.name == small_warhead then
- small_warhead_slot = i
- elseif item.name == medium_warhead then
- medium_warhead_slot = i
- elseif item.name == large_warhead then
- large_warhead_slot = i
- elseif item.name == huge_warhead then
- huge_warhead_slot = i
- end
- end
- end
- if not engine_slot then
- display_message("No rocket engine found in drawer", true)
- goto begin
- end
- if not body_slot then
- display_message("No rocket body found in drawer", true)
- goto begin
- end
- if not nose_slot then
- display_message("No rocket nose cone found in drawer", true)
- goto begin
- end
- rocket_drawer.pushItems(peripheral.getName(controller), engine_slot, 1)
- rocket_drawer.pushItems(peripheral.getName(controller), body_slot, 1)
- rocket_drawer.pushItems(peripheral.getName(controller), nose_slot, 1)
- ::warhead_selection::
- os.sleep(1.1)
- if not small_warhead_slot and not medium_warhead_slot and not large_warhead_slot and not huge_warhead_slot then
- display_message("No warheads found in drawer", true)
- goto begin
- end
- display_message("Rocket assembled, please select the warhead type.")
- os.pullEvent("redstone")
- relay_states = {
- rocket_relay.getInput("back"),
- small_warhead_relay.getInput("back"),
- medium_warhead_relay.getInput("back"),
- large_warhead_relay.getInput("back"),
- huge_warhead_relay.getInput("back")
- }
- os.sleep(1.1)
- if relay_states[1] then
- display_message("Rocket already assembled, please select warhead.", true)
- goto warhead_selection
- end
- local true_count = 0
- for i = 2, 5 do
- if relay_states[i] then
- true_count = true_count + 1
- end
- end
- if true_count > 1 then
- display_message("Please select only one warhead type.")
- goto warhead_selection
- end
- local selected_warhead_slot = nil
- if relay_states[2] then
- selected_warhead_slot = small_warhead_slot
- elseif relay_states[3] then
- selected_warhead_slot = medium_warhead_slot
- elseif relay_states[4] then
- selected_warhead_slot = large_warhead_slot
- elseif relay_states[5] then
- selected_warhead_slot = huge_warhead_slot
- end
- if not selected_warhead_slot then
- print(textutils.serialize(relay_states))
- display_message("Selected warhead not found in drawer", true)
- goto warhead_selection
- end
- warhead_drawer.pushItems(peripheral.getName(controller), selected_warhead_slot, 1)
- display_message("Warhead loaded into rocket.", true)
- goto begin
Advertisement
Add Comment
Please, Sign In to add comment