Advertisement
Guest User

Adv. Password Protected Door for Computer Craft

a guest
Dec 16th, 2012
340
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.20 KB | None | 0 0
  1. os.pullEvent = os.pullEventRaw -- Makes it so that a hacker can't shut down your program by holding Ctrl + T.
  2.  
  3. function clear() -- Creating a function that will clear the screen and reset the cursor.
  4.  term.setCursorPos(1,1)
  5.  term.clear()
  6. end
  7.  
  8. clear()
  9.  
  10. local password -- Defines a string containing the password to be used in the door.
  11. local termPass -- Defines a string containing the password needed to shutdown the program.
  12. local openTime -- Defines an integer to be used to set how long the door will be open.
  13. local availibleSides = {"top, ", "bottom, ", "left, ", "right, ", "front, ", "back", "\n"} -- Defines a table.
  14. local redstoneOutputSide -- Defines a string to be used to set the output of a redstone signal.
  15. local userInput -- Defines a string to be used with read().
  16.  
  17. print("Please define your desired password:") -- Prints the string defined by the quote marks.
  18. password = read() --Setting the password string as whatever the user inputs.
  19. clear() -- Calling the function I made.
  20.  
  21. print("Please define the password to be used to shut down the program.") -- Already explained.
  22. termPass = read() -- Already explained.
  23. clear() -- Already explained.
  24.  
  25. print("Please define the amount of time the redstone pulse will be activated:") -- Already explained.
  26. openTime = tonumber(read()) -- Already explained.
  27. clear() -- Already explained.
  28.  
  29. print("On which side will the redstone be activated?") -- Already explained.
  30. print("Availbe sides are:") -- Already explained.
  31. for i = 1, 7 do -- Loops through my tables and prints everything in it.
  32.  write(availibleSides[i])
  33. end
  34. print("Please define a side:")
  35. redstoneOutputSide = read() -- Already explained.
  36. clear() -- Already explained.
  37.  
  38. while true do -- The actual password door.
  39.  clear()
  40.  write("Please input password: ")
  41.  userInput = read("*")
  42.  if userInput == password then
  43.   clear()
  44.   print("Password is correct! Opening door...")
  45.   rs.setOutput(redstoneOutputSide, true)
  46.   sleep(openTime)
  47.   rs.setOutput(redstoneOutputSide, false)
  48.  elseif userInput == termPass then
  49.   print("Shutting down computer, please wait...")
  50.   sleep(2) -- Waits.
  51.   os.shutdown()
  52.  else
  53.   print("Password is incorrect! Rebooting program...")
  54.   sleep(2) -- Waits.
  55.  end
  56. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement