Advertisement
Fredyman_95

JPB dev2

Oct 5th, 2022 (edited)
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 42.02 KB | Gaming | 0 0
  1. --[[
  2. Just Press Button Program
  3. v5.8.3.12
  4.  
  5. Created By: Fredyman_95
  6. Special Thanks To: Augur ShicKla
  7. ]]--
  8. -- User settings ----------------------------------------------------
  9. ---- General Settings
  10. infoTime = 3 -- 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 = true -- 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 = 55 -- 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 = 1234 -- Replace nil with IDC of DIALED gate e.g 1234 -> IDC = 1234
  31.  
  32. ---- Stargate address - fill without PoO ---------------------------
  33. stargateAddressMW = {"Microscopium", "Leo", "Lynx", "Norma", "Eridanus", "Centaurus", "Perseus"} -- {"Serpens caput", "Leo", ... "Perseus"}
  34. --stargateAddressMW = {"Canis Minor", "Lynx", "Sextans", "Microscopium", "Virgo", "Serpens Caput"}
  35. stargateAddressPG = {"Illume", "Olavii", "Ecrumig", "Abrin", "Ramnon", "Sibbron"} -- {"Illume", "Poco re", ... "Sibbron"}
  36. stargateAddressUNI = {"G23", "G32", "G11", "G1", "G31", "G34", "G20", "G13"} -- {"G1", "G2", ... "G8"}
  37.  
  38. ---- Rings address -------------------------------------------------
  39. ringsAddressGoauld = {"Amun", "Khepri", "Serket", "Felluca"} -- {"Amun", "Khepri", ... "Felluca"}
  40. ringsAddressOri = {} -- Just Stargate Mod -> WIP
  41. ringsAddressAncients = {} -- Just Stargate Mod -> WIP
  42.  
  43. -- End of User settings----------------------------------------------
  44.  
  45. -- Declarations -----------------------------------------------------
  46. local component = require("component")
  47. local computer = require("computer")
  48. local event = require("event")
  49. local sides = require("sides")
  50. local term = require("term")
  51. local unicode = require("unicode")
  52. local gpu = component.gpu
  53. local screen = component.screen
  54. local brokenBroadcastIDC = false
  55. local brokenLocalIDC = false
  56. local dial = false
  57. local dialingFailed = false
  58. local energyCancel = false
  59. local errorBypass = false
  60. local fatalError = false
  61. local first = true
  62. local forceStop = false
  63. local intruderDetector = false
  64. local loop = false
  65. local mainRSLoop = false
  66. local offWorldActivation = false
  67. local ringsFailed = false
  68. local rsLockDialed = false
  69. local standBy = false
  70. local walterMes = false
  71. local wasOpened = false
  72. local wasPressed = false
  73. local disconnected = false
  74. local activeErrors = 0
  75. local changelogTimer = 2
  76. local colorBlue = 0x0092FF
  77. local colorDefault = 0xFFFFFF
  78. local colorGold = 0xFFDB00
  79. local colorGray = 0x969696
  80. local colorLightBlue = 0x00DBFF
  81. local colorLightGray = 0xB4B4B4
  82. local colorRed = 0xFF2100
  83. local resultMessages = {
  84. OK = "OK",
  85. ACTIVATED = "Transport Rings Are Activated",
  86. BUSY = "Local Transport Rings platform is Busy",
  87. BUSY_TARGET = "Target Transport Rings platform is Busy",
  88. OBSTRUCTED = "Local Transport Rings platform is Obstructed",
  89. OBSTRUCTED_TARGET = "Target Transport Rings platform is Obstructed",
  90. NOT_ENOUGH_POWER = "Not Enough Energy to Activate Transport Rings",
  91. NO_SUCH_ADDRESS = "No Transport Ring Platform Detected on Provided Address"}
  92. local changelog = [[ Changelog:
  93.  
  94. - Fixed universe abort Dialing bug
  95. - Added buttons]]
  96. local instructions = [[ Instructions:
  97.  
  98. 1. Edit and check out all settings in User settings
  99. Lines 9 - 36
  100. Default command: edit JPB
  101.  
  102. 2. Press CTRL + C or restart the computer to exit the program
  103. properly
  104.  
  105. 3. Setup your RedstoneIO and connect to selected side BUTTON!
  106. !!NO LEVER!! lever will cause instant repeat of program loop.
  107.  
  108. 4. You can reduce the time for which this message is displayed in
  109. the User Settings - line 19]]
  110. local subLogo = ""
  111. local subColor = ""
  112. local posX = ""
  113. local dialed = ""
  114. local encodedChevron = ""
  115. local symbol = ""
  116. local lastSymbol = ""
  117. local rsInput = ""
  118. local ringType = ""
  119. local AunisVersion = ""
  120. local PoO = {}
  121. local stargateAddress = {}
  122. local ringsAddress = {}
  123. local errorsLog = {}
  124. local ActiveButtons = {}
  125. local buttons = {}
  126. -- End of Declarations ----------------------------------------------
  127.  
  128. -- HARD TO CODE => HARD TO READ!!!
  129.  
  130. -- Check of user Settings -------------------------------------------
  131. if type(fastDial) ~= "boolean" then fastDial = false end
  132. if type(irisAutoClose) ~= "boolean" then irisAutoClose = false end
  133. if type(sendIDC) ~= "boolean" then sendIDC = false end
  134. if type(gateAutoClose) ~= "boolean" then gateAutoClose = false end
  135. if type(forceDial) ~= "boolean" then forceDial = false end
  136. if type(minOpenTime) ~= "number" then minOpenTime = 10 end
  137. if type(maxOpenTime) ~= "number" then maxOpenTime = 2280 end
  138. if type(pauseBetweenDials) ~= "number" then pauseBetweenDials = 3 end
  139. if type(infoTime) ~= "number" then infoTime = 10 end
  140. if type(ringsTheme) ~= "number" then ringsTheme = 0 end
  141. if minOpenTime < 1 then minOpenTime = 5 elseif minOpenTime > maxOpenTime then minOpenTime = 5 end
  142. if maxOpenTime < minOpenTime then maxOpenTime = 2280 end
  143. if pauseBetweenDials < 2 then pauseBetweenDials = 3 end
  144. if infoTime < 0 then infoTime = 10 end
  145. if ringsTheme <= 0 then ringsTheme = 0 elseif ringsTheme > 3 then ringsTheme = 0 end
  146. 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
  147. 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
  148. 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
  149.  
  150. -- End of Check of user Settings ------------------------------------
  151.  
  152. -- Components and system requirements check -------------------------
  153. if gpu.maxResolution() < 81 then
  154. activeErrors = activeErrors + 1
  155. fatalError = true
  156. table.insert(errorsLog, "Tier 3 GPU and Screen Required")
  157. end
  158.  
  159. if component.isAvailable("transportrings") then
  160. rings = component.transportrings
  161. errorBypass = true
  162. NumberOfRings = 0
  163. for k,v in component.list() do if v == "transportrings" then NumberOfRings = NumberOfRings + 1 end end
  164. if NumberOfRings > 1 then
  165. activeErrors = activeErrors + 1
  166. fatalError = true
  167. table.insert(errorsLog, "Too Many Transport Rings Connected to Computer.")
  168. end
  169. end
  170.  
  171. if component.isAvailable("stargate") then
  172. stargate = component.stargate
  173. NumberOfGates = 0
  174. for k,v in component.list() do if v == "stargate" then NumberOfGates = NumberOfGates + 1 end end
  175. if NumberOfGates > 1 then
  176. activeErrors = activeErrors + 1
  177. fatalError = true
  178. table.insert(errorsLog, "Too Many Stargates Connected to Computer.")
  179. end
  180. if stargate.getGateType() ~= "MILKYWAY" then fastDial = false else errorBypass = false end
  181. end
  182.  
  183. if component.isAvailable("dhd") then
  184. dhd = component.dhd
  185. if errorBypass == false then
  186. NumberOfDHDs = 0
  187. for k,v in component.list() do if v == "dhd" then NumberOfDHDs = NumberOfDHDs + 1 end end
  188. if NumberOfDHDs > 1 then
  189. activeErrors = activeErrors + 1
  190. fatalError = true
  191. table.insert(errorsLog, "Too Many DHD Connected to Computer.")
  192. end
  193. end
  194. else
  195. if errorBypass == false and fastDial then
  196. activeErrors = activeErrors + 1
  197. table.insert(errorsLog, "No DHD Connected, Turning off DHD dial")
  198. fastDial = false
  199. end
  200. end
  201.  
  202. if component.isAvailable("redstone") then
  203. rs = component.redstone
  204. NumberOfRsIOs = 0
  205. for k,v in component.list() do if v == "redstone" then NumberOfRsIOs = NumberOfRsIOs + 1 end end
  206. if NumberOfRsIOs > 1 then
  207. activeErrors = activeErrors + 1
  208. fatalError = true
  209. table.insert(errorsLog, "Too Many Redstone Components Connected to Computer (RedstoneIO, Redstone Card)")
  210. end
  211. else
  212. activeErrors = activeErrors + 1
  213. fatalError = true
  214. table.insert(errorsLog, "No Redstone Component Installed (RedstoneIO or Redstone Card.")
  215. end
  216.  
  217. if component.isAvailable("transportrings") and component.isAvailable("stargate") then
  218. activeErrors = activeErrors + 1
  219. fatalError = true
  220. table.insert(errorsLog, "Multiple types of transport devices detected!")
  221. end
  222.  
  223. if not component.isAvailable("transportrings") and not component.isAvailable("stargate") then
  224. activeErrors = activeErrors + 1
  225. fatalError = true
  226. table.insert(errorsLog, "No Transport Rings or Stargate Connected.")
  227. end
  228.  
  229. if activeErrors > 0 then
  230. term.clear()
  231. if activeErrors >= 2 then print("Multiple Errors Detected:") else print("Error Detected:") end
  232. print()
  233. gpu.setForeground(0xFF0000)
  234. for i, v in ipairs(errorsLog) do
  235. print("Error #" .. i .. " " .. v)
  236. computer.beep()
  237. os.sleep(0.2)
  238. end
  239. for i, v in ipairs(errorsLog) do
  240. table.remove(errorsLog, i)
  241. end
  242. gpu.setForeground(0xFFFFFF)
  243. os.sleep(2)
  244. if fatalError then os.exit(1) end
  245. end
  246.  
  247. -- End of Components and system requirements check ------------------
  248.  
  249. -- Button Objects ---------------------------------------------------
  250. local Button = {}
  251. Button.__index = Button
  252. function Button.new(xPos, yPos, width, height, label, func, border)
  253. local self = setmetatable({}, Button)
  254. if xPos < 1 or xPos > term.window.width then xPos = 1 end
  255. if yPos < 1 or yPos > term.window.height then yPos = 1 end
  256. if (width-2) < unicode.len(label) then width = unicode.len(label)+2 end
  257. if height < 3 then height = 3 end
  258. if border == nil then
  259. self.border = true
  260. else
  261. self.border = border
  262. end
  263. self.xPos = xPos
  264. self.yPos = yPos
  265. self.width = width
  266. self.height = height
  267. self.label = label
  268. self.func = func
  269. self.visible = false
  270. self.disabled = false
  271. return self
  272. end
  273.  
  274. function Button.display(self, x, y)
  275. table.insert(ActiveButtons, 1, self)
  276. if (self.width-2) < unicode.len(self.label) then self.width = unicode.len(self.label)+2 end
  277. if x ~= nil and y ~= nil then
  278. self.xPos = x
  279. self.yPos = y
  280. end
  281. if self.border then
  282. gpu.fill(self.xPos+1, self.yPos, self.width-2, 1, "─")
  283. gpu.fill(self.xPos+1, self.yPos+self.height-1, self.width-2, 1, "─")
  284. gpu.fill(self.xPos, self.yPos+1, 1, self.height-2, "│")
  285. gpu.fill(self.xPos+self.width-1, self.yPos+1, 1, self.height-2, "│")
  286. gpu.set(self.xPos, self.yPos, "┌")
  287. gpu.set(self.xPos+self.width-1, self.yPos, "┐")
  288. gpu.set(self.xPos, self.yPos+self.height-1, "└")
  289. gpu.set(self.xPos+self.width-1, self.yPos+self.height-1, "┘")
  290. end
  291. gpu.set(self.xPos+1, self.yPos+1, self.label)
  292. self.visible = true
  293. end
  294.  
  295. function Button.hide(self)
  296. self.visible = false
  297. for i,v in ipairs(ActiveButtons) do
  298. if v == self then table.remove(ActiveButtons, i) end
  299. end
  300. if self.border then
  301. gpu.fill(self.xPos, self.yPos, self.width, self.height, " ")
  302. else
  303. gpu.fill(self.xPos+1, self.yPos+1, self.width-2, 1, " ")
  304. end
  305. end
  306.  
  307. function Button.disable(self, bool)
  308. if bool == nil then
  309. self.disabled = false
  310. else
  311. self.disabled = bool
  312. end
  313. if self.disabled then gpu.setForeground(0x0F0F0F) end
  314. if self.visible then self:display() end
  315. gpu.setForeground(0xFFFFFF)
  316. end
  317.  
  318. function Button.touch(self, x, y)
  319. local wasTouched = false
  320. if self.visible and not self.disabled then
  321. if self.border then
  322. 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
  323. else
  324. 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
  325. end
  326. end
  327. if wasTouched then
  328. gpu.setBackground(0x878787)
  329. gpu.set(self.xPos+1, self.yPos+1, self.label)
  330. gpu.setBackground(0x000000)
  331. if self.visible then gpu.set(self.xPos+1, self.yPos+1, self.label) end
  332. self.func()
  333. end
  334. return wasTouched
  335. end
  336.  
  337. function Button.forceTouch(self)
  338. self:touch(self.xPos+1, self.yPos+1)
  339. end
  340.  
  341. -- End of Button Objects --------------------------------------------
  342.  
  343. -- Common Events ----------------------------------------------------
  344.  
  345. eventInterrupted = event.listen("interrupted", function()
  346. forceStop = true
  347. end)
  348.  
  349. Event_touch = event.listen("touch", function(_, screenAddress, x, y, button, playerName)
  350. local success, msg = xpcall(function()
  351. if button == 0 then
  352. for i,v in ipairs(ActiveButtons) do
  353. if v:touch(x,y) then break end
  354. end
  355. end
  356. end, debug.traceback)
  357. if not success then
  358. ErrorMessage = msg
  359. mainloop = false
  360. end
  361. end)
  362. -- eventy na tlačitka
  363.  
  364. -- End of Common Events --------------------------------------------
  365.  
  366. -- Buttons ----------------------------------------------------------
  367. if component.isAvailable("stargate") then if stargate.getIrisType() ~= "NULL" then butY = 20 else butY = 23 end else butY = 20 end
  368.  
  369. buttons = {
  370. toggleIrisButton = Button.new(58, 23, 15, 3, " Toogle Iris ", function()
  371. computer.beep()
  372. stargate.toggleIris()
  373. if intruderDetector then intruderDetector = false end
  374. end),
  375.  
  376. toggleShieldButton = Button.new(58, 23, 15, 3, "Toogle Shield", function()
  377. computer.beep()
  378. stargate.toggleIris()
  379. if intruderDetector then intruderDetector = false end
  380. end),
  381.  
  382. mainButton = Button.new(58, 26, 15, 3, " Press Me... ", function()
  383. computer.beep()
  384. wasPressed = true
  385. end),
  386.  
  387. abortButton = Button.new(58, butY, 15, 3, "Abort Dialing", function()
  388. computer.beep()
  389. stargate.abortDialing()
  390. dial = false
  391. dialingFailed = true
  392. cancelStargateEvents()
  393. end),}
  394.  
  395. -- End of Buttons ---------------------------------------------------
  396.  
  397. -- Functions --------------------------------------------------------
  398.  
  399. ---- Common functions ----------------------------------------------
  400. local function checkThisTableContent(subject, minLenght, maxLenght, shortError, longError)
  401. gpu.setForeground(0xFF0000)
  402. for i, v in ipairs(subject) do testedValue = i end
  403. if testedValue <= minLenght then print(shortError)
  404. elseif testedValue > maxLenght then print(longError)
  405. end
  406. gpu.setForeground(0xFFFFFF)
  407. end
  408.  
  409. local function errorMessagenger(errorMessage)
  410. gpu.setForeground(0xFF0000)
  411. print(errorMessage)
  412. computer.beep()
  413. gpu.setForeground(0xFFFFFF)
  414. end
  415.  
  416. local function timer(seconds)
  417. seconds = seconds * 10
  418. for i = 0 , seconds do
  419. if forceStop then break end
  420. os.sleep(0.1)
  421. end
  422. end
  423.  
  424. local function gateTimer(countdown)
  425. local countdown = tonumber(countdown)
  426. if countdown <= 0 then
  427. return "00:00"
  428. else
  429. hours = string.format("%02.f", math.floor(countdown/3600))
  430. mins = string.format("%02.f", math.floor(countdown/60 - (hours*60)))
  431. secs = string.format("%02.f", math.floor(countdown - hours*3600 - mins *60))
  432. end
  433. end
  434.  
  435. local function hideAllButtons()
  436. buttons.toggleIrisButton:hide()
  437. buttons.toggleShieldButton:hide()
  438. buttons.mainButton:hide()
  439. buttons.abortButton:hide()
  440. buttons.toggleIrisButton:disable(true)
  441. buttons.toggleShieldButton:disable(true)
  442. buttons.mainButton:disable(true)
  443. buttons.abortButton:disable(true)
  444. end
  445.  
  446. ---- End of Common functions ---------------------------------------
  447.  
  448. ---- Main Screen functions -----------------------------------------
  449.  
  450. logo = [[⢸⠀⡇⠀⢸⠀⡎⠉⠱⠀⠉⢹⠉⠁ ⠀⢸⠉⠉⡆⢸⠉⠉⡆⢸⠉⠉⠀⡎⠉⠱⠀⡎⠉⠱ ⡏⠉⡆⠀⡇⠀⢸⠀⠉⢹⠉⠁⠈⠉⡏⠉⠀⡎⠉⢱⠀⡷⡄⢸
  451. ⡆⠀⢸⠀⡇⠀⢸⠀⡌⠉⢱⠀⠀⢸⠀⠀⠀ ⢸⠉⠉⠀⢸⠉⠫⡀⢸⠉⠉⠀⡌⠉⢱⠀⡌⠉⢱ ⡏⠉⢱⠀⡇⠀⢸⠀⠀⢸⠀⠀⠀⠀⡇⠀⠀⡇⠀⢸⠀⡇⠹⣼
  452. ⠈⠉⠁⠀⠈⠉⠁⠀⠈⠉⠁⠀⠀⠈⠀⠀⠀ ⠈⠀⠀⠀⠈⠀⠀⠁⠈⠉⠉⠀⠈⠉⠁⠀⠈⠉⠁ ⠉⠉⠁⠀⠈⠉⠁⠀⠀⠈⠀⠀⠀⠀⠁⠀⠀⠈⠉⠁⠀⠁⠀⠈ ]]
  453.  
  454. milkywaySubLogo = "⣳⡃⣩⡁⣺⠅⣻⡇⣏⠃⡳⡇⠭⡇⣏⠃ ⢸⠺⢨⢬⠨⢽⢨⣩⢸⣘⠨⢽⢨⢬⢸⢬ ⢸⢹⢘⢮⢠⢷⢨⢬⢨⣩⢘⢮⢐⡯"
  455. pegasusSubLogo = "⡇⡁⡧⡅⣇⡃⠭⡇⡗⠇⠉⡇⡗⠇ ⢸⠺⢨⢬⠨⢽⢨⣩⢸⣘⠨⢽⢨⢬⢸⢬ ⢸⢹⢘⢮⢠⢷⢨⢬⢨⣩⢘⢮⢐⡯"
  456. universeSubLogo = "⠉⡇⡼⡆⣩⡁⣹⡇⡧⡅⣍⡅⡗⠇⡧⡅ ⢸⠺⢨⢬⠨⢽⢨⣩⢸⣘⠨⢽⢨⢬⢸⢬ ⢸⢹⢘⢮⢠⢷⢨⢬⢨⣩⢘⢮⢐⡯"
  457. oriSubLogo = "⡳⡅⣍⡅⣩⡁ ⡥⡅⣍⡅⠭⡇⡼⡆⡗⠇⡇⡁⡳⡅⣍⡅⡥⡅ ⣍⡅⣩⡁⡼⡆⣇⡃⡗⠇ ⢸⢹⢘⢮⢠⢷⢨⢬⢨⣩⢘⢮⢐⡯"
  458. ancientsSubLogo = "⠭⡇⡼⡆⡏⡇⣩⡁⡧⡅⡼⡆⡥⡅⡗⠇ ⡥⡅⣍⡅⠭⡇⡼⡆⡗⠇⡇⡁⡳⡅⣍⡅⡥⡅ ⣍⡅⣩⡁⡼⡆⣇⡃⡗⠇ ⢸⢹⢘⢮⢠⢷⢨⢬⢨⣩⢘⢮⢐⡯"
  459. goauldSubLogo = "⢔⣹⣏⡢⢄⣀⠀⣄⣻⣘⣇⣻⡀ ⢀⡶⣄⡴⠦⠀⡠⡠⡠⡠⡀ ⠐⢶⣶⠖⢖⠄ ⢀⡶⣄⡴⠦ ⢔⣹⣏⡢⢄⣀"
  460.  
  461. local function mainScreen()
  462. gpu.setResolution(72, 28)
  463. term.clear()
  464. term.setCursor(7,2)
  465. print(logo)
  466. print()
  467. end
  468.  
  469. local function operationScreen()
  470. mainScreen()
  471. gpu.setForeground(subColor)
  472. term.setCursor(posX, 5)
  473. print(subLogo)
  474. gpu.setForeground(colorDefault)
  475. term.setCursor(1, 8)
  476. hideAllButtons()
  477. end
  478.  
  479. local function bootingScreen()
  480. mainScreen()
  481. print(changelog)
  482. timer(changelogTimer)
  483. mainScreen()
  484. print(instructions)
  485. timer(infoTime)
  486. end
  487.  
  488. local function closingScreen()
  489. operationScreen()
  490. term.setCursor(32,8)
  491. print("Good bye")
  492. end
  493.  
  494. ---- End of Main Screen functions ----------------------------------
  495.  
  496. ---- Stargate functions---------------------------------------------
  497. local function setupByGateType()
  498. if stargate.getGateType() == "MILKYWAY" then
  499. stargateAddress = stargateAddressMW
  500. PoO = {"Point of Origin"}
  501. subLogo = milkywaySubLogo
  502. subColor = colorRed
  503. posX = 14
  504. if fastDial == false then walterMes = true end
  505. elseif stargate.getGateType() == "PEGASUS" then
  506. stargateAddress = stargateAddressPG
  507. PoO = {"Subido"}
  508. subLogo = pegasusSubLogo
  509. subColor = colorBlue
  510. posX = 14
  511. else
  512. stargateAddress = stargateAddressUNI
  513. PoO = {"G17"}
  514. subLogo = universeSubLogo
  515. subColor = colorGray
  516. posX = 13
  517. end
  518. end
  519.  
  520. local function completeAddress(t1, t2)
  521. for i=1, #t2 do
  522. t1[#t1 + 1] = t2[i]
  523. end
  524. end
  525.  
  526. local function energyLevel()
  527. if type(stargate.getEnergyRequiredToDial(table.unpack(stargateAddress))) == "table" then
  528. if stargate.getEnergyStored() < stargate.getEnergyRequiredToDial(table.unpack(stargateAddress)).open + (stargate.getEnergyRequiredToDial(table.unpack(stargateAddress)).keepAlive * 20 * minOpenTime) then
  529. errorMessagenger("Not Enough Energy to Establish Connection")
  530. energyCancel = true
  531. end
  532. else
  533. if forceDial == false then errorMessagenger("No Stargate Detected on Provided Address") energyCancel = true end
  534. end
  535. end
  536.  
  537. local function IrisCheck()
  538. if stargate.getIrisType() == "NULL" then irisAutoClose = false else
  539. if stargate.getIrisState() == "CLOSED" then stargate.toggleIris() end
  540. end
  541. if stargate.getIrisType() == "SHIELD" then
  542. buttons.toggleShieldButton:display()
  543. buttons.toggleShieldButton:disable(false)
  544. elseif stargate.getIrisType() =="IRIS_TRINIUM" or stargate.getIrisType() =="IRIS_TITANIUM" then
  545. buttons.toggleIrisButton:display()
  546. buttons.toggleIrisButton:disable(false)
  547. end
  548. end
  549.  
  550. local function computerDial(dialed)
  551. glyph = stargateAddress[dialed + 1]
  552. if walterMes == false then
  553. print("Engaging " .. glyph .. "...")
  554. end
  555. stargate.engageSymbol(glyph)
  556. end
  557.  
  558. local function dhdDial(dialed)
  559. for i, v in ipairs(stargateAddress) do
  560. if offWorldActivation or forceStop then break end
  561. glyph = stargateAddress[i]
  562. print("DHD button pressed: "..glyph.."... ")
  563. dhd.pressButton(glyph)
  564. os.sleep(0.6)
  565. end
  566. if offWorldActivation == false or forceStop == false then
  567. os.sleep(1.4)
  568. print("DHD button pressed: Big Red Button... ")
  569. dhd.pressBRB()
  570. rsLockDialed = true
  571. end
  572. end
  573.  
  574. local function IDCsender()
  575. if brokenBroadcastIDC then errorMessagenger("Broadcast IDC Failed: Invalid IDC") sendIDC = false else print("IDC: " .. IDC .. " sent successfully") stargate.sendIrisCode(IDC) end
  576. end
  577.  
  578. ---- End of Stargate functions -------------------------------------
  579.  
  580. ---- Stargate events -----------------------------------------------
  581. local function startStargateEvents()
  582. stargateEventsActive = true
  583.  
  584. openEvent = event.listen("stargate_open", function()
  585. if offWorldActivation == false then
  586. buttons.abortButton:hide()
  587. buttons.abortButton:disable(true)
  588. if walterMes == false then print("Stargate opened successfully") end
  589. rsLockDialed = true
  590. loop = false
  591. end
  592. end)
  593.  
  594. failEvent = event.listen("stargate_failed", function()
  595. if offWorldActivation == false then
  596. dialingFailed = true
  597. if walterMes then print("Chevron " .. encodedChevron .. " will not engage. It won't Lock. Can't Establish Connection") else print("Stargate failed to open") end
  598. if fastDial then errorMessagenger("Make Sure the DHD Contains the Glyph Crystal") timer(2) end
  599. timer(2)
  600. cancelStargateEvents()
  601. end
  602. end)
  603.  
  604. closedEvent = event.listen("stargate_wormhole_closed_fully", function()
  605. if offWorldActivation then print("Conection lost") timer(1) end
  606. rsLockDialed = false
  607. disconnected = true
  608. if stargate.getIrisState() == "CLOSED" then stargate.toggleIris()
  609. if stargate.getIrisType() ~= "SHIELD" then print("Opening IRIS") else print("Turning OFF Shield") end
  610. end
  611. if standBy == false then cancelStargateEvents() end -------------------------------------------------------------------------------------------------------------------------------------------
  612. end)
  613.  
  614. incomingEvent = event.listen("stargate_incoming_wormhole", function()
  615. offWorldActivation = true
  616. loop = false
  617. buttons.abortButton:hide()
  618. buttons.abortButton:disable(true)
  619. if dial then stargate.abortDialing() end
  620. dial = false
  621. if irisAutoClose and stargate.getIrisState() == "OPENED" then stargate.toggleIris() os.sleep(0.2)
  622. if stargate.getIrisType() ~= "SHIELD" then print("Closing IRIS") else print("Turning ON Shield") end
  623. end
  624. end)
  625.  
  626. eventEngaged = event.listen("stargate_spin_chevron_engaged", function(evname, address, caller, num, lock, glyph)
  627. os.sleep(0.5)
  628. if lock then
  629. if walterMes then print("Chevron "..encodedChevron.." Locked") end
  630. stargate.engageGate()
  631. else
  632. if walterMes then print("Chevron "..encodedChevron.. " encoded...") encodedChevron = encodedChevron + 1 end
  633. computerDial(num)
  634. end
  635. end)
  636.  
  637. eventReceiveCode = event.listen("received_code", function(_, _, _, code)
  638. os.sleep(0.5)
  639. if intruderDetector then stargate.sendMessageToIncoming("Intruder Entry Prohibited") else
  640. if irisAutoClose and brokenLocalIDC == false then
  641. if thisIDC == code then
  642. if stargate.getIrisState() == "CLOSED" then stargate.toggleIris() wasOpened = true
  643. 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
  644. else
  645. if stargate.getIrisType() == "SHIELD" then stargate.sendMessageToIncoming("Shield is OFF!") else stargate.sendMessageToIncoming("Iris is Open!") end
  646. end
  647. elseif thisIDC ~= code and stargate.getIrisState() == "CLOSED" then stargate.sendMessageToIncoming("IDC is Incorrect!")
  648. elseif thisIDC ~= code and stargate.getIrisState() == "OPENED" and wasOpened then
  649. 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
  650. stargate.toggleIris()
  651. intruderDetector = true
  652. end
  653. elseif irisAutoClose and brokenLocalIDC then errorMessagenger("Error: IDC Database is Damaged!") stargate.sendMessageToIncoming("Error: Database is Damaged - Your IDC is not Valid!")
  654. end
  655. end
  656. end)
  657. end
  658.  
  659. function cancelStargateEvents()
  660. event.cancel(eventEngaged)
  661. event.cancel(openEvent)
  662. event.cancel(failEvent)
  663. event.cancel(incomingEvent)
  664. event.cancel(closedEvent)
  665. event.cancel(eventReceiveCode)
  666. loop = false
  667. stargateEventsActive = false
  668. end
  669.  
  670. ---- End of Stargate events ----------------------------------------
  671.  
  672. ---- Transport Rings functions -------------------------------------
  673. local function AunisVersionCheck()
  674. local success = pcall(rings.getAunisVersion)
  675. local success1 = pcall(rings.getJSGVersion)
  676. if success or success1 then AunisVersion = "right" else AunisVersion = "legacy" end
  677. end
  678.  
  679. local function setupByRingsType()
  680. ringsAddress = ringsAddressGoauld
  681. ringType = 0
  682. lastSymbol = 5
  683. if ringsTheme == 0 then
  684. --ringsAddress = ringsAddressGoauld ringType = 0 lastSymbol = 5
  685. subLogo = goauldSubLogo
  686. subColor = colorGold
  687. posX = 13
  688. elseif ringsTheme == 1 then
  689. -- ringsAddress = ringsAddressOri ringType = 1 lastSymbol = 5
  690. subLogo = oriSubLogo
  691. subColor = colorLightGray
  692. posX = 11
  693. else
  694. -- ringsAddress = ringsAddressAncients ringType = 2 lastSymbol = ""
  695. subLogo = ancientsSubLogo
  696. subColor = colorLightBlue
  697. posX = 6
  698. end
  699. end
  700.  
  701. local function messageSystem(msg)
  702. if msg ~= "OK" then
  703. local msgString = resultMessages[msg]
  704. if msgString == nil then msgString = msg end
  705. if msg == "ACTIVATED" then
  706. print(msgString)
  707. else
  708. errorMessagenger(msgString)
  709. rsLockDialed = false
  710. ringsFailed = true
  711. end
  712. timer(3)
  713. end
  714. end
  715.  
  716. local function dialRings()
  717. rsLockDialed = true
  718. for i,v in pairs(ringsAddress) do
  719. if forceStop then break end
  720. symbol = ringsAddress[i]
  721. print("Symbol engaged: " .. symbol .. "...")
  722. rings.addSymbolToAddress(ringType, symbol)
  723. os.sleep(0.5)
  724. end
  725. if forceStop == false then
  726. os.sleep(0.5)
  727. local result = rings.addSymbolToAddress(ringType, lastSymbol)
  728. messageSystem(result)
  729. end
  730. end
  731.  
  732. ---- End of Transport Rings functions ------------------------------
  733.  
  734. ---- Transport Rings events ----------------------------------------
  735. local function startRingsEvents()
  736. ringsEventsActive = true
  737. eventTeleportStart = event.listen("transportrings_teleport_start", function(_, address, caller, initiating)
  738. mainRSLoop = false
  739. rsLockDialed = true
  740. end)
  741.  
  742. eventTeleportFinished = event.listen("transportrings_teleport_finished", function(_, address, caller, initiating)
  743. rsLockDialed = false
  744. computer.beep()
  745. end)
  746. end
  747.  
  748. local function cancelRingsEvents()
  749. event.cancel(eventTeleportStart)
  750. event.cancel(eventTeleportFinished)
  751. ringsEventsActive = false
  752. end
  753.  
  754. ---- End of Transport Rings events ---------------------------------
  755.  
  756. -- End of Functions -------------------------------------------------
  757.  
  758. -- Initialization ---------------------------------------------------
  759. hideAllButtons()
  760. bootingScreen()
  761. if component.isAvailable("stargate") then
  762. setupByGateType()
  763. checkThisTableContent(stargateAddress, 5, 8, "Incomplete Stargate Address or No Stargate Address Entered.", "Stargate Address Corrupted")
  764. completeAddress(stargateAddress, PoO)
  765. end
  766. if component.isAvailable("transportrings") then
  767. setupByRingsType()
  768. for i, v in ipairs(ringsAddress)do
  769. print(v)
  770. end
  771. checkThisTableContent(ringsAddress, 3, 5, "Incomplete Rings Address or No Rings Address Entered.", "Rings Address Corrupted")
  772. end
  773.  
  774. -- End of Initialization --------------------------------------------
  775.  
  776. -- Main Loop --------------------------------------------------------
  777. ::Start::
  778. if stargateEventsActive then cancelStargateEvents() end
  779. if ringsEventsActive then cancelRingsEvents() end
  780. operationScreen()
  781. if component.isAvailable("transportrings") then goto Rings end
  782. if first then print("Establishing Communication with Stargate") end
  783. first = false
  784. timer(1)
  785. ---- Stargate Dialing sequence -------------------------------------
  786.  
  787. ------ Loop Declarations ------------------------------------------
  788. loop = false
  789. dial = false
  790. rsLockDialed = false
  791. energyCancel = false
  792. wasOpened = false
  793. wasPressed = false
  794. dialingFailed = false
  795. offWorldActivation = false
  796. intruderDetector = false
  797. mainRSLoop = true
  798. standBy = true
  799. dialed = 0
  800. encodedChevron = 1
  801.  
  802. ------ end of Loop Declarations -----------------------------------
  803.  
  804. ------ Initialization ---------------------------------------------
  805. buttons.toggleIrisButton:hide()
  806. buttons.toggleShieldButton:hide()
  807. buttons.toggleIrisButton:disable(true)
  808. buttons.toggleShieldButton:disable(true)
  809.  
  810. if stargate.dialedAddress == nil then
  811. if stargate.getIrisState() == "OPENED" then stargate.toggleIris() end
  812. startStargateEvents()
  813. offWorldActivation = true
  814. os.sleep(0.1)
  815. goto IncomingLoop
  816. elseif stargate.dialedAddress ~= "[]" and stargate.dialedAddress ~= nil and stargate.getGateStatus() ~= "open" then
  817. stargate.abortDialing()
  818. print("Clearing Stargate Address buffer")
  819. timer(1)
  820. end
  821.  
  822. if stargate.getGateStatus() == "open" then print("Closing Stargate") stargate.disengageGate() timer(1) end
  823.  
  824. if stargate.getGateStatus() ~= "idle" and stargate.getGateType() == "UNIVERSE" then print("Stargate is Restarting...") end
  825. while stargate.getGateStatus() ~= "idle" do os.sleep(0.1) if forceStop then goto CloseProgram end end
  826. if stargate.getGateType() == "UNIVERSE" then timer(4) else timer(1) end
  827. startStargateEvents()
  828.  
  829. ------ End of Initialization --------------------------------------
  830.  
  831. ------ Dialing Programs -------------------------------------------
  832. operationScreen()
  833. IrisCheck()
  834. buttons.mainButton:display()
  835. buttons.mainButton:disable(false)
  836. print("Press Button to Activate Stargate Dialing Sequence")
  837. print()
  838. disconnected = false
  839. wasPressed = false
  840. while mainRSLoop do
  841. if forceStop then goto CloseProgram end
  842. if rs.getInput(rsInput) > 0 or wasPressed then
  843. mainRSLoop = false
  844. wasPressed = false
  845. end
  846. if offWorldActivation then mainRSLoop = false goto IncomingLoop end
  847. os.sleep(0.1)
  848. end
  849.  
  850. energyLevel()
  851. if energyCancel then timer(5) cancelStargateEvents() goto Start end
  852.  
  853. if fastDial then print("Initiate the dialing sequence with DHD") dhdDial(0) dial = true else
  854. if walterMes then print("Input the coordinates and initiate the dialing sequence") else print("Dialing the Stargate") end
  855. buttons.abortButton:display()
  856. buttons.abortButton:disable(false)
  857. computerDial(0)
  858. loop = true
  859. dial = true
  860. while loop do
  861. if forceStop then goto CloseProgram end
  862. if offWorldActivation then loop = false goto IncomingLoop end
  863. os.sleep(0.1)
  864. end
  865. end
  866.  
  867. print()
  868. if dialingFailed then goto Start end
  869. timer(1)
  870. if sendIDC and dialingFailed == false then timer(4) IDCsender() print() computer.beep() else timer(2) end
  871. ------ End of Dialing Programs ------------------------------------
  872.  
  873. ------ Interlock Loops --------------------------------------------
  874. wasPressed = false
  875. if rsLockDialed then
  876. term.setCursor(1, 24)
  877. if gateAutoClose then print("Stargate closes in: ") else print("Press Button to Close Stargate") end
  878. if gateAutoClose == false then
  879. while disconnected == false do
  880. os.sleep(0.1)
  881. if rs.getInput(rsInput) > 0 or wasPressed then
  882. wasPressed = false
  883. break end
  884. if forceStop then goto CloseProgram end
  885. end
  886. else
  887. loopTime = maxOpenTime * 10
  888. stopwatch = maxOpenTime
  889. gateTimer(stopwatch)
  890. clockLoop = 0
  891. term.setCursor(21 ,24)
  892. print(mins.. ":" .. secs)
  893. for i = 0, loopTime do
  894. clockLoop = clockLoop + 1
  895. if clockLoop == 5 then term.setCursor(21 ,24) print(mins.. " " .. secs) elseif clockLoop == 10 then
  896. clockLoop = 0
  897. stopwatch = stopwatch - 1
  898. gateTimer(stopwatch)
  899. term.setCursor(21 ,24)
  900. print(mins.. ":" .. secs)
  901. end
  902. if forceStop then goto CloseProgram end
  903. if rs.getInput(rsInput) > 0 or wasPressed then
  904. wasPressed = false
  905. break end
  906. if disconnected then break end
  907. os.sleep(0.1)
  908. end
  909. end
  910.  
  911. stargate.disengageGate()
  912. print("Closing stargate")
  913.  
  914. timer(1)
  915. if stargate.getGateStatus() ~= "idle" and stargate.getGateType() == "UNIVERSE" then print("Stargate is Restarting...") end
  916. while stargate.getGateStatus() ~= "idle" do os.sleep(0.1) if forceStop then goto CloseProgram end end
  917. cancelStargateEvents()
  918. goto Start
  919. end
  920.  
  921. ::IncomingLoop::
  922.  
  923. if offWorldActivation then operationScreen()
  924. if walterMes then print("Unscheduled Offworld Activation") print() else print("Incoming Wormhole!") print() end
  925. while offWorldActivation do
  926. if forceStop then goto CloseProgram end
  927. if disconnected then break end
  928. os.sleep(0.1)
  929. end
  930. end
  931. cancelStargateEvents()
  932. goto Start
  933.  
  934. ------ End of Interlock Loops -------------------------------------
  935.  
  936. ---- End of Stargate Dialing sequence ------------------------------
  937.  
  938. ---- Transport Rings Dialing sequence ------------------------------
  939. ::Rings::
  940.  
  941. ------ Loop Declarations ------------------------------------------
  942. mainRSLoop = true
  943. rsLockDialed = false
  944. ringsFailed = false
  945.  
  946. ------ End of Loop Declarations -----------------------------------
  947.  
  948. ------ Initialization ---------------------------------------------
  949. AunisVersionCheck()
  950. if AunisVersion == "legacy" then
  951. errorMessagenger("You are using outdated version of Aunis (JSG). This program is not compatible for transport rings control.")
  952. print() print("Supported versions: 4.10.0.1 and newer")
  953. timer(6)
  954. goto CloseProgram
  955. end
  956.  
  957. rings.addSymbolToAddress(ringType, lastSymbol)
  958.  
  959. os.sleep(0.5)
  960. startRingsEvents()
  961.  
  962. ------ End of Initialization --------------------------------------
  963.  
  964. ------ Rings Dialing Program --------------------------------------
  965. buttons.mainButton:display()
  966. buttons.mainButton:disable(false)
  967. print("Press Button to Activate Transport Rings")
  968. print()
  969. timer(1)
  970. wasPressed = false
  971. while mainRSLoop do
  972. if forceStop then goto CloseProgram end
  973. if rs.getInput(rsInput) > 0 or wasPressed then
  974. mainRSLoop = false
  975. wasPressed = false
  976. end
  977. os.sleep(0.1)
  978. end
  979.  
  980. print("Activating Transport Rings Dialing Sequence")
  981. dialRings()
  982.  
  983. ------ End of Rings Dialing program -------------------------------
  984.  
  985. ------ Interlock Loop ---------------------------------------------
  986. while rsLockDialed do
  987. if forceStop then goto CloseProgram end
  988. os.sleep(0.1)
  989. end
  990.  
  991. if ringsFailed == false then
  992. print()
  993. print("Preparing Transport Rings for further operation")
  994. timer(pauseBetweenDials)
  995. end
  996.  
  997. cancelRingsEvents()
  998. goto Start
  999. ------End of Interlock Loop ---------------------------------------
  1000.  
  1001. ---- End of Transport Rings Dialing sequence -----------------------
  1002.  
  1003. -- End of Main Loop -------------------------------------------------
  1004.  
  1005. -- Closing procedure ------------------------------------------------
  1006. ::CloseProgram::
  1007.  
  1008. event.cancel(eventInterrupted)
  1009. event.cancel(Event_touch)
  1010. hideAllButtons()
  1011. if stargateEventsActive then cancelStargateEvents() end
  1012. if ringsEventsActive then cancelRingsEvents() end
  1013. if component.isAvailable("stargate") and dial then stargate.abortDialing() end
  1014. closingScreen()
  1015. os.sleep(2)
  1016. term.clear()
  1017. gpu.setResolution(160, 50)
  1018. -- End of Closing procedure -----------------------------------------
  1019.  
  1020. --[[
  1021.  
  1022. to-do list:
  1023. #0 command na verzi je jiný
  1024. #7 vymazat WIP veci
  1025. #8 installer na verze
  1026. #9 dat to na github
  1027. #10 nahradit if promena == false then za if not promena then
  1028.  
  1029. Bug report:
  1030. #15
  1031.  
  1032. vyřešeny:
  1033.  
  1034. #1 po příchozí díře, failed a not enough energy nedělat restart brány ------ udelat ::skipRestart::
  1035. #3 error DHD tak sleep na 3 sekundy ------ Snad opraveno jinak to vypíná event a to doupravím jindy
  1036. #7 dela zvuk pri vypinani
  1037. #8 nefunguje GUI selector
  1038. #6 nevrati se z loopy po incoming wormhole
  1039. #9 kdyz se brana zavre sama - bez redstonu neukonci se smycka => press button to close stargate
  1040. #5 Iris zprávy a code nefunguje - pro lokalni branu, ale prijmeme vysilani
  1041. #4 Duplicitní zprávy pro failed pouze pro PEG a UNI brany
  1042. #11 Zprávy po vypnutí brány zobrazují se všechny
  1043. #10 nefuguje GUI selector pro ringy -- je ta rignTheme misto ringTheme
  1044. #12 musíš znáčknout tlačítko 2x aby se aktivovali kruhy ----- dlouha pauza - 4s
  1045. #14 nezobrazují se buttony na iris
  1046. #3 tlačítko na terminaci zadavani
  1047. #6 skryte tlačitko button
  1048. #13 nefunguje abort button
  1049.  
  1050. hotovo:
  1051. zapnutí časového vypínání
  1052. nahrazení os.sleep timerem
  1053. test vešerých funkcí na branách
  1054. #4 když časové zamykání tak dát časovač za jak dlouho se zavře
  1055. #11 Prohodit pozice tlačítek abort a IRIS/Shield
  1056.  
  1057.  
  1058. ]]
  1059. -- while not stopMe do os.sleep(0.1) end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement