Advertisement
oswald_the_void

Midway Dialing Program V3

May 4th, 2025 (edited)
168
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- Midway Relay Program (Event-Driven Version)
  2. -- For Stargate Journey + ComputerCraft Tweaked
  3. -- Supports a 2x2 monitor and two crystal interfaces (Milky Way & Pegasus)
  4.  
  5. local gate_1 = peripheral.wrap("crystal_interface_27") -- Milky Way
  6. local gate_2 = peripheral.wrap("crystal_interface_26") -- Pegasus
  7. local monitor = peripheral.find("monitor") -- Assumes 2x2 monitor
  8.  
  9. local lantea_address = {29, 5, 17, 34, 6, 12, 0} --modify if needed
  10. local return_address = {27, 25, 4, 35, 10, 28, 0} --you can set it to an 8th chevron address for specific dialing
  11.  
  12. local timeout_timer = nil
  13. local awaiting_confirmation = false
  14. local active_gate = nil
  15. local status = "Idle"
  16.  
  17. -- === Monitor UI ===
  18. local function center(text, y)
  19.     local w, _ = monitor.getSize()
  20.     local x = math.floor((w - #text) / 2) + 1
  21.     monitor.setCursorPos(x, y)
  22.     monitor.write(text)
  23. end
  24.  
  25. local function drawScreen()
  26.     monitor.setBackgroundColor(colors.black)
  27.     monitor.clear()
  28.     monitor.setTextColor(colors.lime)
  29.     center("Midway Relay Active", 1)
  30.     monitor.setTextColor(colors.white)
  31.     center("Status: " .. status, 2)
  32.  
  33.     if awaiting_confirmation then
  34.         monitor.setCursorPos(6, 4)
  35.         monitor.setBackgroundColor(colors.gray)
  36.         monitor.setTextColor(colors.black)
  37.         monitor.write(" CONFIRM ")
  38.     end
  39.     monitor.setBackgroundColor(colors.black)
  40. end
  41.  
  42. local function waitForConfirmation()
  43.     awaiting_confirmation = true
  44.     drawScreen()
  45.  
  46.     while true do
  47.         local event, side, x, y = os.pullEvent("monitor_touch")
  48.         if x >= 6 and x <= 13 and y == 4 then
  49.             awaiting_confirmation = false
  50.             drawScreen()
  51.             return true
  52.         end
  53.     end
  54. end
  55.  
  56. -- === Dial Logic ===
  57. local function dialAddress(gate, address)
  58.     if not gate then return false end
  59.     for _, symbol in ipairs(address) do
  60.         local ok, err = pcall(function() gate.engageSymbol(symbol) end)
  61.         if not ok then
  62.             print("Dial error at symbol:", symbol, "->", err)
  63.             return false
  64.         end
  65.         os.sleep(0.5)
  66.     end
  67.     return true
  68. end
  69.  
  70. -- === Event Loop ===
  71. print("Midway Event Relay Started")
  72. drawScreen()
  73.  
  74. while true do
  75.     local event, param1, param2 = os.pullEvent()
  76.  
  77.     if event == "sgJourney_incoming_wormhole" then
  78.         local iface = param1
  79.         print("Incoming wormhole on:", iface)
  80.  
  81.         if iface == "crystal_interface_27" then
  82.             status = "Incoming Gate 1"
  83.             drawScreen()
  84.             active_gate = gate_2
  85.  
  86.             if waitForConfirmation() then
  87.                 status = "Dialing Lantea"
  88.                 drawScreen()
  89.                 dialAddress(gate_2, lantea_address)
  90.                 timeout_timer = os.startTimer(20)
  91.             end
  92.  
  93.         elseif iface == "crystal_interface_26" then
  94.             status = "Incoming Gate 2"
  95.             drawScreen()
  96.             active_gate = gate_1
  97.  
  98.             if waitForConfirmation() then
  99.                 status = "Dialing Return"
  100.                 drawScreen()
  101.                 dialAddress(gate_1, return_address)
  102.             end
  103.         end
  104.  
  105.     elseif event == "sgJourney_gate_closed" then
  106.         local iface = param1
  107.         print("Gate closed:", iface)
  108.         status = "Idle"
  109.         drawScreen()
  110.  
  111.     elseif event == "timer" and param1 == timeout_timer then
  112.         print("Timeout reached: closing Pegasus gate")
  113.         if gate_2 then gate_2.disconnect() end
  114.         status = "Pegasus Timed Out"
  115.         timeout_timer = nil
  116.         drawScreen()
  117.     end
  118. end
Advertisement
Comments
Add Comment
Please, Sign In to add comment
Advertisement