Fredyman_95

Iris Redstone Control - CC + JSG 1.20.1

Sep 20th, 2025 (edited)
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.03 KB | None | 0 0
  1. sg = peripheral.find("stargate")
  2. shouldCancel = false
  3. manualyOpened = false
  4.  
  5. -- User settings
  6. side = "right"
  7. IDC = "1234"
  8. -- End of user settings
  9.  
  10.     function startUpSetting()
  11.         if sg.getIrisState() == "OPENING" then os.pullEvent("stargate_iris_opened") end
  12.         if sg.getIrisState() == "CLOSING" then os.pullEvent("stargate_iris_closed") end
  13.         isOpen, direction = sg.getGateStatus()
  14.         if isOpen == "open" and not direction and sg.getIrisState() == "OPENED" then sg.toggleIris() end
  15.     end
  16.            
  17.     function keyEvents()
  18.         repeat
  19.             _, key = os.pullEvent("key")
  20.             if key == 265 then
  21.                 os.sleep(0.2)
  22.                 if sg.getIrisState() == "OPENING" then os.pullEvent("stargate_iris_opened") end
  23.                 if sg.getIrisState() == "CLOSING" then os.pullEvent("stargate_iris_closed") end
  24.                 currentIrisStatus = sg.getIrisState()
  25.                 sg.toggleIris()
  26.                 if currentIrisStatus == "OPENED" then os.pullEvent("stargate_iris_closed") else os.pullEvent("stargate_iris_opened") end
  27.             end
  28.             if key == 293 then shouldCancel = true error("Program ended") end
  29.         until shouldCancel == true
  30.     end
  31.  
  32.     function switchIrisState()
  33.         repeat
  34.             if sg.getIrisState() == "OPENING" then os.pullEvent("stargate_iris_opened") end
  35.             if sg.getIrisState() == "CLOSING" then os.pullEvent("stargate_iris_closed") end
  36.             currentIrisState = sg.getIrisState()
  37.             if rs.getAnalogInput(side) > 0 then
  38.                 sg.toggleIris()
  39.                 if currentIrisState == "OPENED" then os.pullEvent("stargate_iris_closed") else manualyOpened = true os.pullEvent("stargate_iris_opened") end
  40.             end
  41.         until shouldCancel == true
  42.     end
  43.  
  44.     function controlIris()
  45.         repeat
  46.             isOpen, direction = sg.getGateStatus()
  47.             if isOpen == "open" and not direction then
  48.                 _, _, code = os.pullEvent("received_code")
  49.                 if code == IDC and sg.getIrisState() == "CLOSED" then
  50.                     manualyOpened = true
  51.                     sg.toggleIris()
  52.                     os.pullEvent("stargate_iris_opened")
  53.                     sg.sendMessageToIncoming("Iris is opened!")
  54.                 end
  55.             end  
  56.             until shouldCancel == true
  57.     end
  58.  
  59.     function resetParameters()
  60.         repeat
  61.             os.pullEvent("stargate_wormhole_closed_fully")
  62.             manualyOpened = false
  63.             if sg.getIrisState() == "CLOSED" then sg.toggleIris() end
  64.         until shouldCancel == true
  65.     end
  66.  
  67.     function irisAutoclose()
  68.         repeat
  69.             _, _, direction = os.pullEvent("stargate_open")
  70.             if not direction and not manualyOpened then
  71.                 if sg.getIrisState() == "OPENED" then sg.toggleIris() end
  72.             end
  73.         until shouldCancel == true
  74.     end
  75.  
  76.     startUpSetting()
  77.     parallel.waitForAll(switchIrisState, controlIris, irisAutoclose, resetParameters, keyEvents)
Advertisement
Add Comment
Please, Sign In to add comment