Theshadow989

[Keycard] Reactor Control

Aug 28th, 2021 (edited)
2,160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 9.11 KB | None | 0 0
  1. --[[
  2. Reactor Control
  3. Written by TheShadow989
  4. ]]--
  5.  
  6. local reactorTitle = "Reactor #1" -- Terminal Title
  7. local sides = {"top", "bottom", "left", "right", "front", "back"}
  8. local _drive= ""
  9. local _secLevel = -1 -- Card Level Access (1 - Lowest and 5 = highest)
  10.  
  11. --[[
  12. Card Passwords
  13. Level 1: 5BCE0FE268FA6B4B801FB1082F185B90000AB1258202C653F64B4F037D172336
  14. Level 2: 9EA9B8889DE45FA608597CB52B79749E2E32C97EF6481CFE6B315655933331F8
  15. Level 3: 387B8E8247FE18FFFA39FA2DFCDFB555633A0585B6F7D781FFCDA8E82AA20232
  16. Level 4: 51B92A735030BDBF16100656E55D9F98D0CACA269266782E2F3E850894898BEE
  17. Level 5: 7B48A89633F05F625E007F3287CD3858584503B9972578791D321851C9D44E51
  18.  
  19. Insert a floppy disk into the computer and enter this command 'edit disk/password' and paste one the strings above inside the disk.
  20. ]]--
  21. local _passwords = {"5BCE0FE268FA6B4B801FB1082F185B90000AB1258202C653F64B4F037D172336", "9EA9B8889DE45FA608597CB52B79749E2E32C97EF6481CFE6B315655933331F8", "387B8E8247FE18FFFA39FA2DFCDFB555633A0585B6F7D781FFCDA8E82AA20232", "51B92A735030BDBF16100656E55D9F98D0CACA269266782E2F3E850894898BEE", "7B48A89633F05F625E007F3287CD3858584503B9972578791D321851C9D44E51"}
  22.  
  23. -- Reactor menu options
  24. local menu_options =
  25. {
  26.     [1] = {menuOption="Reactor:", option1="  ON  ", option2="  OFF ", yPos=8, option1xPos=22, option2xPos=31, selected=2, access=4},
  27.     [2] = {menuOption="Lights:", option1="  ON  ", option2="  OFF ", yPos=9, option1xPos=22, option2xPos=31, selected=2, access=2},
  28.     [3] = {menuOption="Info Displays:", option1="  ON  ", option2="  OFF ", yPos=10, option1xPos=22, option2xPos=31, selected=2, access=3},
  29.     [4] = {menuOption="Emerg. Flood:", option1="  ON  ", option2="  OFF ", yPos=11, option1xPos=22, option2xPos=31, selected=2, access=1},
  30.     [5] = {menuOption="Access Doors:", option1=" OPEN ", option2="CLOSED", yPos=12, option1xPos=22, option2xPos=31, selected=2, access=4},
  31.     [6] = {menuOption="", option1="Emergency Shutdown", option2="", yPos=16, option1xPos=17, option2xPos=0, selected=0, access=-1},
  32.     [7] = {menuOption="", option1="Logout", option2="", yPos=19, option1xPos=1, option2xPos=0, selected=2, access=1},
  33. }
  34.  
  35. --Find Drive Side
  36. for i=1, #sides do
  37.     if peripheral.isPresent(sides[i]) then
  38.         if peripheral.getType(sides[i]) == "drive" then
  39.             _drive = sides[i]
  40.         end
  41.     end
  42. end
  43.  
  44. --------------------------------------------------------------------------
  45. --  Center Terminal Text Function
  46. --------------------------------------------------------------------------
  47. local function centerTermialText(text, xcor, ycor)
  48.     term.setCursorPos(xcor,ycor)
  49.     local x,y = term.getSize()
  50.     local x2,y2 = term.getCursorPos()
  51.     term.setCursorPos(math.ceil((x / 2) - (text:len() / 2)), y2)
  52.     term.setBackgroundColor(colors.black)
  53.     write(text)
  54. end
  55.  
  56. --------------------------------------------------------------------------
  57. --  Draw Selection Menu Function
  58. --------------------------------------------------------------------------
  59. local function drawSelectMenu()
  60.     centerTermialText(reactorTitle, 1, 3)
  61.  
  62.     for index, data in pairs(menu_options) do
  63.         if _secLevel >= data.access then
  64.             term.setCursorPos(data.option1xPos-2-data.menuOption:len(), data.yPos)
  65.             term.setBackgroundColor(colors.black)
  66.             term.write(data.menuOption)
  67.  
  68.             term.setCursorPos(data.option1xPos, data.yPos)
  69.             if data.selected == 1 then
  70.                 term.setBackgroundColor(colors.green)
  71.             elseif data.selected == 0 then
  72.                 term.setBackgroundColor(colors.red)
  73.             else
  74.                 term.setBackgroundColor(colors.gray)
  75.             end
  76.             term.write(data.option1)
  77.  
  78.             term.setCursorPos(data.option2xPos, data.yPos)
  79.             if data.selected == 2 then
  80.                 term.setBackgroundColor(colors.red)
  81.             elseif data.selected == 0 then
  82.                 term.setBackgroundColor(colors.red)
  83.             else
  84.                 term.setBackgroundColor(colors.gray)
  85.             end
  86.             term.write(data.option2)
  87.         end
  88.     end
  89.    
  90.     term.setCursorPos(0,0)
  91.     term.setBackgroundColor(colors.black)
  92. end
  93.  
  94. --------------------------------------------------------------------------
  95. --  Disk Message Function
  96. --------------------------------------------------------------------------
  97. local function diskMessage(text)
  98.     centerTermialText(reactorTitle, 1, 3)
  99.    
  100.     centerTermialText("======================================", 1, 9)
  101.     centerTermialText(text, 1, 10)
  102.     centerTermialText("======================================", 1, 11)
  103. end
  104.  
  105. --------------------------------------------------------------------------
  106. --  Check Click Function
  107. --------------------------------------------------------------------------
  108. local function checkClick(x,y)
  109.     for index, data in pairs(menu_options) do
  110.         if _secLevel >= data.access then
  111.             if x >= data.option1xPos and x < data.option1:len() + data.option1xPos and y == data.yPos then
  112.                 if data.selected ~= 0 then
  113.                     return index, 1
  114.                 else
  115.                     return index, 0
  116.                 end
  117.             end
  118.  
  119.             if x >= data.option2xPos and x < data.option2:len() + data.option2xPos and y == data.yPos then
  120.                 if data.selected ~= 0 then
  121.                     return index, 2
  122.                 else
  123.                     return index, 0
  124.                 end
  125.             end
  126.         end
  127.     end
  128.     return false, false
  129. end
  130.  
  131. -- Clear Screen
  132. term.clear()
  133.  
  134. -- Show Disk Message
  135. diskMessage("Please insert keycard to use termial")
  136. drawSelectMenu()
  137.  
  138. --------------------------------------------------------------------------
  139. --  LOOP
  140. --------------------------------------------------------------------------
  141.  
  142. while true do
  143.     local e = {os.pullEvent()}
  144.     local indexSelected, optionSelected = "", ""
  145.    
  146.     if e[1] == "disk" then
  147.         if _secLevel == -1 then
  148.             if fs.exists("disk/password") then
  149.                 local file = fs.open("disk/password","r")  
  150.                 data = file.readLine()                  
  151.                 file.close()
  152.                 for i=1, #_passwords do
  153.                     if data == _passwords[i] then
  154.                         _secLevel = i
  155.                     end
  156.                 end
  157.             else
  158.                 term.clear()
  159.                 diskMessage("Unformatted keycard inserted")
  160.                 drawSelectMenu()
  161.             end
  162.         end
  163.     end
  164.  
  165.     if e[1] == "mouse_click" then
  166.         indexSelected, optionSelected = checkClick(e[3], e[4]) --Check the mouse click
  167.  
  168.         if indexSelected ~= false and optionSelected ~= false then
  169.             menu_options[indexSelected].selected = optionSelected
  170.         end
  171.     end
  172.    
  173.     -- Put button actions below
  174.     if indexSelected == 6 and optionSelected == 0 then -- Emergency Shutdown
  175.         -- Turn Reactor OFF
  176.         menu_options[1].selected = 2
  177.         redstone.setBundledOutput("back",colors.subtract(redstone.getBundledOutput("back"), colors.red))
  178.         -- Turn Lights ON
  179.         menu_options[2].selected = 1
  180.         redstone.setBundledOutput("back",colors.combine(redstone.getBundledOutput("back"),colors.purple))
  181.         -- Turn Info Display ON
  182.         menu_options[3].selected = 1
  183.         redstone.setBundledOutput("back",colors.combine(redstone.getBundledOutput("back"),colors.black))
  184.         -- Turn Emergency Flood ON
  185.         menu_options[4].selected = 1
  186.         redstone.setBundledOutput("back",colors.combine(redstone.getBundledOutput("back"),colors.orange))
  187.         -- Close Access Door
  188.         menu_options[5].selected = 2
  189.         redstone.setBundledOutput("back",colors.subtract(redstone.getBundledOutput("back"), colors.yellow))
  190.     elseif indexSelected == 1 and optionSelected == 1 then -- Reactor On
  191.         redstone.setBundledOutput("back",colors.combine(redstone.getBundledOutput("back"),colors.red))
  192.     elseif indexSelected == 1 and optionSelected == 2 then -- Reactor Off
  193.         redstone.setBundledOutput("back",colors.subtract(redstone.getBundledOutput("back"), colors.red))
  194.     elseif indexSelected == 2 and optionSelected == 1 then -- Lights On
  195.         redstone.setBundledOutput("back",colors.combine(redstone.getBundledOutput("back"),colors.purple))
  196.     elseif indexSelected == 2 and optionSelected == 2 then -- Lights Off
  197.         redstone.setBundledOutput("back",colors.subtract(redstone.getBundledOutput("back"), colors.purple))
  198.     elseif indexSelected == 3 and optionSelected == 1 then -- Info Displays ON
  199.         redstone.setBundledOutput("back",colors.combine(redstone.getBundledOutput("back"),colors.black))
  200.     elseif indexSelected == 3 and optionSelected == 2 then -- Info Displays OFF
  201.         redstone.setBundledOutput("back",colors.subtract(redstone.getBundledOutput("back"), colors.black))
  202.     elseif indexSelected == 4 and optionSelected == 1 then -- Emergency Flood ON
  203.         redstone.setBundledOutput("back",colors.combine(redstone.getBundledOutput("back"),colors.orange))
  204.     elseif indexSelected == 4 and optionSelected == 2 then -- Emergency Flood OFF
  205.         redstone.setBundledOutput("back",colors.subtract(redstone.getBundledOutput("back"), colors.orange))
  206.     elseif indexSelected == 5 and optionSelected == 1 then -- Access Doors On
  207.         redstone.setBundledOutput("back",colors.combine(redstone.getBundledOutput("back"),colors.yellow))
  208.     elseif indexSelected == 5 and optionSelected == 2 then -- Access Doors Off
  209.         redstone.setBundledOutput("back",colors.subtract(redstone.getBundledOutput("back"), colors.yellow))
  210.     elseif indexSelected == 7 and optionSelected == 1 then -- Logout
  211.         menu_options[7].selected = 2
  212.         peripheral.call(_drive, "ejectDisk")
  213.     end
  214.    
  215.     if _secLevel ~= -1 then
  216.         term.clear()
  217.         drawSelectMenu()
  218.     end
  219.    
  220.     if e[1] == "disk_eject" then
  221.         term.clear()
  222.         _secLevel = -1
  223.         diskMessage("Please insert keycard to use termial")
  224.         drawSelectMenu()
  225.     end
  226. end
Add Comment
Please, Sign In to add comment