Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Variables are being defined here
- password = "password" -- This is the password variable
- side = "back" -- This is the redstone output side, in this case the back
- lockDown = 60 -- If the password is wrong the computer will lock down for 60 seconds
- count = 2 -- This number checks how many times you can try entering a password.
- -- Clear the screen
- os.pullEvent = os.pullEventRaw
- term.clear() -- Clear screen
- term.setCursorPos(1, 1) --Reset cursor
- -- Prints text to the screen
- print("Enter the password to open the door.")
- var1 = read("*") -- This defines var1 as whatever the user types on the screen. The * means that every character will be replaced with a * to ensure nobody can read the pass while you are typing it.
- sleep(0.5)
- -- Lockdown check starts here
- while true do -- This is a loop and will run continuously.
- if count <= 0 then -- Checks how many tries are left. <= means smaller than or equal to.
- print("Lockdown activated. Program will be inaccessible for: 1 minute(s).")
- for i = 1, 60 do -- Here's another loop. This will repeat the code below 60 times.
- print("Lockdown will disable in: ", lockDown, " seconds.") -- Prints the remaining time
- sleep(1) -- Wait one second
- lockDown = lockDown - 1 -- Subtract one second from the time
- term.clear() -- Clear the screen so it isn't filled with text
- term.setCursorPos(1, 1) -- idem
- end
- lockDown = 60 -- Resets the value
- break -- Loop ends here
- end -- and here
- -- Password check starts here
- if var1 ~= password then -- Check if user input DOES NOT match password
- print("Incorrect password.")
- term.clearLine()
- print(count, " attempt(s) remaining.") -- Print remaining attempts
- count = count - 1 -- Subtract 1 from the attempt.
- var1 = read("*") -- Again, accept user input
- elseif var1 == "@quit" then --If you enter a certain code the program will stop.
- break
- elseif var1 == password then -- If user input MATCHES password
- print("Enter the amount of seconds you want the door to stay open. Maximum is 20, minimum is 1.")
- varTime = read() --User input
- varTime = tonumber(varTime) -- Writes user input to value.
- if tonumber(varTime) ~= nil then -- check if user actually inputted something
- if varTime < 1 then -- Smaller than one is not allowed.
- print("Minimum is 1 second.")
- return -- Return to the user input
- elseif varTime > 20 then -- Bigger than 20 seconds isn't allowed either
- print("Maximum is 20 seconds.")
- return -- Back to input again
- elseif varTime >= 1 and varTime <= 20 then -- If input is between 1 and 20, proceed
- print("Door will open. Please leave the console.")
- rs.setOutput(side, true) -- Turns on the output on the side, "back" as defined above.
- sleep(varTime) -- The program waits for the time specified earlier, between 1 and 20 seconds.
- rs.setOutput(side, false) -- Turns redstone off again
- break --Loop
- end -- Ends
- end -- Here
- end -- Password check ends here
- sleep(0.5)
- end
- term.clear() -- Clear the screen
- term.setCursorPos(1, 1) -- Reset cursor position
- os.reboot() -- Restart the system. In my case I put this program in the startup file so on reboot this program would restart.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement