Advertisement
MR_Spagetty

GBS.lua

Jan 20th, 2022
814
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.80 KB | None | 0 0
  1. local comp = require('component')
  2. local sides = require('sides')
  3. local event = require('event')
  4. local sg = comp.stargate
  5. local rs = comp.redstone
  6. local serialization = require('serialization')
  7.  
  8. gateAddress = {}
  9.  
  10. loop = true
  11. timesDialed = 0
  12.  
  13. eventStargateOpen = event.listen('stargate_open', function (nam, add, call, me)
  14.     loop = false
  15.     if me then
  16.         gateAddress = serialization.unserialize(sg.dialedAddress:gsub(", ", "\",\""):gsub("%[", "{\""):gsub("%]", "\"}"))
  17.     end
  18.     timesDialed = timesDialed + 1
  19. end)
  20.  
  21. while loop do os.sleep(0.1) end
  22. print()
  23. failed = false
  24. event.cancel(eventStargateOpen)
  25. while rs.getInput(sides.left) > 0 and not failed do
  26.     event.pull('stargate_wormhole_closed_fully')
  27.     print("Dialing")
  28.     for i, v in ipairs(gateAddress) do print(i, v) end
  29.     print()
  30.     loop = true
  31.     function dialNext(dialed)
  32.         glyph = gateAddress[dialed + 1]
  33.         sg.engageSymbol(glyph)
  34.     end
  35.     function cancelEvents()
  36.         event.cancel(eventEngaged)
  37.         event.cancel(openEvent)
  38.         event.cancel(failEvent)
  39.         loop = false
  40.     end
  41.     eventEngaged = event.listen("stargate_spin_chevron_engaged", function(evname, address, caller, num, lock, glyph)
  42.         os.sleep(0.5)
  43.         if lock then
  44.             print("Engaging...")
  45.             sg.engageGate()
  46.         else
  47.             dialNext(num)
  48.         end
  49.     end)
  50.     dialNext(0)
  51.     openEvent = event.listen("stargate_open", function()
  52.         print("Stargate opened successfully")
  53.         timesDialed = timesDialed + 1
  54.         cancelEvents()
  55.     end)
  56.     failEvent = event.listen("stargate_failed", function()
  57.         print("Stargate failed to open after" .. timesDialed .. "successfull dials")
  58.         failed = true
  59.         cancelEvents()
  60.     end)
  61.     while loop do os.sleep(0.1) end
  62. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement