Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- variables
- -- constants
- local bp = true
- --local pw = "iboom45" -- doesn't make difference if you use lower or uppercase
- local pwu = ""
- local t = 15.0 -- seconds
- local s = 0.0
- local m = 0.0
- local td = 0.1
- local ts = 0.0
- local tf = t
- local data = "data.txt"
- local data_path = ""
- local scrt_path = ""
- -- sides responsible for input & output
- local inp = "bottom"
- local out = "left"
- -- all the sides possible
- local sides = {
- "top",
- "bottom",
- "right",
- "left",
- "front",
- "back"
- }
- -- FUNCTIONS
- -- divider
- local function divider(char)
- term.setTextColor(colors.white)
- local w, h = term.getSize()
- for i=1,w do
- write(char)
- end
- end
- -- checks if the file exists
- local function file_exists(file)
- local f = io.open(file, "rb")
- if f then f:close() end
- return f ~= nil
- end
- -- creates the file
- local function create_file(file)
- local f = io.open(file, "w")
- f:close()
- end
- -- NON FUNZIONA CAZZO, COSA DOVREI USARE???
- -- spits out the file path the script in running in
- local function script_path()
- local str = debug.getinfo(2, "S").source:sub(2)
- return str:match("(.*/)")
- end
- local function get_lines(file)
- local lines = {}
- -- io.lines returns an iterator, so we need to manually unpack it into an array
- for line in io.lines(file) do
- lines[#lines+1] = line
- end
- return lines
- end
- -- MAIN
- -- if a monitor is detected, it redirects the output to that
- local monitor = peripheral.find("monitor")
- if monitor then
- term.redirect(monitor)
- end
- -- does all the scap responsible for the security
- scrt_path = script_path()
- data_path = scrt_path .. data
- -- checks if the file exists in the first place
- print("Checking data file in " .. scrt_path .. "...")
- if not file_exists(data_path) then
- -- if not then it creates it and lets the user pick the new password
- print("The file has not been found")
- print("Creating data file in " .. scrt_path .. "...")
- create_file(data_path)
- print("Created!")
- -- new password input
- term.clear()
- term.setTextColor(colors.white)
- term.setCursorPos(1,1)
- print("MISSILE PASSWORD SELECTOR")
- divider("=")
- print("Insert the new password:")
- write("-> ")
- pwu = read("*")
- local f = io.open(data_path, "w")
- f:write(pwu)
- -- all done
- print("The new password has been selected")
- print("Rebooting...")
- os.reboot()
- else
- -- if it exists it just reads it from it
- print("File has been found")
- print("Reading data...")
- local f = get_lines(data_path)
- pw = f[1]
- end
- f:close()
- print("All done!")
- -- resets all the sides redstone outputs to 0
- for g=1,#sides do
- rs.setOutput(sides[g], false)
- end
- os.sleep(1)
- term.clear()
- -- password
- pw = string.lower(pw)
- while bp do
- term.clear()
- term.setTextColor(colors.white)
- term.setCursorPos(1,1)
- print("MISSILE SEQUENCE VERIFIER")
- divider("=")
- print("Insert the password:")
- write("-> ")
- pwu = read("*")
- if string.lower(pwu) == pw then
- bp = false
- term.setTextColor(colors.lime)
- print("CORRECT PASSWORD, YOU MAY PROCEED")
- os.sleep(3)
- else
- term.setTextColor(colors.red)
- local x, y = term.getCursorPos()
- for i=5,0,-1 do
- term.setCursorPos(x, y)
- print("INCORRECT PASSWORD, PLEASE RETRY IN: " .. i .. "s")
- os.sleep(1)
- end
- end
- end
- -- checks for an input on the said side, if it does it lets that side powered
- term.clear()
- term.setTextColor(colors.white)
- term.setCursorPos(1,1)
- print("WAITING FOR SIGNAL")
- divider("=")
- while not rs.getInput(inp) do
- os.sleep(0.02)
- end
- rs.setOutput(inp, true)
- -- timer
- term.clear()
- term.setCursorPos(1,2)
- divider("=")
- -- loop
- for g=t,0.0,-td do
- term.setCursorPos(1,1)
- -- color for the main text
- if tf-g > 0.5 then
- tf = g
- term.setTextColor(colors.red)
- else
- term.setTextColor(colors.yellow)
- end
- print("MISSILE LAUNCH SISTEM")
- -- real timer
- term.setCursorPos(1,3)
- write("-> ")
- ts = g/t
- if ts > 0.5 then
- term.setTextColor(colors.lime)
- elseif ts > 0.2 and ts < 0.5 then
- term.setTextColor(colors.yellow)
- else
- term.setTextColor(colors.red)
- end
- s = g
- m = s / 60
- s = math.floor(s % 60)
- m = math.floor(m % 60)
- write(m .. ":" .. s .. "." .. math.floor((g-math.floor(g))*10) .. " ")
- print()
- os.sleep(td)
- end
- term.setTextColor(colors.white)
- -- final output
- rs.setOutput(out, true)
- divider("=")
- print("MISSILE LAUNCHED")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement