Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- Just Press Button Program
- v5.8.3.12
- Created By: Fredyman_95
- Special Thanks To: Augur ShicKla
- ]]--
- -- User settings ----------------------------------------------------
- ---- General Settings
- infoTime = 3 -- min: 1, Period for infoScreen
- ringsTheme = 0 -- 0 = Goauld, 1 = Ori, 2 = Ancients
- rsSignal = east -- Choose one of: east, west, south, north, top, bottom
- ---- Stargate General Settings
- fastDial = true -- Use DHD to dial
- forceDial = false -- Gate will dial even when invalid Address
- gateAutoClose = false -- Gate will automatically close after time chosen by player
- minOpenTime = 10 -- Minimal time to keep gate open in seconds
- maxOpenTime = 30 -- Period in s how long to keep gate open
- ---- Rings General Settings
- pauseBetweenDials = 3 -- Period in s between program restart after rings finish transport
- ---- Iris Settings -------------------------------------------------
- irisAutoClose = true -- Close Iris with incoming wormhole
- thisIDC = 55 -- Replace nil with YOUR gate IDC e.g 1234 -> IDC = 1234
- ---- IDC send Settings ---------------------------------------------
- sendIDC = true -- Dialing program send IDC after stargate establish connection
- IDC = 1234 -- Replace nil with IDC of DIALED gate e.g 1234 -> IDC = 1234
- ---- Stargate address - fill without PoO ---------------------------
- stargateAddressMW = {"Microscopium", "Leo", "Lynx", "Norma", "Eridanus", "Centaurus", "Perseus"} -- {"Serpens caput", "Leo", ... "Perseus"}
- --stargateAddressMW = {"Canis Minor", "Lynx", "Sextans", "Microscopium", "Virgo", "Serpens Caput"}
- stargateAddressPG = {"Illume", "Olavii", "Ecrumig", "Abrin", "Ramnon", "Sibbron"} -- {"Illume", "Poco re", ... "Sibbron"}
- stargateAddressUNI = {"G23", "G32", "G11", "G1", "G31", "G34", "G20", "G13"} -- {"G1", "G2", ... "G8"}
- ---- Rings address -------------------------------------------------
- ringsAddressGoauld = {"Amun", "Khepri", "Serket", "Felluca"} -- {"Amun", "Khepri", ... "Felluca"}
- ringsAddressOri = {} -- Just Stargate Mod -> WIP
- ringsAddressAncients = {} -- Just Stargate Mod -> WIP
- -- End of User settings----------------------------------------------
- -- Declarations -----------------------------------------------------
- local component = require("component")
- local computer = require("computer")
- local event = require("event")
- local sides = require("sides")
- local term = require("term")
- local unicode = require("unicode")
- local gpu = component.gpu
- local screen = component.screen
- local brokenBroadcastIDC = false
- local brokenLocalIDC = false
- local dial = false
- local dialingFailed = false
- local energyCancel = false
- local errorBypass = false
- local fatalError = false
- local forceStop = false
- local intruderDetector = false
- local loop = false
- local mainRSLoop = false
- local offWorldActivation = false
- local ringsFailed = false
- local rsLockDialed = false
- local standBy = false
- local walterMes = false
- local wasOpened = false
- local wasPressed = false
- local disconnected = false
- local activeErrors = 0
- local changelogTimer = 2
- local colorBlue = 0x0092FF
- local colorDefault = 0xFFFFFF
- local colorGold = 0xFFDB00
- local colorGray = 0x969696
- local colorLightBlue = 0x00DBFF
- local colorLightGray = 0xB4B4B4
- local colorRed = 0xFF2100
- local resultMessages = {
- OK = "OK",
- ACTIVATED = "Transport Rings Are Activated",
- BUSY = "Local Transport Rings platform is Busy",
- BUSY_TARGET = "Target Transport Rings platform is Busy",
- OBSTRUCTED = "Local Transport Rings platform is Obstructed",
- OBSTRUCTED_TARGET = "Target Transport Rings platform is Obstructed",
- NOT_ENOUGH_POWER = "Not Enough Energy to Activate Transport Rings",
- NO_SUCH_ADDRESS = "No Transport Ring Platform Detected on Provided Address"}
- local changelog = [[ Changelog:
- - Removed autorestart when program wasn't closed properely
- - Edited Events and events system
- - Edited stargate check system
- - Edited Error system and system messages
- - Added new functions for Transport Rings
- - Edited GUI + created new GUI elements
- - Edited Iris/Shield functions
- - Gate can be closed by reach time limit - with countdown]]
- local instructions = [[ Instructions:
- 1. Edit and check out all settings in User settings
- Lines 9 - 36
- Default command: edit JPB
- 2. Press CTRL + C or restart the computer to exit the program
- properly
- 3. Setup your RedstoneIO and connect to selected side BUTTON!
- !!NO LEVER!! lever will cause instant repeat of program loop.
- 4. You can reduce the time for which this message is displayed in
- the User Settings - line 19]]
- local subLogo = ""
- local subColor = ""
- local posX = ""
- local dialed = ""
- local encodedChevron = ""
- local symbol = ""
- local lastSymbol = ""
- local rsInput = ""
- local ringType = ""
- local AunisVersion = ""
- local PoO = {}
- local stargateAddress = {}
- local ringsAddress = {}
- local errorsLog = {}
- local ActiveButtons = {}
- local buttons = {}
- -- End of Declarations ----------------------------------------------
- -- HARD TO CODE => HARD TO READ!!!
- -- Check of user Settings -------------------------------------------
- if type(fastDial) ~= "boolean" then fastDial = false end
- if type(irisAutoClose) ~= "boolean" then irisAutoClose = false end
- if type(sendIDC) ~= "boolean" then sendIDC = false end
- if type(gateAutoClose) ~= "boolean" then gateAutoClose = false end
- if type(forceDial) ~= "boolean" then forceDial = false end
- if type(minOpenTime) ~= "number" then minOpenTime = 10 end
- if type(maxOpenTime) ~= "number" then maxOpenTime = 2280 end
- if type(pauseBetweenDials) ~= "number" then pauseBetweenDials = 3 end
- if type(infoTime) ~= "number" then infoTime = 10 end
- if type(ringsTheme) ~= "number" then ringsTheme = 0 end
- if minOpenTime < 1 then minOpenTime = 5 elseif minOpenTime > maxOpenTime then minOpenTime = 5 end
- if maxOpenTime < minOpenTime then maxOpenTime = 2280 end
- if pauseBetweenDials < 2 then pauseBetweenDials = 3 end
- if infoTime < 0 then infoTime = 10 end
- if ringsTheme <= 0 then ringsTheme = 0 elseif ringsTheme > 3 then ringsTheme = 0 end
- 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
- 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
- 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
- -- End of Check of user Settings ------------------------------------
- -- Components and system requirements check -------------------------
- if gpu.maxResolution() < 81 then
- activeErrors = activeErrors + 1
- fatalError = true
- table.insert(errorsLog, "Tier 3 GPU and Screen Required")
- end
- if component.isAvailable("transportrings") then
- rings = component.transportrings
- errorBypass = true
- NumberOfRings = 0
- for k,v in component.list() do if v == "transportrings" then NumberOfRings = NumberOfRings + 1 end end
- if NumberOfRings > 1 then
- activeErrors = activeErrors + 1
- fatalError = true
- table.insert(errorsLog, "Too Many Transport Rings Connected to Computer.")
- end
- end
- if component.isAvailable("stargate") then
- stargate = component.stargate
- NumberOfGates = 0
- for k,v in component.list() do if v == "stargate" then NumberOfGates = NumberOfGates + 1 end end
- if NumberOfGates > 1 then
- activeErrors = activeErrors + 1
- fatalError = true
- table.insert(errorsLog, "Too Many Stargates Connected to Computer.")
- end
- if stargate.getGateType() ~= "MILKYWAY" then fastDial = false else errorBypass = false end
- end
- if component.isAvailable("dhd") then
- dhd = component.dhd
- if errorBypass == false then
- NumberOfDHDs = 0
- for k,v in component.list() do if v == "dhd" then NumberOfDHDs = NumberOfDHDs + 1 end end
- if NumberOfDHDs > 1 then
- activeErrors = activeErrors + 1
- fatalError = true
- table.insert(errorsLog, "Too Many DHD Connected to Computer.")
- end
- end
- else
- if errorBypass == false and fastDial then
- activeErrors = activeErrors + 1
- table.insert(errorsLog, "No DHD Connected, Turning off DHD dial")
- fastDial = false
- end
- end
- if component.isAvailable("redstone") then
- rs = component.redstone
- NumberOfRsIOs = 0
- for k,v in component.list() do if v == "redstone" then NumberOfRsIOs = NumberOfRsIOs + 1 end end
- if NumberOfRsIOs > 1 then
- activeErrors = activeErrors + 1
- fatalError = true
- table.insert(errorsLog, "Too Many Redstone Components Connected to Computer (RedstoneIO, Redstone Card)")
- end
- else
- activeErrors = activeErrors + 1
- fatalError = true
- table.insert(errorsLog, "No Redstone Component Installed (RedstoneIO or Redstone Card.")
- end
- if component.isAvailable("transportrings") and component.isAvailable("stargate") then
- activeErrors = activeErrors + 1
- fatalError = true
- table.insert(errorsLog, "Multiple types of transport devices detected!")
- end
- if not component.isAvailable("transportrings") and not component.isAvailable("stargate") then
- activeErrors = activeErrors + 1
- fatalError = true
- table.insert(errorsLog, "No Transport Rings or Stargate Connected.")
- end
- if activeErrors > 0 then
- term.clear()
- if activeErrors >= 2 then print("Multiple Errors Detected:") else print("Error Detected:") end
- print()
- gpu.setForeground(0xFF0000)
- for i, v in ipairs(errorsLog) do
- print("Error #" .. i .. " " .. v)
- computer.beep()
- os.sleep(0.2)
- end
- for i, v in ipairs(errorsLog) do
- table.remove(errorsLog, i)
- end
- gpu.setForeground(0xFFFFFF)
- os.sleep(2)
- if fatalError then os.exit(1) end
- end
- -- End of Components and system requirements check ------------------
- -- Button Objects ---------------------------------------------------
- local Button = {}
- Button.__index = Button
- function Button.new(xPos, yPos, width, height, label, func, border)
- local self = setmetatable({}, Button)
- if xPos < 1 or xPos > term.window.width then xPos = 1 end
- if yPos < 1 or yPos > term.window.height then yPos = 1 end
- if (width-2) < unicode.len(label) then width = unicode.len(label)+2 end
- if height < 3 then height = 3 end
- if border == nil then
- self.border = true
- else
- self.border = border
- end
- self.xPos = xPos
- self.yPos = yPos
- self.width = width
- self.height = height
- self.label = label
- self.func = func
- self.visible = false
- self.disabled = false
- return self
- end
- function Button.display(self, x, y)
- table.insert(ActiveButtons, 1, self)
- if (self.width-2) < unicode.len(self.label) then self.width = unicode.len(self.label)+2 end
- if x ~= nil and y ~= nil then
- self.xPos = x
- self.yPos = y
- end
- if self.border then
- gpu.fill(self.xPos+1, self.yPos, self.width-2, 1, "─")
- gpu.fill(self.xPos+1, self.yPos+self.height-1, self.width-2, 1, "─")
- gpu.fill(self.xPos, self.yPos+1, 1, self.height-2, "│")
- gpu.fill(self.xPos+self.width-1, self.yPos+1, 1, self.height-2, "│")
- gpu.set(self.xPos, self.yPos, "┌")
- gpu.set(self.xPos+self.width-1, self.yPos, "┐")
- gpu.set(self.xPos, self.yPos+self.height-1, "└")
- gpu.set(self.xPos+self.width-1, self.yPos+self.height-1, "┘")
- end
- gpu.set(self.xPos+1, self.yPos+1, self.label)
- self.visible = true
- end
- function Button.hide(self)
- self.visible = false
- for i,v in ipairs(ActiveButtons) do
- if v == self then table.remove(ActiveButtons, i) end
- end
- if self.border then
- gpu.fill(self.xPos, self.yPos, self.width, self.height, " ")
- else
- gpu.fill(self.xPos+1, self.yPos+1, self.width-2, 1, " ")
- end
- end
- function Button.disable(self, bool)
- if bool == nil then
- self.disabled = false
- else
- self.disabled = bool
- end
- if self.disabled then gpu.setForeground(0x0F0F0F) end
- if self.visible then self:display() end
- gpu.setForeground(0xFFFFFF)
- end
- function Button.touch(self, x, y)
- local wasTouched = false
- if self.visible and not self.disabled then
- if self.border then
- if x >= self.xPos and x <= (self.xPos+self.width-1) and y >= self.yPos and y <= (self.yPos+self.height-1) then wasTouched = true end
- else
- if x >= self.xPos+1 and x <= (self.xPos+self.width-2) and y >= self.yPos+1 and y <= (self.yPos+self.height-2) then wasTouched = true end
- end
- end
- if wasTouched then
- gpu.setBackground(0x878787)
- gpu.set(self.xPos+1, self.yPos+1, self.label)
- gpu.setBackground(0x000000)
- if self.visible then gpu.set(self.xPos+1, self.yPos+1, self.label) end
- self.func()
- end
- return wasTouched
- end
- function Button.forceTouch(self)
- self:touch(self.xPos+1, self.yPos+1)
- end
- -- End of Button Objects --------------------------------------------
- -- Common Events ----------------------------------------------------
- eventInterrupted = event.listen("interrupted", function()
- forceStop = true
- end)
- eventTouch = event.listen("touch", function(_, screenAddress, x, y, button, playerName)
- local success, msg = xpcall(function()
- if button == 0 then
- for i,v in ipairs(ActiveButtons) do
- if v:touch(x,y) then break end
- end
- end
- end)
- end)
- -- eventy na tlačitka
- -- End of Common Events --------------------------------------------
- -- Buttons ----------------------------------------------------------
- buttons = {
- toggleIrisButton = Button.new(44, 26, 13, 3, "Toogle Iris", function()
- stargate.toggleIris()
- if intruderDetector then intruderDetector = false end
- end),
- toggleShieldButton = Button.new(42, 26, 15, 3, "Toogle Shield", function()
- stargate.toggleIris()
- if intruderDetector then intruderDetector = false end
- end),
- mainButton = Button.new(4, 10, 96, 3, " ", function()
- wasPressed = true
- end),
- abortButton = Button.new(58, 26, 15, 3, "Abort Dialing", function()
- stargate.abortDialing()
- dial = false
- end),}
- -- End of Buttons ---------------------------------------------------
- -- Functions --------------------------------------------------------
- ---- Common functions ----------------------------------------------
- local function checkThisTableContent(subject, minLenght, maxLenght, shortError, longError)
- gpu.setForeground(0xFF0000)
- for i, v in ipairs(subject) do testedValue = i end
- if testedValue <= minLenght then print(shortError)
- elseif testedValue > maxLenght then print(longError)
- end
- gpu.setForeground(0xFFFFFF)
- end
- local function errorMessagenger(errorMessage)
- gpu.setForeground(0xFF0000)
- print(errorMessage)
- computer.beep()
- gpu.setForeground(0xFFFFFF)
- end
- local function timer(seconds)
- seconds = seconds * 10
- for i = 0 , seconds do
- if forceStop then break end
- os.sleep(0.1)
- end
- end
- local function gateTimer(countdown)
- local countdown = tonumber(countdown)
- if countdown <= 0 then
- return "00:00"
- else
- hours = string.format("%02.f", math.floor(countdown/3600))
- mins = string.format("%02.f", math.floor(countdown/60 - (hours*60)))
- secs = string.format("%02.f", math.floor(countdown - hours*3600 - mins *60))
- end
- end
- local function hideAllButtons()
- buttons.toggleIrisButton:hide()
- buttons.toggleShieldButton:hide()
- buttons.mainButton:hide()
- buttons.abortButton:hide()
- buttons.toggleIrisButton:disable(true)
- buttons.toggleShieldButton:disable(true)
- buttons.mainButton:disable(true)
- buttons.abortButton:disable(true)
- end
- ---- End of Common functions ---------------------------------------
- ---- Main Screen functions -----------------------------------------
- logo = [[⢸⠀⡇⠀⢸⠀⡎⠉⠱⠀⠉⢹⠉⠁ ⠀⢸⠉⠉⡆⢸⠉⠉⡆⢸⠉⠉⠀⡎⠉⠱⠀⡎⠉⠱ ⡏⠉⡆⠀⡇⠀⢸⠀⠉⢹⠉⠁⠈⠉⡏⠉⠀⡎⠉⢱⠀⡷⡄⢸
- ⡆⠀⢸⠀⡇⠀⢸⠀⡌⠉⢱⠀⠀⢸⠀⠀⠀ ⢸⠉⠉⠀⢸⠉⠫⡀⢸⠉⠉⠀⡌⠉⢱⠀⡌⠉⢱ ⡏⠉⢱⠀⡇⠀⢸⠀⠀⢸⠀⠀⠀⠀⡇⠀⠀⡇⠀⢸⠀⡇⠹⣼
- ⠈⠉⠁⠀⠈⠉⠁⠀⠈⠉⠁⠀⠀⠈⠀⠀⠀ ⠈⠀⠀⠀⠈⠀⠀⠁⠈⠉⠉⠀⠈⠉⠁⠀⠈⠉⠁ ⠉⠉⠁⠀⠈⠉⠁⠀⠀⠈⠀⠀⠀⠀⠁⠀⠀⠈⠉⠁⠀⠁⠀⠈ ]]
- milkywaySubLogo = "⣳⡃⣩⡁⣺⠅⣻⡇⣏⠃⡳⡇⠭⡇⣏⠃ ⢸⠺⢨⢬⠨⢽⢨⣩⢸⣘⠨⢽⢨⢬⢸⢬ ⢸⢹⢘⢮⢠⢷⢨⢬⢨⣩⢘⢮⢐⡯"
- pegasusSubLogo = "⡇⡁⡧⡅⣇⡃⠭⡇⡗⠇⠉⡇⡗⠇ ⢸⠺⢨⢬⠨⢽⢨⣩⢸⣘⠨⢽⢨⢬⢸⢬ ⢸⢹⢘⢮⢠⢷⢨⢬⢨⣩⢘⢮⢐⡯"
- universeSubLogo = "⠉⡇⡼⡆⣩⡁⣹⡇⡧⡅⣍⡅⡗⠇⡧⡅ ⢸⠺⢨⢬⠨⢽⢨⣩⢸⣘⠨⢽⢨⢬⢸⢬ ⢸⢹⢘⢮⢠⢷⢨⢬⢨⣩⢘⢮⢐⡯"
- oriSubLogo = "⡳⡅⣍⡅⣩⡁ ⡥⡅⣍⡅⠭⡇⡼⡆⡗⠇⡇⡁⡳⡅⣍⡅⡥⡅ ⣍⡅⣩⡁⡼⡆⣇⡃⡗⠇ ⢸⢹⢘⢮⢠⢷⢨⢬⢨⣩⢘⢮⢐⡯"
- ancientsSubLogo = "⠭⡇⡼⡆⡏⡇⣩⡁⡧⡅⡼⡆⡥⡅⡗⠇ ⡥⡅⣍⡅⠭⡇⡼⡆⡗⠇⡇⡁⡳⡅⣍⡅⡥⡅ ⣍⡅⣩⡁⡼⡆⣇⡃⡗⠇ ⢸⢹⢘⢮⢠⢷⢨⢬⢨⣩⢘⢮⢐⡯"
- goauldSubLogo = "⢔⣹⣏⡢⢄⣀⠀⣄⣻⣘⣇⣻⡀ ⢀⡶⣄⡴⠦⠀⡠⡠⡠⡠⡀ ⠐⢶⣶⠖⢖⠄ ⢀⡶⣄⡴⠦ ⢔⣹⣏⡢⢄⣀"
- local function mainScreen()
- gpu.setResolution(72, 28)
- term.clear()
- term.setCursor(7,2)
- print(logo)
- print()
- end
- local function operationScreen()
- mainScreen()
- gpu.setForeground(subColor)
- term.setCursor(posX, 5)
- print(subLogo)
- gpu.setForeground(colorDefault)
- term.setCursor(1, 8)
- end
- local function bootingScreen()
- mainScreen()
- print(changelog)
- timer(changelogTimer)
- mainScreen()
- print(instructions)
- timer(infoTime)
- end
- local function closingScreen()
- operationScreen()
- term.setCursor(32,8)
- print("Good bye")
- end
- ---- End of Main Screen functions ----------------------------------
- ---- Stargate functions---------------------------------------------
- local function setupByGateType()
- if stargate.getGateType() == "MILKYWAY" then
- stargateAddress = stargateAddressMW
- PoO = {"Point of Origin"}
- subLogo = milkywaySubLogo
- subColor = colorRed
- posX = 14
- if fastDial == false then walterMes = true end
- elseif stargate.getGateType() == "PEGASUS" then
- stargateAddress = stargateAddressPG
- PoO = {"Subido"}
- subLogo = pegasusSubLogo
- subColor = colorBlue
- posX = 14
- else
- stargateAddress = stargateAddressUNI
- PoO = {"G17"}
- subLogo = universeSubLogo
- subColor = colorGray
- posX = 13
- end
- end
- local function completeAddress(t1, t2)
- for i=1, #t2 do
- t1[#t1 + 1] = t2[i]
- end
- end
- local function energyLevel()
- if type(stargate.getEnergyRequiredToDial(table.unpack(stargateAddress))) == "table" then
- if stargate.getEnergyStored() < stargate.getEnergyRequiredToDial(table.unpack(stargateAddress)).open + (stargate.getEnergyRequiredToDial(table.unpack(stargateAddress)).keepAlive * 20 * minOpenTime) then
- errorMessagenger("Not Enough Energy to Establish Connection")
- energyCancel = true
- end
- else
- if forceDial == false then errorMessagenger("No Stargate Detected on Provided Address") energyCancel = true end
- end
- end
- local function IrisCheck()
- if stargate.getIrisType() == "NULL" then irisAutoClose = false else
- if stargate.getIrisState() == "CLOSED" then stargate.toggleIris() end
- end
- if stargate.getIrisType() == "SHIELD" then
- buttons.toggleShieldButton:display()
- buttons.toggleShieldButton:disable(false)
- elseif stargate.getIrisState ~= "NULL" and stargate.getIrisState ~="SHIELD" then
- buttons.toggleIrisButton:display()
- buttons.toggleIrisButton:disable(false)
- end
- end
- local function computerDial(dialed)
- glyph = stargateAddress[dialed + 1]
- if walterMes == false then
- print("Engaging " .. glyph .. "...")
- end
- stargate.engageSymbol(glyph)
- end
- local function dhdDial(dialed)
- for i, v in ipairs(stargateAddress) do
- if offWorldActivation or forceStop then break end
- glyph = stargateAddress[i]
- print("DHD button pressed: "..glyph.."... ")
- dhd.pressButton(glyph)
- os.sleep(0.6)
- end
- if offWorldActivation == false or forceStop == false then
- os.sleep(1.4)
- print("DHD button pressed: Big Red Button... ")
- dhd.pressBRB()
- rsLockDialed = true
- end
- end
- local function IDCsender()
- if brokenBroadcastIDC then errorMessagenger("Broadcast IDC Failed: Invalid IDC") sendIDC = false else print("IDC: " .. IDC .. " sent successfully") stargate.sendIrisCode(IDC) end
- end
- ---- End of Stargate functions -------------------------------------
- ---- Stargate events -----------------------------------------------
- local function startStargateEvents()
- stargateEventsActive = true
- openEvent = event.listen("stargate_open", function()
- if offWorldActivation == false then
- buttons.abortButton:hide()
- buttons.abortButton:disable(true)
- if walterMes == false then print("Stargate opened successfully") end
- rsLockDialed = true
- loop = false
- end
- end)
- failEvent = event.listen("stargate_failed", function()
- if offWorldActivation == false then
- dialingFailed = true
- if walterMes then print("Chevron " .. encodedChevron .. " will not engage. It won't Lock. Can't Establish Connection") else print("Stargate failed to open") end
- if fastDial then errorMessagenger("Make Sure the DHD Contains the Glyph Crystal") timer(2) end
- timer(2)
- cancelStargateEvents()
- end
- end)
- closedEvent = event.listen("stargate_wormhole_closed_fully", function()
- if offWorldActivation then print("Conection lost") timer(1) end
- rsLockDialed = false
- disconnected = true
- if stargate.getIrisState() == "CLOSED" then stargate.toggleIris()
- if stargate.getIrisType() ~= "SHIELD" then print("Opening IRIS") else print("Turning OFF Shield") end
- end
- if standBy == false then cancelStargateEvents() end -------------------------------------------------------------------------------------------------------------------------------------------
- end)
- incomingEvent = event.listen("stargate_incoming_wormhole", function()
- offWorldActivation = true
- loop = false
- buttons.abortButton:hide()
- buttons.abortButton:disable(true)
- if dial then stargate.abortDialing() end
- dial = false
- if irisAutoClose and stargate.getIrisState() == "OPENED" then stargate.toggleIris() os.sleep(0.2)
- if stargate.getIrisType() ~= "SHIELD" then print("Closing IRIS") else print("Turning ON Shield") end
- end
- end)
- eventEngaged = event.listen("stargate_spin_chevron_engaged", function(evname, address, caller, num, lock, glyph)
- os.sleep(0.5)
- if lock then
- if walterMes then print("Chevron "..encodedChevron.." Locked") end
- stargate.engageGate()
- else
- if walterMes then print("Chevron "..encodedChevron.. " encoded...") encodedChevron = encodedChevron + 1 end
- computerDial(num)
- end
- end)
- eventReceiveCode = event.listen("received_code", function(_, _, _, code)
- os.sleep(0.5)
- if intruderDetector then stargate.sendMessageToIncoming("Intruder Entry Prohibited") else
- if irisAutoClose and brokenLocalIDC == false then
- if thisIDC == code then
- if stargate.getIrisState() == "CLOSED" then stargate.toggleIris() wasOpened = true
- 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
- else
- if stargate.getIrisType() == "SHIELD" then stargate.sendMessageToIncoming("Shield is OFF!") else stargate.sendMessageToIncoming("Iris is Open!") end
- end
- elseif thisIDC ~= code and stargate.getIrisState() == "CLOSED" then stargate.sendMessageToIncoming("IDC is Incorrect!")
- elseif thisIDC ~= code and stargate.getIrisState() == "OPENED" and wasOpened then
- 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
- stargate.toggleIris()
- intruderDetector = true
- end
- elseif irisAutoClose and brokenLocalIDC then errorMessagenger("Error: IDC Database is Damaged!") stargate.sendMessageToIncoming("Error: Database is Damaged - Your IDC is not Valid!")
- end
- end
- end)
- end
- function cancelStargateEvents()
- event.cancel(eventEngaged)
- event.cancel(openEvent)
- event.cancel(failEvent)
- event.cancel(incomingEvent)
- event.cancel(closedEvent)
- event.cancel(eventReceiveCode)
- loop = false
- stargateEventsActive = false
- end
- ---- End of Stargate events ----------------------------------------
- ---- Transport Rings functions -------------------------------------
- local function AunisVersionCheck()
- local success, result = pcall(rings.getAunisVersion)
- if not success then AunisVersion = "legacy" else AunisVersion = result end
- end
- local function setupByRingsType()
- ringsAddress = ringsAddressGoauld
- ringType = 0
- lastSymbol = 5
- if ringsTheme == 0 then
- --ringsAddress = ringsAddressGoauld ringType = 0 lastSymbol = 5
- subLogo = goauldSubLogo
- subColor = colorGold
- posX = 13
- elseif ringsTheme == 1 then
- -- ringsAddress = ringsAddressOri ringType = 1 lastSymbol = 5
- subLogo = oriSubLogo
- subColor = colorLightGray
- posX = 11
- else
- -- ringsAddress = ringsAddressAncients ringType = 2 lastSymbol = ""
- subLogo = ancientsSubLogo
- subColor = colorLightBlue
- posX = 6
- end
- end
- local function messageSystem(msg)
- if msg ~= "OK" then
- local msgString = resultMessages[msg]
- if msgString == nil then msgString = msg end
- if msg == "ACTIVATED" then
- print(msgString)
- else
- errorMessagenger(msgString)
- rsLockDialed = false
- ringsFailed = true
- end
- timer(3)
- end
- end
- local function dialRings()
- rsLockDialed = true
- for i,v in pairs(ringsAddress) do
- if forceStop then break end
- symbol = ringsAddress[i]
- print("Symbol engaged: " .. symbol .. "...")
- rings.addSymbolToAddress(ringType, symbol)
- os.sleep(0.5)
- end
- if forceStop == false then
- os.sleep(0.5)
- local result = rings.addSymbolToAddress(ringType, lastSymbol)
- messageSystem(result)
- end
- end
- ---- End of Transport Rings functions ------------------------------
- ---- Transport Rings events ----------------------------------------
- local function startRingsEvents()
- ringsEventsActive = true
- eventTeleportStart = event.listen("transportrings_teleport_start", function(_, address, caller, initiating)
- mainRSLoop = false
- rsLockDialed = true
- end)
- eventTeleportFinished = event.listen("transportrings_teleport_finished", function(_, address, caller, initiating)
- rsLockDialed = false
- computer.beep()
- end)
- end
- local function cancelRingsEvents()
- event.cancel(eventTeleportStart)
- event.cancel(eventTeleportFinished)
- ringsEventsActive = false
- end
- ---- End of Transport Rings events ---------------------------------
- -- End of Functions -------------------------------------------------
- -- Initialization ---------------------------------------------------
- hideAllButtons()
- bootingScreen()
- if component.isAvailable("stargate") then
- setupByGateType()
- checkThisTableContent(stargateAddress, 5, 8, "Incomplete Stargate Address or No Stargate Address Entered.", "Stargate Address Corrupted")
- completeAddress(stargateAddress, PoO)
- end
- if component.isAvailable("transportrings") then
- setupByRingsType()
- for i, v in ipairs(ringsAddress)do
- print(v)
- end
- checkThisTableContent(ringsAddress, 3, 5, "Incomplete Rings Address or No Rings Address Entered.", "Rings Address Corrupted")
- end
- -- End of Initialization --------------------------------------------
- -- Main Loop --------------------------------------------------------
- ::Start::
- if stargateEventsActive then cancelStargateEvents() end
- if ringsEventsActive then cancelRingsEvents() end
- operationScreen()
- if component.isAvailable("transportrings") then goto Rings end
- timer(1)
- ---- Stargate Dialing sequence -------------------------------------
- ------ Loop Declarations ------------------------------------------
- loop = false
- dial = false
- rsLockDialed = false
- energyCancel = false
- wasOpened = false
- wasTouched = false
- dialingFailed = false
- offWorldActivation = false
- intruderDetector = false
- mainRSLoop = true
- standBy = true
- dialed = 0
- encodedChevron = 1
- ------ end of Loop Declarations -----------------------------------
- ------ Initialization ---------------------------------------------
- buttons.toggleIrisButton:hide()
- buttons.toggleShieldButton:hide()
- buttons.toggleIrisButton:disable(true)
- buttons.toggleShieldButton:disable(true)
- if stargate.dialedAddress == nil then
- if stargate.getIrisState() == "OPENED" then stargate.toggleIris() end
- startStargateEvents()
- offWorldActivation = true
- os.sleep(0.1)
- goto IncomingLoop
- elseif stargate.dialedAddress ~= "[]" and stargate.dialedAddress ~= nil and stargate.getGateStatus() ~= "open" then
- stargate.abortDialing()
- print("Clearing Stargate Address buffer")
- timer(1)
- end
- if stargate.getGateStatus() == "open" then print("Closing Stargate") stargate.disengageGate() timer(1) end
- startStargateEvents()
- if stargate.getGateStatus() ~= "idle" and stargate.getGateType() == "UNIVERSE" then print("Stargate is Restarting...") end
- while stargate.getGateStatus() ~= "idle" do os.sleep(0.1) if forceStop then goto CloseProgram end end
- timer(1)
- IrisCheck()
- ------ End of Initialization --------------------------------------
- ------ Dialing Programs -------------------------------------------
- operationScreen()
- print("Press Button to Activate Stargate Dialing Sequence")
- print()
- disconnected = false
- while mainRSLoop do
- if forceStop then goto CloseProgram end
- if rs.getInput(rsInput) > 0 or wasTouched then
- mainRSLoop = false
- wasTouched = false
- end
- if offWorldActivation then mainRSLoop = false goto IncomingLoop end
- os.sleep(0.1)
- end
- energyLevel()
- if energyCancel then timer(5) cancelStargateEvents() goto Start end
- buttons.abortButton:display()
- buttons.abortButton:disable(false)
- if fastDial then print("Initiate the dialing sequence with DHD") dhdDial(0) dial = true else
- if walterMes then print("Input the coordinates and initiate the dialing sequence") else print("Dialing the Stargate") end
- computerDial(0)
- loop = true
- dial = true
- while loop do
- if forceStop then goto CloseProgram end
- if offWorldActivation then loop = false goto IncomingLoop end
- os.sleep(0.1)
- end
- end
- print()
- timer(1)
- if sendIDC and dialingFailed == false then timer(4) IDCsender() print() computer.beep() else timer(2) end
- if dialingFailed then goto Start end
- ------ End of Dialing Programs ------------------------------------
- ------ Interlock Loops --------------------------------------------
- if rsLockDialed then
- term.setCursor(1, 24)
- if gateAutoClose then print("Stargate closes in: ") else print("Press Button to Close Stargate") end
- if gateAutoClose == false then
- while disconnected == false do
- os.sleep(0.1)
- if rs.getInput(rsInput) > 0 or wasTouched then
- wasTouched = false
- break end
- if forceStop then goto CloseProgram end
- end
- else
- loopTime = maxOpenTime * 10
- stopwatch = maxOpenTime
- gateTimer(stopwatch)
- clockLoop = 0
- term.setCursor(21 ,24)
- print(mins.. ":" .. secs)
- for i = 0, loopTime do
- clockLoop = clockLoop + 1
- if clockLoop == 5 then term.setCursor(21 ,24) print(mins.. " " .. secs) elseif clockLoop == 10 then
- clockLoop = 0
- stopwatch = stopwatch - 1
- gateTimer(stopwatch)
- term.setCursor(21 ,24)
- print(mins.. ":" .. secs)
- end
- if forceStop then goto CloseProgram end
- if rs.getInput(rsInput) > 0 or wasTouched then
- wasTouched = false
- break end
- if disconnected then break end
- os.sleep(0.1)
- end
- end
- stargate.disengageGate()
- print("Closing stargate")
- timer(1)
- if stargate.getGateStatus() ~= "idle" and stargate.getGateType() == "UNIVERSE" then print("Stargate is Restarting...") end
- while stargate.getGateStatus() ~= "idle" do os.sleep(0.1) if forceStop then goto CloseProgram end end
- cancelStargateEvents()
- goto Start
- end
- ::IncomingLoop::
- if offWorldActivation then operationScreen()
- if walterMes then print("Unscheduled Offworld Activation") print() else print("Incoming Wormhole!") print() end
- while offWorldActivation do
- if forceStop then goto CloseProgram end
- if disconnected then break end
- os.sleep(0.1)
- end
- end
- cancelStargateEvents()
- goto Start
- ------ End of Interlock Loops -------------------------------------
- ---- End of Stargate Dialing sequence ------------------------------
- ---- Transport Rings Dialing sequence ------------------------------
- ::Rings::
- ------ Loop Declarations ------------------------------------------
- mainRSLoop = true
- rsLockDialed = false
- ringsFailed = false
- ------ End of Loop Declarations -----------------------------------
- ------ Initialization ---------------------------------------------
- AunisVersionCheck()
- if AunisVersion == "legacy" then
- errorMessagenger("You are using outdated version of Aunis (JSG). This program is not compatible for transport rings control.")
- print() print("Supported versions: 4.10.0.1 and newer")
- timer(6)
- goto CloseProgram
- end
- rings.addSymbolToAddress(ringType, lastSymbol)
- os.sleep(0.5)
- startRingsEvents()
- ------ End of Initialization --------------------------------------
- ------ Rings Dialing Program --------------------------------------
- print("Press Button to Activate Transport Rings")
- print()
- timer(1)
- while mainRSLoop do
- if forceStop then goto CloseProgram end
- if rs.getInput(rsInput) > 0 or wasTouched then
- mainRSLoop = false
- wasTouched = false
- end
- os.sleep(0.1)
- end
- print("Activating Transport Rings Dialing Sequence")
- dialRings()
- ------ End of Rings Dialing program -------------------------------
- ------ Interlock Loop ---------------------------------------------
- while rsLockDialed do
- if forceStop then goto CloseProgram end
- os.sleep(0.1)
- end
- if ringsFailed == false then
- print()
- print("Preparing Transport Rings for further operation")
- timer(pauseBetweenDials)
- end
- cancelRingsEvents()
- goto Start
- ------End of Interlock Loop ---------------------------------------
- ---- End of Transport Rings Dialing sequence -----------------------
- -- End of Main Loop -------------------------------------------------
- -- Closing procedure ------------------------------------------------
- ::CloseProgram::
- event.cancel(eventInterrupted)
- event.cancel(eventTouch)
- hideAllButtons()
- if stargateEventsActive then cancelStargateEvents() end
- if ringsEventsActive then cancelRingsEvents() end
- if component.isAvailable("stargate") and dial then stargate.abortDialing() end
- closingScreen()
- os.sleep(2)
- term.clear()
- gpu.setResolution(160, 50)
- -- End of Closing procedure ----------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement