Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Midway Relay Program (Event-Driven Version)
- -- For Stargate Journey + ComputerCraft Tweaked
- -- Supports a 2x2 monitor and two crystal interfaces (Milky Way & Pegasus)
- local gate_1 = peripheral.wrap("crystal_interface_27") -- Milky Way
- local gate_2 = peripheral.wrap("crystal_interface_26") -- Pegasus
- local monitor = peripheral.find("monitor") -- Assumes 2x2 monitor
- local lantea_address = {29, 5, 17, 34, 6, 12, 0} --modify if needed
- local return_address = {27, 25, 4, 35, 10, 28, 0} --you can set it to an 8th chevron address for specific dialing
- local timeout_timer = nil
- local awaiting_confirmation = false
- local active_gate = nil
- local status = "Idle"
- -- === Monitor UI ===
- local function center(text, y)
- local w, _ = monitor.getSize()
- local x = math.floor((w - #text) / 2) + 1
- monitor.setCursorPos(x, y)
- monitor.write(text)
- end
- local function drawScreen()
- monitor.setBackgroundColor(colors.black)
- monitor.clear()
- monitor.setTextColor(colors.lime)
- center("Midway Relay Active", 1)
- monitor.setTextColor(colors.white)
- center("Status: " .. status, 2)
- if awaiting_confirmation then
- monitor.setCursorPos(6, 4)
- monitor.setBackgroundColor(colors.gray)
- monitor.setTextColor(colors.black)
- monitor.write(" CONFIRM ")
- end
- monitor.setBackgroundColor(colors.black)
- end
- local function waitForConfirmation()
- awaiting_confirmation = true
- drawScreen()
- while true do
- local event, side, x, y = os.pullEvent("monitor_touch")
- if x >= 6 and x <= 13 and y == 4 then
- awaiting_confirmation = false
- drawScreen()
- return true
- end
- end
- end
- -- === Dial Logic ===
- local function dialAddress(gate, address)
- if not gate then return false end
- for _, symbol in ipairs(address) do
- local ok, err = pcall(function() gate.engageSymbol(symbol) end)
- if not ok then
- print("Dial error at symbol:", symbol, "->", err)
- return false
- end
- os.sleep(0.5)
- end
- return true
- end
- -- === Event Loop ===
- print("Midway Event Relay Started")
- drawScreen()
- while true do
- local event, param1, param2 = os.pullEvent()
- if event == "sgJourney_incoming_wormhole" then
- local iface = param1
- print("Incoming wormhole on:", iface)
- if iface == "crystal_interface_27" then
- status = "Incoming Gate 1"
- drawScreen()
- active_gate = gate_2
- if waitForConfirmation() then
- status = "Dialing Lantea"
- drawScreen()
- dialAddress(gate_2, lantea_address)
- timeout_timer = os.startTimer(20)
- end
- elseif iface == "crystal_interface_26" then
- status = "Incoming Gate 2"
- drawScreen()
- active_gate = gate_1
- if waitForConfirmation() then
- status = "Dialing Return"
- drawScreen()
- dialAddress(gate_1, return_address)
- end
- end
- elseif event == "sgJourney_gate_closed" then
- local iface = param1
- print("Gate closed:", iface)
- status = "Idle"
- drawScreen()
- elseif event == "timer" and param1 == timeout_timer then
- print("Timeout reached: closing Pegasus gate")
- if gate_2 then gate_2.disconnect() end
- status = "Pegasus Timed Out"
- timeout_timer = nil
- drawScreen()
- end
- end
Advertisement
Advertisement