Advertisement
samuelask

Hiddengatenibiru

Jan 12th, 2025 (edited)
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.45 KB | None | 0 0
  1. local term = require("term")
  2. local component = require("component")
  3. local modem = component.modem
  4. local reds = component.redstone
  5. local sg = component.stargate
  6. local zpm = component.zpmhub
  7. local sides = require("sides")
  8. local colors = require("colors")
  9. local port = 1234
  10. local asd = 1
  11. local IDC = "1337"
  12. local event = require("event")
  13. local os = require("os")
  14. local computer = require("computer")
  15. local serialization = require("serialization")
  16. local currentSymbolCount = 0 -- Tracks the number of successfully engaged symbols
  17. pressedbutton = 0
  18. address = {"Glyph 24","Glyph 13","Glyph 30","Glyph 11","Glyph 6","Glyph 12","Glyph 2","Glyph 17"}
  19. print("Redstone Dialer")
  20. print("--------------------------------------------------------------------------------------------------------------------------------------------------------------")
  21. print()
  22. -- Function to listen for incoming wormhole stabilization
  23. local function handleIncomingWormhole(address, caller, dialedAddressSize)
  24.     zpm.toggleSlots()
  25.     print("Incoming wormhole detected!")
  26.     print("Address: " .. tostring(address))
  27.     print("Caller: " .. tostring(caller))
  28.     print("Dialed Address Size: " .. tostring(dialedAddressSize))
  29.     local wormholeEventID = event.listen("stargate_wormhole_stabilized", function(_, _, _, isInitiating)
  30.         if not isInitiating then
  31.             print("Incoming wormhole detected.")
  32.              local receivedCodeEventID = event.listen("received_code", function(_, _, _, code)
  33.                 if code == IDC then
  34.                     print("IDC Accepted.")
  35.                     if sg.getIrisState() == "CLOSED" then
  36.                         sg.toggleIris()
  37.                         zpm.toggleSlots()
  38.                         if IrisType == "SHIELD" then
  39.                             sg.sendMessageToIncoming("Shield is Off!")
  40.                         else
  41.                             sg.sendMessageToIncoming("Iris is Open!")
  42.                         end
  43.                     end
  44.                 elseif IDC ~= code and sg.getIrisState() == "CLOSED" then
  45.                     print("Incorrect IDC.")
  46.                     sg.sendMessageToIncoming("IDC Incorrect!")
  47.                 end
  48.             end)
  49.             -- Remove the listener after handling
  50.             event.ignore("received_code", receivedCodeEventID)
  51.         end
  52.     end)
  53.     return wormholeEventID
  54. end
  55. local function abortDialing(reason)
  56.     if sg.getGateStatus() ~= "idle" then
  57.         print("Dialing aborted: " .. reason)
  58.         sg.disengageGate()
  59.         pressedbutton = 0
  60.     end
  61. end
  62. local function handleStargateFailed(_, address, caller, reason)
  63.     if reason == "aborted" then
  64.         print("Dialing sequence aborted by Universe Dialer.")
  65.         abortDialing(reason)
  66.     elseif reason == "address_malformed" then
  67.         print("Dialing failed: Address malformed.")
  68.         abortDialing(reason)
  69.     elseif reason == "not_enough_power" then
  70.         print("Dialing failed: Not enough power.")
  71.         abortDialing(reason)
  72.     else
  73.         print("Unknown failure reason: " .. reason)
  74.     end
  75. end
  76. -- Function to engage a symbol and wait for confirmation
  77. local function engageSymbolAndWait(glyph, expectedSymbolCount)
  78.     local success = false
  79.     local lockDetected = false
  80.  
  81.     -- Define the event handler function
  82.     local function onGlyphEngaged(_, _, _, symbolCount, lock, glyphName)
  83.         print("Event Triggered: stargate_spin_chevron_engaged")
  84.         print("Details: symbolCount=" .. symbolCount .. ", lock=" .. tostring(lock) .. ", glyphName=" .. glyphName)
  85.         if glyphName == glyph and symbolCount == expectedSymbolCount then
  86.             print("Glyph successfully engaged: " .. glyphName .. " (Symbol Count: " .. symbolCount .. ")")
  87.             success = true
  88.         end
  89.  
  90.         -- If this is the last glyph, confirm `lock` is true
  91.         if lock and symbolCount == #address then
  92.             print("Last glyph engaged and address is valid.")
  93.             lockDetected = true
  94.         end
  95.     end
  96.  
  97.     -- Call `sg.engageSymbol` and wait for confirmation
  98.     print("Engaging glyph: " .. glyph)
  99.     local result = sg.engageSymbol(glyph)
  100.    
  101.     print("Raw result from engageSymbol:", result)
  102.    
  103.     if result ~= "stargate_spin" then
  104.         print("Failed to initiate glyph engagement: " .. glyph)
  105.         print("Error Details: ", result and result.stargate_failure or "No failure info")
  106.         abortDialing("Glyph engagement failure")
  107.         return false, lockDetected
  108.     end
  109.    
  110.     event.listen("stargate_spin_chevron_engaged", onGlyphEngaged)
  111.    
  112.     -- Wait for the event to confirm success
  113.     local timeout = 20 -- Timeout in seconds
  114.     local elapsed = 0
  115.     while not success and elapsed < timeout do
  116.         os.sleep(0.1)
  117.         elapsed = elapsed + 0.1
  118.     end
  119.  
  120.     -- Cleanup the event listener
  121.     event.ignore("stargate_spin_chevron_engaged", onGlyphEngaged)
  122.  
  123.     if not success then
  124.         print("Timeout waiting for glyph engagement: " .. glyph)
  125.         return false, lockDetected
  126.     end
  127.  
  128.     return true, lockDetected
  129. end
  130.  
  131. local function eventListener()
  132. -- Start listening for incoming wormholes
  133. wormholeEventID = event.listen("stargate_incoming_wormhole", handleIncomingWormhole)
  134. end
  135. -- Start listening for Stargate failures
  136. local failureEventID = event.listen("stargate_failed", handleStargateFailed)
  137.  
  138. if wormholeEventID then
  139.     print("Wormhole event listener successfully registered!")
  140. else
  141.     print("Failed to register wormhole event listener.")
  142. end
  143.  
  144. local function main()
  145.         -- Run the listener in a separate coroutine
  146.         require("thread").create(eventListener)
  147.     repeat
  148.         coroutine.yield()
  149.         -- Debug shutdown
  150.         if reds.getBundledInput(sides.south, colors.gray) > 0 then
  151.             asd = 2
  152.         end
  153.         -- Detect redstone input to start dialing
  154.         if reds.getBundledInput(sides.south, colors.red) > 0 and component.stargate.getGateStatus() == "idle" then
  155.             local lockDetected = false
  156.             term.clear(true)
  157.             pressedbutton = 1
  158.             zpm.toggleSlots()
  159.             print("Dialing Hidden gate")
  160.             os.sleep(3)
  161.             for i,v in ipairs(address) do
  162.                 print(i,v)
  163.             end
  164.             local gateStatus = sg.getGateStatus()
  165.            
  166.             for i, glyph in ipairs(address) do
  167.                 -- Check if the gate status changes to "incoming" during dialing
  168.                 if gateStatus == "incoming" then
  169.                     if sg.getIrisState() == "OPENED" or "OPENING" then
  170.                         sg.toggleIris()
  171.                     end
  172.                     print("Incoming wormhole detected during dialing!")
  173.                     handleIncomingWormhole()
  174.                     abortDialing("Incoming wormhole")
  175.                     break
  176.                 end
  177.                 -- Ensure only program-controlled dialing proceeds
  178.                 if gateStatus ~= "dialing_computer" and gateStatus ~= "idle" then
  179.                     print("Abort detected during dialing.")
  180.                     abortDialing("manual or external")
  181.                     break
  182.                 end
  183.                 local success, lock = engageSymbolAndWait(glyph, i)
  184.                 if not success then
  185.                     print("Dialing aborted: Failed to engage glyph " .. glyph)
  186.                 end
  187.                 if lock then
  188.                     lockDetected = true
  189.                 end
  190.             end
  191.             -- Engage gate if all glyphs dialed
  192.             if lockDetected then
  193.                 print("Engaging...")   
  194.                 sg.engageGate()
  195.                 print("30 seconds before wormhole closes")
  196.                 os.sleep(3)
  197.                 zpm.toggleSlots()
  198.                 os.sleep(17)
  199.                 print("10 seconds")
  200.                 os.sleep(5)
  201.                 os.sleep(1) print("5")
  202.                 os.sleep(1) print("4")
  203.                 os.sleep(1) print("3")
  204.                 os.sleep(1) print("2")
  205.                 os.sleep(1) print("1")
  206.                 sg.disengageGate()
  207.                 os.sleep(1) print("Stargate Shutdown")
  208.                 pressedbutton = 0
  209.             else
  210.                 print("No valid lock detected. Dialing failed.")
  211.             end
  212.         end
  213.     until asd == 2 -- Run until the program is terminated
  214.     event.ignore("stargate_failed", handleStargateFailed)
  215.     event.ignore("stargate_incoming_wormhole", wormholeEventID)
  216.     print("Shutting down...")
  217. end
  218.  
  219. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement