Advertisement
samuelask

Hiddengatenibiru

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