Advertisement
Fredyman_95

Just Press Button

Oct 8th, 2022 (edited)
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 32.97 KB | Gaming | 0 0
  1. --[[
  2. Just Press Button Program
  3. v5.8.4.1
  4.  
  5. Created By: Fredyman_95
  6. Special Thanks To: Augur ShicKla
  7. ]]--
  8. -- User settings ----------------------------------------------------
  9.  ---- General Settings
  10.   infoTime = 8             -- min: 1, Period for infoScreen
  11.   ringsTheme = 0            -- 0 = Goauld, 1 = Ori, 2 = Ancients
  12.   rsSignal = east           -- Choose one of: east, west, south, north, top, bottom
  13.  
  14.  ---- Stargate General Settings
  15.   fastDial = false          -- Use DHD to dial
  16.   forceDial = false         -- Gate will dial even when invalid Address
  17.   gateAutoClose = false     -- Gate will automatically close after time chosen by player
  18.   minOpenTime = 10          -- Minimal time to keep gate open in seconds
  19.   maxOpenTime = 30          -- Period in s how long to keep gate open
  20.  
  21.  ---- Rings General Settings
  22.   pauseBetweenDials = 3     -- Period in s between program restart after rings finish transport
  23.  
  24.  ---- Iris Settings -------------------------------------------------
  25.   irisAutoClose = true      -- Close Iris with incoming wormhole
  26.   thisIDC = nil             -- Replace nil with YOUR gate IDC e.g 1234 -> IDC = 1234
  27.  
  28.  ---- IDC send Settings ---------------------------------------------
  29.   sendIDC = true            -- Dialing program send IDC after stargate establish connection
  30.   IDC = nil                 -- Replace nil with IDC of DIALED gate e.g 1234 -> IDC = 1234
  31.  
  32.  ---- Stargate address - fill without PoO ---------------------------
  33.   stargateAddressMW = {}   -- {"Serpens caput", "Leo", ... "Perseus"}
  34.   stargateAddressPG = {}   -- {"Illume", "Poco re", ... "Sibbron"}
  35.   stargateAddressUNI = {}  -- {"G1", "G2", ... "G8"}
  36.  
  37.  ---- Rings address -------------------------------------------------
  38.   ringsAddressGoauld = {}   -- {"Amun", "Khepri", ... "Felluca"}
  39.  
  40. -- End of User settings----------------------------------------------
  41.  
  42. -- Declarations -----------------------------------------------------
  43.  local component = require("component")
  44.  local computer = require("computer")
  45.  local event = require("event")
  46.  local sides = require("sides")
  47.  local term = require("term")
  48.  local gpu = component.gpu
  49.  local screen = component.screen
  50.  local brokenBroadcastIDC = false
  51.  local brokenLocalIDC = false
  52.  local dial = false
  53.  local dialingFailed = false
  54.  local energyCancel = false
  55.  local errorBypass = false
  56.  local fatalError = false
  57.  local forceStop = false
  58.  local intruderDetector = false
  59.  local loop = false
  60.  local mainRSLoop = false
  61.  local offWorldActivation = false
  62.  local ringsFailed = false
  63.  local rsLockDialed = false
  64.  local standBy = false
  65.  local walterMes = false
  66.  local wasOpened = false
  67.  local disconnected = false
  68.  local activeErrors = 0
  69.  local changelogTimer = 6
  70.  local colorBlue = 0x0092FF
  71.  local colorDefault = 0xFFFFFF
  72.  local colorGold = 0xFFDB00
  73.  local colorGray = 0x969696
  74.  local colorLightBlue = 0x00DBFF
  75.  local colorLightGray = 0xB4B4B4
  76.  local colorRed = 0xFF2100
  77.  local resultMessages = {
  78.    OK = "OK",
  79.    ACTIVATED = "Transport Rings Are Activated",
  80.    BUSY = "Local Transport Rings platform is Busy",
  81.    BUSY_TARGET = "Target Transport Rings platform is Busy",
  82.    OBSTRUCTED = "Local Transport Rings platform is Obstructed",
  83.    OBSTRUCTED_TARGET = "Target Transport Rings platform is Obstructed",
  84.    NOT_ENOUGH_POWER = "Not Enough Energy to Activate Transport Rings",
  85.    NO_SUCH_ADDRESS = "No Transport Ring Platform Detected on Provided Address"}
  86.  local changelog = [[ Changelog:
  87.  
  88.   - Removed autorestart when program wasn't closed properely
  89.  - Edited Events and Events system
  90.  - Edited Error system and System messages
  91.  - Added new Functions for Transport Rings
  92.  - Edited GUI + created new GUI elements
  93.  - Edited Iris/Shield functions
  94.  - Added stargate Autoclose - timer]]
  95. local instructions = [[ Instructions:
  96.  
  97. 1. Edit and check out all settings in User settings
  98.    Lines 10 - 40
  99.    Default command: edit JPB
  100.  
  101. 2. Press CTRL + C or restart the computer to exit the program
  102.    properly
  103.  
  104. 3. Setup your RedstoneIO and connect to selected side BUTTON!
  105.    !!NO LEVER!! lever will cause instant repeat of program loop.
  106.  
  107. 4. You can reduce the time for which this message is displayed in
  108.    the User Settings - line 10]]
  109. local subLogo = ""
  110. local subColor = ""
  111. local posX = ""
  112. local dialed = ""
  113. local encodedChevron = ""
  114. local symbol = ""
  115. local lastSymbol = ""
  116. local rsInput = ""
  117. local ringType = ""
  118. local AunisVersion = ""
  119. local PoO = {}
  120. local stargateAddress = {}
  121. local ringsAddress = {}
  122. local errorsLog = {}
  123. -- End of Declarations ----------------------------------------------
  124.  
  125. -- Check of user Settings -------------------------------------------
  126.    if type(fastDial) ~= "boolean" then fastDial = false end
  127.    if type(irisAutoClose) ~= "boolean" then irisAutoClose = false end
  128.    if type(sendIDC) ~= "boolean" then sendIDC = false end
  129.    if type(gateAutoClose) ~= "boolean" then gateAutoClose = false end
  130.    if type(forceDial) ~= "boolean" then forceDial = false end
  131.    if type(minOpenTime) ~= "number" then minOpenTime = 10 end
  132.    if type(maxOpenTime) ~= "number" then maxOpenTime = 2280 end
  133.    if type(pauseBetweenDials) ~= "number" then pauseBetweenDials = 3 end
  134.    if type(infoTime) ~= "number" then infoTime = 10 end
  135.    if type(ringsTheme) ~= "number" then ringsTheme = 0 end
  136.    if minOpenTime < 1 then minOpenTime = 5 elseif minOpenTime > maxOpenTime then minOpenTime = 5 end
  137.    if maxOpenTime < minOpenTime then maxOpenTime = 2280 end
  138.    if pauseBetweenDials < 2 then pauseBetweenDials = 3 end
  139.    if infoTime < 0 then infoTime = 10 end
  140.    if ringsTheme <= 0 then ringsTheme = 0 elseif ringsTheme > 3 then ringsTheme = 0 end
  141.    if type(thisIDC) == "number" and thisIDC >= 0 and thisIDC < 1e9 then os.sleep() else activeErrors = activeErrors + 1 table.insert(errorsLog, "Your IDC is Invalid") brokenLocalIDC = true end
  142.    if type(IDC) == "number" and IDC >= 0 and IDC < 1e9 then os.sleep() else activeErrors = activeErrors + 1 table.insert(errorsLog, "IDC for broadcast is Invalid") brokenBroadcastIDC = true end
  143.    if rsSignal == east then rsInput = sides.east elseif rsSignal == west then rsInput = sides.west elseif rsSignal == north then rsInput = sides.north elseif rsSignal == south then rsInput = sides.south elseif rsSignal == top then rsInput = sides.top elseif rsSignal == bottom then rsInput = sides.bottom end
  144.  
  145. -- End of Check of user Settings ------------------------------------
  146.  
  147. -- Components and system requirements check -------------------------
  148.    if gpu.maxResolution() < 81 then
  149.        activeErrors = activeErrors + 1
  150.        fatalError = true
  151.        table.insert(errorsLog, "Tier 3 GPU and Screen Required")
  152.    end
  153.  
  154.    if component.isAvailable("transportrings") then
  155.        rings = component.transportrings
  156.        errorBypass = true
  157.        NumberOfRings = 0
  158.        for k,v in component.list() do if v == "transportrings" then NumberOfRings = NumberOfRings + 1 end end
  159.        if NumberOfRings > 1 then
  160.            activeErrors = activeErrors + 1
  161.            fatalError = true
  162.            table.insert(errorsLog, "Too Many Transport Rings Connected to Computer.")
  163.        end
  164.    end
  165.  
  166.    if component.isAvailable("stargate") then
  167.        stargate = component.stargate
  168.        NumberOfGates = 0
  169.        for k,v in component.list() do if v == "stargate" then NumberOfGates = NumberOfGates + 1 end end
  170.        if NumberOfGates > 1 then
  171.            activeErrors = activeErrors + 1
  172.            fatalError = true
  173.            table.insert(errorsLog, "Too Many Stargates Connected to Computer.")
  174.        end
  175.        if stargate.getGateType() ~= "MILKYWAY" then fastDial = false else errorBypass = false end
  176.    end
  177.  
  178.    if component.isAvailable("dhd") then
  179.        dhd = component.dhd
  180.        if errorBypass == false then
  181.            NumberOfDHDs = 0
  182.            for k,v in component.list() do if v == "dhd" then NumberOfDHDs = NumberOfDHDs + 1 end end
  183.            if NumberOfDHDs > 1 then
  184.                activeErrors = activeErrors + 1
  185.                fatalError = true
  186.                table.insert(errorsLog, "Too Many DHD Connected to Computer.")
  187.            end
  188.        end
  189.    else
  190.        if errorBypass == false and fastDial then
  191.            activeErrors = activeErrors + 1
  192.            table.insert(errorsLog, "No DHD Connected, Turning off DHD dial")
  193.            fastDial = false
  194.        end
  195.    end
  196.  
  197.    if component.isAvailable("redstone") then
  198.        rs = component.redstone
  199.        NumberOfRsIOs = 0
  200.        for k,v in component.list() do if v == "redstone" then NumberOfRsIOs = NumberOfRsIOs + 1 end end
  201.        if NumberOfRsIOs > 1 then
  202.            activeErrors = activeErrors + 1
  203.            fatalError = true
  204.            table.insert(errorsLog, "Too Many Redstone Components Connected to Computer (RedstoneIO, Redstone Card)")
  205.        end
  206.    else
  207.        activeErrors = activeErrors + 1
  208.        fatalError = true
  209.        table.insert(errorsLog, "No Redstone Component Installed (RedstoneIO or Redstone Card.")
  210.    end
  211.  
  212.    if component.isAvailable("transportrings") and component.isAvailable("stargate") then
  213.        activeErrors = activeErrors + 1
  214.        fatalError = true
  215.        table.insert(errorsLog, "Multiple types of transport devices detected!")
  216.    end
  217.  
  218.    if not component.isAvailable("transportrings") and not component.isAvailable("stargate") then
  219.        activeErrors = activeErrors + 1
  220.        fatalError = true
  221.        table.insert(errorsLog, "No Transport Rings or Stargate Connected.")
  222.    end
  223.  
  224.    if activeErrors > 0 then
  225.        term.clear()
  226.        if activeErrors >= 2 then print("Multiple Errors Detected:") else print("Error Detected:") end
  227.        print()
  228.        gpu.setForeground(0xFF0000)
  229.        for i, v in ipairs(errorsLog) do
  230.            print("Error #" .. i .. " " .. v)
  231.            computer.beep()
  232.            os.sleep(0.2)
  233.        end
  234.        for i, v in ipairs(errorsLog) do
  235.            table.remove(errorsLog, i)
  236.        end
  237.        gpu.setForeground(0xFFFFFF)
  238.        os.sleep(2)
  239.        if fatalError then os.exit(1) end
  240.    end
  241.  
  242. -- End of Components and system requirements check ------------------
  243.  
  244. -- Common Events ----------------------------------------------------
  245.  
  246.    eventInterrupted = event.listen("interrupted", function()
  247.        forceStop = true
  248.    end)
  249.  
  250. -- End of Common Events --------------------------------------------
  251.  
  252. -- Functions --------------------------------------------------------
  253.  
  254. ---- Common functions ----------------------------------------------
  255.    local function checkThisTableContent(subject, minLenght, maxLenght, shortError, longError)
  256.        gpu.setForeground(0xFF0000)
  257.        for i, v in ipairs(subject) do testedValue = i end
  258.            if testedValue <= minLenght then print(shortError)
  259.            elseif testedValue > maxLenght then print(longError)
  260.        end
  261.        gpu.setForeground(0xFFFFFF)
  262.    end
  263.  
  264.    local function errorMessagenger(errorMessage)
  265.        gpu.setForeground(0xFF0000)
  266.        print(errorMessage)
  267.        computer.beep()
  268.        gpu.setForeground(0xFFFFFF)
  269.    end
  270.  
  271.    local function timer(seconds)
  272.        seconds = seconds * 10
  273.        for i = 0 , seconds do
  274.            if forceStop then break end
  275.            os.sleep(0.1)
  276.        end
  277.    end
  278.  
  279.    local function gateTimer(countdown)
  280.        local countdown = tonumber(countdown)
  281.        if countdown <= 0 then
  282.            return "00:00"
  283.        else
  284.            hours = string.format("%02.f", math.floor(countdown/3600))
  285.            mins = string.format("%02.f", math.floor(countdown/60 - (hours*60)))
  286.            secs = string.format("%02.f", math.floor(countdown - hours*3600 - mins *60))
  287.        end
  288.    end
  289.  
  290. ---- End of Common functions ---------------------------------------
  291.  
  292. ---- Main Screen functions -----------------------------------------
  293.  
  294.    logo = [[⢸⠀⡇⠀⢸⠀⡎⠉⠱⠀⠉⢹⠉⠁ ⠀⢸⠉⠉⡆⢸⠉⠉⡆⢸⠉⠉⠀⡎⠉⠱⠀⡎⠉⠱   ⡏⠉⡆⠀⡇⠀⢸⠀⠉⢹⠉⠁⠈⠉⡏⠉⠀⡎⠉⢱⠀⡷⡄⢸
  295.    ⡆⠀⢸⠀⡇⠀⢸⠀⡌⠉⢱⠀⠀⢸⠀⠀⠀ ⢸⠉⠉⠀⢸⠉⠫⡀⢸⠉⠉⠀⡌⠉⢱⠀⡌⠉⢱   ⡏⠉⢱⠀⡇⠀⢸⠀⠀⢸⠀⠀⠀⠀⡇⠀⠀⡇⠀⢸⠀⡇⠹⣼
  296.    ⠈⠉⠁⠀⠈⠉⠁⠀⠈⠉⠁⠀⠀⠈⠀⠀⠀ ⠈⠀⠀⠀⠈⠀⠀⠁⠈⠉⠉⠀⠈⠉⠁⠀⠈⠉⠁   ⠉⠉⠁⠀⠈⠉⠁⠀⠀⠈⠀⠀⠀⠀⠁⠀⠀⠈⠉⠁⠀⠁⠀⠈ ]]
  297.  
  298.    milkywaySubLogo = "⣳⡃⣩⡁⣺⠅⣻⡇⣏⠃⡳⡇⠭⡇⣏⠃ ⢸⠺⢨⢬⠨⢽⢨⣩⢸⣘⠨⢽⢨⢬⢸⢬ ⢸⢹⢘⢮⢠⢷⢨⢬⢨⣩⢘⢮⢐⡯"
  299.    pegasusSubLogo = "⡇⡁⡧⡅⣇⡃⠭⡇⡗⠇⠉⡇⡗⠇ ⢸⠺⢨⢬⠨⢽⢨⣩⢸⣘⠨⢽⢨⢬⢸⢬ ⢸⢹⢘⢮⢠⢷⢨⢬⢨⣩⢘⢮⢐⡯"
  300.    universeSubLogo = "⠉⡇⡼⡆⣩⡁⣹⡇⡧⡅⣍⡅⡗⠇⡧⡅ ⢸⠺⢨⢬⠨⢽⢨⣩⢸⣘⠨⢽⢨⢬⢸⢬ ⢸⢹⢘⢮⢠⢷⢨⢬⢨⣩⢘⢮⢐⡯"
  301.    oriSubLogo = "⡳⡅⣍⡅⣩⡁ ⡥⡅⣍⡅⠭⡇⡼⡆⡗⠇⡇⡁⡳⡅⣍⡅⡥⡅ ⣍⡅⣩⡁⡼⡆⣇⡃⡗⠇ ⢸⢹⢘⢮⢠⢷⢨⢬⢨⣩⢘⢮⢐⡯"
  302.    ancientsSubLogo = "⠭⡇⡼⡆⡏⡇⣩⡁⡧⡅⡼⡆⡥⡅⡗⠇ ⡥⡅⣍⡅⠭⡇⡼⡆⡗⠇⡇⡁⡳⡅⣍⡅⡥⡅ ⣍⡅⣩⡁⡼⡆⣇⡃⡗⠇ ⢸⢹⢘⢮⢠⢷⢨⢬⢨⣩⢘⢮⢐⡯"
  303.    goauldSubLogo = "⢔⣹⣏⡢⢄⣀⠀⣄⣻⣘⣇⣻⡀ ⢀⡶⣄⡴⠦⠀⡠⡠⡠⡠⡀ ⠐⢶⣶⠖⢖⠄ ⢀⡶⣄⡴⠦  ⢔⣹⣏⡢⢄⣀"
  304.  
  305.    local function mainScreen()  -- Old screenClear()
  306.        gpu.setResolution(72, 25)
  307.        term.clear()
  308.        term.setCursor(7,2)
  309.        print(logo)
  310.        print()
  311.    end
  312.  
  313.    local function operationScreen()
  314.        mainScreen()
  315.        gpu.setForeground(subColor)
  316.        term.setCursor(posX, 5)
  317.        print(subLogo)
  318.        gpu.setForeground(colorDefault)
  319.        term.setCursor(1, 8)
  320.    end
  321.  
  322.    local function bootingScreen()
  323.        mainScreen()
  324.        print(changelog)
  325.        timer(changelogTimer)
  326.        mainScreen()
  327.        print(instructions)
  328.        timer(infoTime)
  329.    end
  330.  
  331.    local function closingScreen()
  332.        operationScreen()
  333.        term.setCursor(32,8)
  334.        print("Good bye")
  335.    end
  336.  
  337. ---- End of Main Screen functions ----------------------------------
  338.  
  339. ---- Stargate functions---------------------------------------------
  340.    local function setupByGateType()
  341.        if stargate.getGateType() == "MILKYWAY" then
  342.            stargateAddress = stargateAddressMW
  343.            PoO = {"Point of Origin"}
  344.            subLogo = milkywaySubLogo
  345.            subColor = colorRed
  346.            posX = 14
  347.            if fastDial == false then walterMes = true end
  348.        elseif stargate.getGateType() == "PEGASUS" then
  349.            stargateAddress = stargateAddressPG
  350.            PoO = {"Subido"}
  351.            subLogo = pegasusSubLogo
  352.            subColor = colorBlue
  353.            posX = 14
  354.        else
  355.            stargateAddress = stargateAddressUNI
  356.            PoO = {"G17"}
  357.            subLogo = universeSubLogo
  358.            subColor = colorGray
  359.            posX = 13
  360.        end
  361.    end
  362.  
  363.    local function completeAddress(t1, t2)
  364.        for i=1, #t2 do
  365.            t1[#t1 + 1] = t2[i]
  366.        end
  367.    end
  368.  
  369.    local function energyLevel()
  370.        if type(stargate.getEnergyRequiredToDial(table.unpack(stargateAddress))) == "table" then
  371.            if stargate.getEnergyStored() < stargate.getEnergyRequiredToDial(table.unpack(stargateAddress)).open + (stargate.getEnergyRequiredToDial(table.unpack(stargateAddress)).keepAlive * 20 * minOpenTime) then
  372.                errorMessagenger("Not Enough Energy to Establish Connection")
  373.                energyCancel = true
  374.            end
  375.        else
  376.            if forceDial == false then errorMessagenger("No Stargate Detected on Provided Address") energyCancel = true end
  377.        end
  378.    end
  379.  
  380.    local function IrisCheck()
  381.        if stargate.getIrisType() == "NULL" then irisAutoClose = false else
  382.            if stargate.getIrisState() == "CLOSED" then stargate.toggleIris() end
  383.        end
  384.    end
  385.  
  386.    local function computerDial(dialed)
  387.       glyph = stargateAddress[dialed + 1]
  388.           if walterMes == false then
  389.               print("Engaging " .. glyph .. "...")
  390.           end
  391.       stargate.engageSymbol(glyph)
  392.    end
  393.  
  394.    local function dhdDial(dialed)
  395.        for i, v in ipairs(stargateAddress) do
  396.            if offWorldActivation or forceStop then break end
  397.            glyph = stargateAddress[i]
  398.            print("DHD button pressed: "..glyph.."... ")
  399.            dhd.pressButton(glyph)
  400.            os.sleep(0.6)
  401.       end
  402.       if offWorldActivation == false or forceStop == false then
  403.           os.sleep(1.4)
  404.           print("DHD button pressed: Big Red Button... ")
  405.           dhd.pressBRB()
  406.           rsLockDialed = true
  407.       end
  408.    end
  409.  
  410.    local function IDCsender()
  411.        if brokenBroadcastIDC then errorMessagenger("Broadcast IDC Failed: Invalid IDC") sendIDC = false else print("IDC: " .. IDC .. " sent successfully") stargate.sendIrisCode(IDC) end
  412.    end
  413.  
  414. ---- End of Stargate functions -------------------------------------
  415.  
  416. ---- Stargate events -----------------------------------------------
  417.    local function startStargateEvents()
  418.        stargateEventsActive = true
  419.  
  420.        openEvent = event.listen("stargate_open", function()
  421.            if offWorldActivation == false then
  422.                if walterMes == false then print("Stargate opened successfully") end
  423.                rsLockDialed = true
  424.                loop = false
  425.            end
  426.        end)        
  427.  
  428.        failEvent = event.listen("stargate_failed", function()
  429.            if offWorldActivation == false then
  430.                dialingFailed = true
  431.                if walterMes then print("Chevron " .. encodedChevron .. " will not engage. It won't Lock. Can't Establish Connection") else print("Stargate failed to open") end
  432.                if fastDial then errorMessagenger("Make Sure the DHD Contains the Glyph Crystal") timer(2) end
  433.                timer(2)
  434.                cancelStargateEvents()
  435.            end
  436.        end)
  437.                    
  438.        closedEvent = event.listen("stargate_wormhole_closed_fully", function()
  439.            if offWorldActivation then print("Conection lost") timer(1) end
  440.            rsLockDialed = false
  441.            disconnected = true
  442.            if stargate.getIrisState() == "CLOSED" then stargate.toggleIris()
  443.                if stargate.getIrisType() ~= "SHIELD" then print("Opening IRIS") else print("Turning OFF Shield") end
  444.            end
  445.            if standBy == false then cancelStargateEvents() end -------------------------------------------------------------------------------------------------------------------------------------------
  446.        end)
  447.  
  448.        incomingEvent = event.listen("stargate_incoming_wormhole", function()
  449.            offWorldActivation = true
  450.            loop = false
  451.            if dial then stargate.abortDialing() end
  452.            dial = false
  453.            if irisAutoClose and stargate.getIrisState() == "OPENED" then stargate.toggleIris() os.sleep(0.2)
  454.                if stargate.getIrisType() ~= "SHIELD" then print("Closing IRIS") else print("Turning ON Shield") end
  455.            end
  456.        end)
  457.  
  458.         eventEngaged = event.listen("stargate_spin_chevron_engaged", function(evname, address, caller, num, lock, glyph)   
  459.            os.sleep(0.5)
  460.            if lock then
  461.                if walterMes then print("Chevron "..encodedChevron.." Locked") end
  462.                stargate.engageGate()
  463.            else
  464.                if walterMes then print("Chevron "..encodedChevron.. " encoded...") encodedChevron = encodedChevron + 1 end
  465.                computerDial(num)
  466.            end
  467.        end)
  468.  
  469.        eventReceiveCode = event.listen("received_code", function(_, _, _, code)
  470.            os.sleep(0.5)
  471.            if intruderDetector then stargate.sendMessageToIncoming("Intruder Entry Prohibited") else
  472.                if irisAutoClose and brokenLocalIDC == false then
  473.                    if thisIDC == code then
  474.                        if stargate.getIrisState() == "CLOSED" then stargate.toggleIris() wasOpened = true
  475.                            if stargate.getIrisType() == "SHIELD" then print("IDC Accepted - Turning off Shield") stargate.sendMessageToIncoming("IDC Accepted - Turning off Shield") else print("IDC Accepted - Opening Iris") stargate.sendMessageToIncoming("IDC Accepted - Opening Iris") end
  476.                        else
  477.                            if stargate.getIrisType() == "SHIELD" then stargate.sendMessageToIncoming("Shield is OFF!") else stargate.sendMessageToIncoming("Iris is Open!") end
  478.                        end
  479.                    elseif thisIDC ~= code and stargate.getIrisState() == "CLOSED" then stargate.sendMessageToIncoming("IDC is Incorrect!")
  480.                    elseif thisIDC ~= code and stargate.getIrisState() == "OPENED" and wasOpened then
  481.                            if stargate.getIrisType() ~= "SHIELD" then stargate.sendMessageToIncoming("Intruder Detected - closing IRIS") print("Invalid IDC received - Closing Iris") else stargate.sendMessageToIncoming("Intruder Detected - SHIELD is ON") print("Invalid IDC received - Turning on Shield") end
  482.                            stargate.toggleIris()
  483.                            intruderDetector = true
  484.                    end
  485.                elseif irisAutoClose and brokenLocalIDC then errorMessagenger("Error: IDC Database is Damaged!") stargate.sendMessageToIncoming("Error: Database is Damaged - Your IDC is not Valid!")
  486.                end
  487.            end
  488.        end)
  489.    end            
  490.  
  491.   function cancelStargateEvents()
  492.       event.cancel(eventEngaged)
  493.       event.cancel(openEvent)
  494.       event.cancel(failEvent)
  495.       event.cancel(incomingEvent)
  496.       event.cancel(closedEvent)
  497.       event.cancel(eventReceiveCode)
  498.       loop = false
  499.       stargateEventsActive = false
  500.   end
  501.  
  502. ---- End of Stargate events ----------------------------------------
  503.  
  504. ---- Transport Rings functions -------------------------------------
  505.    local function AunisVersionCheck()
  506.         local success = pcall(rings.getAunisVersion)
  507.         local success1 = pcall(rings.getJSGVersion)
  508.         if success or success1 then AunisVersion = "new" else AunisVersion = "legacy" end
  509.    end
  510.  
  511.    local function setupByRingsType()
  512.        ringsAddress = ringsAddressGoauld
  513.        ringType = 0
  514.        lastSymbol = 5
  515.        if ringsTheme == 0 then
  516.           subLogo = goauldSubLogo
  517.           subColor = colorGold
  518.           posX = 13
  519.       elseif ringsTheme == 1 then
  520.           subLogo = oriSubLogo
  521.           subColor = colorLightGray
  522.           posX = 11
  523.       else
  524.           subLogo = ancientsSubLogo
  525.           subColor = colorLightBlue
  526.           posX = 6
  527.       end
  528.    end
  529.  
  530.    local function messageSystem(msg)
  531.        if msg ~= "OK" then
  532.            local msgString = resultMessages[msg]
  533.            if msgString == nil then msgString = msg end    
  534.            if msg == "ACTIVATED" then
  535.                print(msgString)
  536.            else
  537.                errorMessagenger(msgString)
  538.                rsLockDialed = false
  539.                ringsFailed = true
  540.            end
  541.            timer(3)
  542.        end
  543.    end
  544.  
  545.    local function dialRings()
  546.        rsLockDialed = true
  547.        for i,v in pairs(ringsAddress) do
  548.            if forceStop then break end
  549.            symbol = ringsAddress[i]
  550.            print("Symbol engaged: " .. symbol .. "...")
  551.            rings.addSymbolToAddress(ringType, symbol)
  552.            os.sleep(0.5)
  553.        end
  554.        if forceStop == false then
  555.            os.sleep(0.5)
  556.            local result = rings.addSymbolToAddress(ringType, lastSymbol)
  557.            messageSystem(result)
  558.        end
  559.    end
  560.  
  561. ---- End of Transport Rings functions ------------------------------
  562.  
  563. ---- Transport Rings events ----------------------------------------
  564.   local function startRingsEvents()
  565.       ringsEventsActive = true
  566.       eventTeleportStart = event.listen("transportrings_teleport_start", function(_, address, caller, initiating)
  567.           mainRSLoop = false
  568.           rsLockDialed = true
  569.       end)
  570.  
  571.       eventTeleportFinished = event.listen("transportrings_teleport_finished", function(_, address, caller, initiating)
  572.           rsLockDialed = false
  573.           computer.beep()
  574.       end)
  575.   end  
  576.  
  577.   local function cancelRingsEvents()
  578.       event.cancel(eventTeleportStart)
  579.       event.cancel(eventTeleportFinished)
  580.       ringsEventsActive = false
  581.   end
  582.  
  583. ---- End of Transport Rings events ---------------------------------
  584.  
  585. -- End of Functions -------------------------------------------------
  586.  
  587. -- Initialization ---------------------------------------------------
  588.    bootingScreen()
  589.    if component.isAvailable("stargate") then
  590.        setupByGateType()
  591.        checkThisTableContent(stargateAddress, 5, 8, "Incomplete Stargate Address or No Stargate Address Entered.", "Stargate Address Corrupted")
  592.        completeAddress(stargateAddress, PoO)
  593.    end
  594.    if component.isAvailable("transportrings") then
  595.        setupByRingsType()
  596.        for i, v in ipairs(ringsAddress)do
  597.            print(v)
  598.        end
  599.        checkThisTableContent(ringsAddress, 3, 5, "Incomplete Rings Address or No Rings Address Entered.", "Rings Address Corrupted")
  600.    end
  601.  
  602. -- End of Initialization --------------------------------------------
  603.  
  604. -- Main Loop --------------------------------------------------------
  605.    ::Start::
  606.    if stargateEventsActive then cancelStargateEvents() end
  607.    if ringsEventsActive then cancelRingsEvents() end
  608.    operationScreen()
  609.    if component.isAvailable("transportrings") then goto Rings end
  610.    timer(1)
  611. ---- Stargate Dialing sequence -------------------------------------
  612.  
  613. ------ Loop Declarations ------------------------------------------
  614.   loop = false                                                  
  615.   dial = false
  616.   rsLockDialed = false
  617.   energyCancel = false
  618.   wasOpened = false
  619.   dialingFailed = false
  620.   offWorldActivation = false
  621.   intruderDetector = false
  622.   mainRSLoop = true
  623.   standBy = true
  624.   dialed = 0
  625.   encodedChevron = 1
  626.  
  627. ------ end of Loop Declarations -----------------------------------
  628.  
  629. ------ Initialization ---------------------------------------------
  630.    if stargate.dialedAddress == nil then
  631.        if stargate.getIrisState() == "OPENED" then stargate.toggleIris() end
  632.        startStargateEvents()
  633.        offWorldActivation = true
  634.        os.sleep(0.1)
  635.        goto IncomingLoop
  636.    elseif stargate.dialedAddress ~= "[]" and stargate.dialedAddress ~= nil and stargate.getGateStatus() ~= "open" then
  637.        stargate.abortDialing()
  638.        print("Clearing Stargate Address buffer")
  639.        timer(1)
  640.    end
  641.  
  642.    if stargate.getGateStatus() == "open" then print("Closing Stargate") stargate.disengageGate() timer(1) end
  643.    
  644.    startStargateEvents()
  645.  
  646.    if stargate.getGateStatus() ~= "idle" and stargate.getGateType() == "UNIVERSE" then print("Stargate is Restarting...") end
  647.    while stargate.getGateStatus() ~= "idle" do os.sleep(0.1) if forceStop then goto CloseProgram end end
  648.    IrisCheck()
  649.  
  650. ------ End of Initialization --------------------------------------
  651.  
  652. ------ Dialing Programs -------------------------------------------
  653.    operationScreen()
  654.    print("Press Button to Activate Stargate Dialing Sequence")
  655.    print()
  656.    disconnected = false
  657.    while mainRSLoop do
  658.        if forceStop then goto CloseProgram end
  659.        if rs.getInput(rsInput) > 0 then mainRSLoop = false end
  660.        if offWorldActivation then mainRSLoop = false goto IncomingLoop end
  661.        os.sleep(0.1)
  662.    end
  663.  
  664.    energyLevel()
  665.    if energyCancel then timer(5) cancelStargateEvents() goto Start end
  666.  
  667.    if fastDial then print("Initiate the dialing sequence with DHD") dhdDial(0) dial = true else
  668.        if walterMes then print("Input the coordinates and initiate the dialing sequence") else print("Dialing the Stargate") end
  669.        computerDial(0)
  670.        loop = true
  671.        dial = true
  672.        while loop do
  673.            if forceStop then goto CloseProgram end
  674.            if offWorldActivation then loop = false goto IncomingLoop end
  675.            os.sleep(0.1)
  676.        end
  677.    end
  678.  
  679.    print()
  680.    timer(1)
  681.    if sendIDC and dialingFailed == false then timer(4) IDCsender() print() computer.beep() else timer(2) end
  682.    if dialingFailed then goto Start end
  683. ------ End of Dialing Programs ------------------------------------
  684.  
  685. ------ Interlock Loops --------------------------------------------
  686.    if rsLockDialed then
  687.        term.setCursor(1, 24)
  688.        if gateAutoClose then print("Stargate closes in: ") else print("Press Button to Close Stargate") end
  689.        if gateAutoClose == false then
  690.            while disconnected == false do
  691.                os.sleep(0.1)
  692.                if rs.getInput(rsInput) > 0 then break end
  693.                if forceStop then goto CloseProgram end
  694.            end
  695.        else
  696.            loopTime = maxOpenTime * 10
  697.            stopwatch = maxOpenTime
  698.            gateTimer(stopwatch)
  699.            clockLoop = 0
  700.            term.setCursor(21 ,24)
  701.            print(mins.. ":" .. secs)
  702.            for i = 0, loopTime do
  703.                clockLoop = clockLoop + 1
  704.                if clockLoop == 5 then term.setCursor(21 ,24) print(mins.. " " .. secs) elseif clockLoop == 10 then
  705.                    clockLoop = 0
  706.                    stopwatch = stopwatch - 1
  707.                    gateTimer(stopwatch)
  708.                    term.setCursor(21 ,24)
  709.                    print(mins.. ":" .. secs)
  710.                end
  711.                if forceStop then goto CloseProgram end
  712.                if rs.getInput(rsInput) > 0 then break end
  713.                if disconnected then break end
  714.                os.sleep(0.1)
  715.            end
  716.        end
  717.        
  718.        stargate.disengageGate()
  719.        print("Closing stargate")
  720.        if stargate.getGateStatus() ~= "idle" and stargate.getGateType() == "UNIVERSE" then print("Stargate is Restarting...") end
  721.        while stargate.getGateStatus() ~= "idle" do os.sleep(0.1) if forceStop then goto CloseProgram end end
  722.        cancelStargateEvents()
  723.        goto Start
  724.    end
  725.        
  726.    ::IncomingLoop::
  727.  
  728.    if offWorldActivation then operationScreen()
  729.        if walterMes then print("Unscheduled Offworld Activation") print() else print("Incoming Wormhole!") print() end
  730.        while offWorldActivation do
  731.            if forceStop then goto CloseProgram end
  732.            if disconnected then break end
  733.            os.sleep(0.1)
  734.        end
  735.    end
  736.    cancelStargateEvents()
  737.    goto Start
  738.  
  739. ------ End of Interlock Loops -------------------------------------
  740.  
  741. ---- End of Stargate Dialing sequence ------------------------------
  742.  
  743. ---- Transport Rings Dialing sequence ------------------------------
  744. ::Rings::
  745.  
  746. ------ Loop Declarations ------------------------------------------
  747.   mainRSLoop = true
  748.   rsLockDialed = false
  749.   ringsFailed = false
  750.  
  751. ------ End of Loop Declarations -----------------------------------
  752.  
  753. ------ Initialization ---------------------------------------------
  754.    AunisVersionCheck()
  755.    if AunisVersion == "legacy" then
  756.        errorMessagenger("You are using outdated version of Aunis (JSG). This program is not      compatible for transport rings control.")
  757.        print() print("Supported versions: 4.10.0.1 and newer")
  758.        timer(6)
  759.        goto CloseProgram
  760.    end
  761.  
  762.    rings.addSymbolToAddress(ringType, lastSymbol)
  763.  
  764.    os.sleep(0.5)
  765.    startRingsEvents()
  766.  
  767. ------ End of Initialization --------------------------------------
  768.  
  769. ------ Rings Dialing Program --------------------------------------
  770.    print("Press Button to Activate Transport Rings")
  771.    print()
  772.    timer(1)
  773.    while mainRSLoop do
  774.        if forceStop then goto CloseProgram end
  775.        if rs.getInput(rsInput) > 0 then mainRSLoop = false end
  776.        os.sleep(0.1)
  777.    end
  778.  
  779.   print("Activating Transport Rings Dialing Sequence")
  780.   dialRings()
  781.  
  782. ------ End of Rings Dialing program -------------------------------
  783.  
  784. ------ Interlock Loop ---------------------------------------------
  785.   while rsLockDialed do
  786.       if forceStop then goto CloseProgram end
  787.       os.sleep(0.1)
  788.   end
  789.  
  790.   if ringsFailed == false then
  791.       print()
  792.       print("Preparing Transport Rings for further operation")
  793.       timer(pauseBetweenDials)
  794.   end
  795.  
  796.   cancelRingsEvents()
  797.   goto Start
  798. ------End of Interlock Loop ---------------------------------------
  799.  
  800. ---- End of Transport Rings Dialing sequence -----------------------
  801.  
  802. -- End of Main Loop -------------------------------------------------
  803.  
  804. -- Closing procedure ------------------------------------------------
  805. ::CloseProgram::
  806.  
  807. event.cancel(eventInterrupted)
  808. if stargateEventsActive then cancelStargateEvents() end
  809. if ringsEventsActive then cancelRingsEvents() end
  810. if component.isAvailable("stargate") and dial then stargate.abortDialing() end
  811. closingScreen()
  812. os.sleep(2)
  813. term.clear()
  814. gpu.setResolution(160, 50)
  815. -- End of Closing procedure -----------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement