Advertisement
MR_Spagetty

GRS.lua

Jan 20th, 2022
803
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local comp = require('component')
  2. local sides = require('sides')
  3. local event = require('event')
  4. os = require("os")
  5. local sg = comp.stargate
  6. local rs = comp.redstone
  7. local serialization = require('serialization')
  8. sg.disengageGate()
  9. rs.setOutput(sides.posy, 0)
  10. gateAddress = {}
  11. processingLoop = true
  12. event.listen("interrupted", function() processingLoop = false end)
  13. gateOpened = event.listen("stargate_open", function (nam, add, call, me)
  14.     if me then
  15.         gateAddress = serialization.unserialize(sg.dialedAddress:gsub(", ", "\",\""):gsub("%[", "{\""):gsub("%]", "\"}"))
  16.     end
  17. end)
  18.  
  19. function dial()
  20.     rs.setOutput(sides.posy, 0)
  21.     print("Dialing")
  22.     for i,v in ipairs(gateAddress) do print(i,v) end
  23.     print()
  24.     loop = true
  25.     function dialNext(dialed)
  26.         glyph = gateAddress[dialed + 1]
  27.         print("Engaging "..glyph.."... ")
  28.         sg.engageSymbol(glyph)
  29.     end
  30.     function cancelEvents()
  31.         event.cancel(eventEngaged)
  32.         event.cancel(openEvent)
  33.         event.cancel(failEvent)
  34.         print("Cancelled all event listeners")
  35.         loop = false
  36.     end
  37.     eventEngaged = event.listen("stargate_spin_chevron_engaged", function(evname, add, caller, num, lock, glyph)
  38.         os.sleep(0.5)
  39.         if lock then
  40.             print("Engaging...")
  41.             sg.engageGate()
  42.         else
  43.             dialNext(num)
  44.         end
  45.     end)
  46.     dialNext(0)
  47.     openEvent = event.listen("stargate_open", function()
  48.         print("Stargate opened successfully")
  49.         cancelEvents()
  50.     end)
  51.     failEvent = event.listen("stargate_failed", function()
  52.         print("Stargate failed to open")
  53.         cancelEvents()
  54.     end)
  55.     while loop do os.sleep(0.1) end
  56. end
  57. event.pull('stargate_wormhole_closed_fully')
  58. rs.setOutput(sides.posy, 15)
  59. function checkNDial(nam, add, side, old, new)
  60.     if new > 0 and sg.getGateStatus() == "idle" and gateAddress then
  61.         dial()
  62.     end
  63. end
  64. gateClose = event.listen("stargate_wormhole_closed_fully", function()
  65.     if gateAddress then
  66.         rs.setOutput(sides.posy, 15)
  67.     end
  68. end)
  69. while processingLoop do
  70.     local nam, add, side, old, new = event.pull('redstone_changed')
  71.     checkNDial(nam, add, side, old, new)
  72. end
  73. event.cancel(gateClose)
  74. event.cancel(gateOpened)
  75. event.cancel(eventEngaged)
  76. event.cancel(openEvent)
  77. event.cancel(failEvent)
  78. print("Cancelled all event listeners")
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement