Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- sg = peripheral.find("stargate")
- shouldCancel = false
- manualyOpened = false
- -- User settings
- side = "right"
- IDC = "1234"
- -- End of user settings
- function startUpSetting()
- if sg.getIrisState() == "OPENING" then os.pullEvent("stargate_iris_opened") end
- if sg.getIrisState() == "CLOSING" then os.pullEvent("stargate_iris_closed") end
- isOpen, direction = sg.getGateStatus()
- if isOpen == "open" and not direction and sg.getIrisState() == "OPENED" then sg.toggleIris() end
- end
- function keyEvents()
- repeat
- _, key = os.pullEvent("key")
- if key == 265 then
- os.sleep(0.2)
- if sg.getIrisState() == "OPENING" then os.pullEvent("stargate_iris_opened") end
- if sg.getIrisState() == "CLOSING" then os.pullEvent("stargate_iris_closed") end
- currentIrisStatus = sg.getIrisState()
- sg.toggleIris()
- if currentIrisStatus == "OPENED" then os.pullEvent("stargate_iris_closed") else os.pullEvent("stargate_iris_opened") end
- end
- if key == 293 then shouldCancel = true error("Program ended") end
- until shouldCancel == true
- end
- function switchIrisState()
- repeat
- if sg.getIrisState() == "OPENING" then os.pullEvent("stargate_iris_opened") end
- if sg.getIrisState() == "CLOSING" then os.pullEvent("stargate_iris_closed") end
- currentIrisState = sg.getIrisState()
- if rs.getAnalogInput(side) > 0 then
- sg.toggleIris()
- if currentIrisState == "OPENED" then os.pullEvent("stargate_iris_closed") else manualyOpened = true os.pullEvent("stargate_iris_opened") end
- end
- until shouldCancel == true
- end
- function controlIris()
- repeat
- isOpen, direction = sg.getGateStatus()
- if isOpen == "open" and not direction then
- _, _, code = os.pullEvent("received_code")
- if code == IDC and sg.getIrisState() == "CLOSED" then
- manualyOpened = true
- sg.toggleIris()
- os.pullEvent("stargate_iris_opened")
- sg.sendMessageToIncoming("Iris is opened!")
- end
- end
- until shouldCancel == true
- end
- function resetParameters()
- repeat
- os.pullEvent("stargate_wormhole_closed_fully")
- manualyOpened = false
- if sg.getIrisState() == "CLOSED" then sg.toggleIris() end
- until shouldCancel == true
- end
- function irisAutoclose()
- repeat
- _, _, direction = os.pullEvent("stargate_open")
- if not direction and not manualyOpened then
- if sg.getIrisState() == "OPENED" then sg.toggleIris() end
- end
- until shouldCancel == true
- end
- startUpSetting()
- parallel.waitForAll(switchIrisState, controlIris, irisAutoclose, resetParameters, keyEvents)
Advertisement
Add Comment
Please, Sign In to add comment