Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- Reactor Control
- Written by TheShadow989
- ]]--
- local reactorTitle = "Reactor #1" -- Terminal Title
- local sides = {"top", "bottom", "left", "right", "front", "back"}
- local _drive= ""
- local _secLevel = -1 -- Card Level Access (1 - Lowest and 5 = highest)
- --[[
- Card Passwords
- Level 1: 5BCE0FE268FA6B4B801FB1082F185B90000AB1258202C653F64B4F037D172336
- Level 2: 9EA9B8889DE45FA608597CB52B79749E2E32C97EF6481CFE6B315655933331F8
- Level 3: 387B8E8247FE18FFFA39FA2DFCDFB555633A0585B6F7D781FFCDA8E82AA20232
- Level 4: 51B92A735030BDBF16100656E55D9F98D0CACA269266782E2F3E850894898BEE
- Level 5: 7B48A89633F05F625E007F3287CD3858584503B9972578791D321851C9D44E51
- Insert a floppy disk into the computer and enter this command 'edit disk/password' and paste one the strings above inside the disk.
- ]]--
- local _passwords = {"5BCE0FE268FA6B4B801FB1082F185B90000AB1258202C653F64B4F037D172336", "9EA9B8889DE45FA608597CB52B79749E2E32C97EF6481CFE6B315655933331F8", "387B8E8247FE18FFFA39FA2DFCDFB555633A0585B6F7D781FFCDA8E82AA20232", "51B92A735030BDBF16100656E55D9F98D0CACA269266782E2F3E850894898BEE", "7B48A89633F05F625E007F3287CD3858584503B9972578791D321851C9D44E51"}
- -- Reactor menu options
- local menu_options =
- {
- [1] = {menuOption="Reactor:", option1=" ON ", option2=" OFF ", yPos=8, option1xPos=22, option2xPos=31, selected=2, access=4},
- [2] = {menuOption="Lights:", option1=" ON ", option2=" OFF ", yPos=9, option1xPos=22, option2xPos=31, selected=2, access=2},
- [3] = {menuOption="Info Displays:", option1=" ON ", option2=" OFF ", yPos=10, option1xPos=22, option2xPos=31, selected=2, access=3},
- [4] = {menuOption="Emerg. Flood:", option1=" ON ", option2=" OFF ", yPos=11, option1xPos=22, option2xPos=31, selected=2, access=1},
- [5] = {menuOption="Access Doors:", option1=" OPEN ", option2="CLOSED", yPos=12, option1xPos=22, option2xPos=31, selected=2, access=4},
- [6] = {menuOption="", option1="Emergency Shutdown", option2="", yPos=16, option1xPos=17, option2xPos=0, selected=0, access=-1},
- [7] = {menuOption="", option1="Logout", option2="", yPos=19, option1xPos=1, option2xPos=0, selected=2, access=1},
- }
- --Find Drive Side
- for i=1, #sides do
- if peripheral.isPresent(sides[i]) then
- if peripheral.getType(sides[i]) == "drive" then
- _drive = sides[i]
- end
- end
- end
- --------------------------------------------------------------------------
- -- Center Terminal Text Function
- --------------------------------------------------------------------------
- local function centerTermialText(text, xcor, ycor)
- term.setCursorPos(xcor,ycor)
- local x,y = term.getSize()
- local x2,y2 = term.getCursorPos()
- term.setCursorPos(math.ceil((x / 2) - (text:len() / 2)), y2)
- term.setBackgroundColor(colors.black)
- write(text)
- end
- --------------------------------------------------------------------------
- -- Draw Selection Menu Function
- --------------------------------------------------------------------------
- local function drawSelectMenu()
- centerTermialText(reactorTitle, 1, 3)
- for index, data in pairs(menu_options) do
- if _secLevel >= data.access then
- term.setCursorPos(data.option1xPos-2-data.menuOption:len(), data.yPos)
- term.setBackgroundColor(colors.black)
- term.write(data.menuOption)
- term.setCursorPos(data.option1xPos, data.yPos)
- if data.selected == 1 then
- term.setBackgroundColor(colors.green)
- elseif data.selected == 0 then
- term.setBackgroundColor(colors.red)
- else
- term.setBackgroundColor(colors.gray)
- end
- term.write(data.option1)
- term.setCursorPos(data.option2xPos, data.yPos)
- if data.selected == 2 then
- term.setBackgroundColor(colors.red)
- elseif data.selected == 0 then
- term.setBackgroundColor(colors.red)
- else
- term.setBackgroundColor(colors.gray)
- end
- term.write(data.option2)
- end
- end
- term.setCursorPos(0,0)
- term.setBackgroundColor(colors.black)
- end
- --------------------------------------------------------------------------
- -- Disk Message Function
- --------------------------------------------------------------------------
- local function diskMessage(text)
- centerTermialText(reactorTitle, 1, 3)
- centerTermialText("======================================", 1, 9)
- centerTermialText(text, 1, 10)
- centerTermialText("======================================", 1, 11)
- end
- --------------------------------------------------------------------------
- -- Check Click Function
- --------------------------------------------------------------------------
- local function checkClick(x,y)
- for index, data in pairs(menu_options) do
- if _secLevel >= data.access then
- if x >= data.option1xPos and x < data.option1:len() + data.option1xPos and y == data.yPos then
- if data.selected ~= 0 then
- return index, 1
- else
- return index, 0
- end
- end
- if x >= data.option2xPos and x < data.option2:len() + data.option2xPos and y == data.yPos then
- if data.selected ~= 0 then
- return index, 2
- else
- return index, 0
- end
- end
- end
- end
- return false, false
- end
- -- Clear Screen
- term.clear()
- -- Show Disk Message
- diskMessage("Please insert keycard to use termial")
- drawSelectMenu()
- --------------------------------------------------------------------------
- -- LOOP
- --------------------------------------------------------------------------
- while true do
- local e = {os.pullEvent()}
- local indexSelected, optionSelected = "", ""
- if e[1] == "disk" then
- if _secLevel == -1 then
- if fs.exists("disk/password") then
- local file = fs.open("disk/password","r")
- data = file.readLine()
- file.close()
- for i=1, #_passwords do
- if data == _passwords[i] then
- _secLevel = i
- end
- end
- else
- term.clear()
- diskMessage("Unformatted keycard inserted")
- drawSelectMenu()
- end
- end
- end
- if e[1] == "mouse_click" then
- indexSelected, optionSelected = checkClick(e[3], e[4]) --Check the mouse click
- if indexSelected ~= false and optionSelected ~= false then
- menu_options[indexSelected].selected = optionSelected
- end
- end
- -- Put button actions below
- if indexSelected == 6 and optionSelected == 0 then -- Emergency Shutdown
- -- Turn Reactor OFF
- menu_options[1].selected = 2
- redstone.setBundledOutput("back",colors.subtract(redstone.getBundledOutput("back"), colors.red))
- -- Turn Lights ON
- menu_options[2].selected = 1
- redstone.setBundledOutput("back",colors.combine(redstone.getBundledOutput("back"),colors.purple))
- -- Turn Info Display ON
- menu_options[3].selected = 1
- redstone.setBundledOutput("back",colors.combine(redstone.getBundledOutput("back"),colors.black))
- -- Turn Emergency Flood ON
- menu_options[4].selected = 1
- redstone.setBundledOutput("back",colors.combine(redstone.getBundledOutput("back"),colors.orange))
- -- Close Access Door
- menu_options[5].selected = 2
- redstone.setBundledOutput("back",colors.subtract(redstone.getBundledOutput("back"), colors.yellow))
- elseif indexSelected == 1 and optionSelected == 1 then -- Reactor On
- redstone.setBundledOutput("back",colors.combine(redstone.getBundledOutput("back"),colors.red))
- elseif indexSelected == 1 and optionSelected == 2 then -- Reactor Off
- redstone.setBundledOutput("back",colors.subtract(redstone.getBundledOutput("back"), colors.red))
- elseif indexSelected == 2 and optionSelected == 1 then -- Lights On
- redstone.setBundledOutput("back",colors.combine(redstone.getBundledOutput("back"),colors.purple))
- elseif indexSelected == 2 and optionSelected == 2 then -- Lights Off
- redstone.setBundledOutput("back",colors.subtract(redstone.getBundledOutput("back"), colors.purple))
- elseif indexSelected == 3 and optionSelected == 1 then -- Info Displays ON
- redstone.setBundledOutput("back",colors.combine(redstone.getBundledOutput("back"),colors.black))
- elseif indexSelected == 3 and optionSelected == 2 then -- Info Displays OFF
- redstone.setBundledOutput("back",colors.subtract(redstone.getBundledOutput("back"), colors.black))
- elseif indexSelected == 4 and optionSelected == 1 then -- Emergency Flood ON
- redstone.setBundledOutput("back",colors.combine(redstone.getBundledOutput("back"),colors.orange))
- elseif indexSelected == 4 and optionSelected == 2 then -- Emergency Flood OFF
- redstone.setBundledOutput("back",colors.subtract(redstone.getBundledOutput("back"), colors.orange))
- elseif indexSelected == 5 and optionSelected == 1 then -- Access Doors On
- redstone.setBundledOutput("back",colors.combine(redstone.getBundledOutput("back"),colors.yellow))
- elseif indexSelected == 5 and optionSelected == 2 then -- Access Doors Off
- redstone.setBundledOutput("back",colors.subtract(redstone.getBundledOutput("back"), colors.yellow))
- elseif indexSelected == 7 and optionSelected == 1 then -- Logout
- menu_options[7].selected = 2
- peripheral.call(_drive, "ejectDisk")
- end
- if _secLevel ~= -1 then
- term.clear()
- drawSelectMenu()
- end
- if e[1] == "disk_eject" then
- term.clear()
- _secLevel = -1
- diskMessage("Please insert keycard to use termial")
- drawSelectMenu()
- end
- end
Add Comment
Please, Sign In to add comment