Advertisement
Guest User

PIN Program w/ MOTD

a guest
Apr 19th, 2015
279
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1. #!/bin/lua
  2.  
  3. --[[
  4. Credit to the following people on the IRC room:
  5. Kodos
  6. NotLyra
  7. Sandra
  8. As well as the following tools:
  9. Pastebin
  10. I would not be able to make this program without them. I,
  11. Ekoserin, am a Lua noob and I'm proud!
  12. I'm a Lua noob and I'm proud!
  13. I'm a Lua noob and I'm proud!
  14. --]]
  15.  
  16. local component = require("component") -- We need components.
  17. local computer = require("computer") -- We need the computer, obviously.
  18. local text = require("text") -- We need text displaying.
  19. local unicode = require("unicode") -- To display text, we need Unicode.
  20. local term = require("term") -- We need "term" commands.
  21. local pin = "1234" -- The PIN is this number.
  22.  
  23. if not component.isAvailable("gpu") then -- If GPU is not available, return.
  24. return
  25. end
  26. local lines = {_OSVERSION .. " (" .. math.floor(computer.totalMemory() / 1024) .. "k RAM)"}
  27. local maxWidth = unicode.len(lines[1])
  28. local f = io.open("/usr/misc/greetings2.txt") -- Open greetings2.txt
  29. if f then
  30. local greetings = {}
  31. pcall(function()
  32. for line in f:lines() do table.insert(greetings, line) end
  33. end)
  34. f:close()
  35. local greeting = greetings[math.random(1, #greetings)]
  36. if greeting then
  37. local width = math.max(10, component.gpu.getResolution())
  38. for line in text.wrappedLines(greeting, width - 4, width - 4) do
  39. table.insert(lines, line)
  40. maxWidth = math.max(maxWidth, unicode.len(line))
  41. end
  42. end
  43. end
  44.  
  45. ::pin_enter::
  46. print("Please enter the correct PIN to unlock door.") -- Display text.
  47. local inputvar = text.trim(term.read())
  48. if inputvar == pin then -- If input is equal to the PIN, goto "correct"
  49. goto correct
  50. else
  51. print("Incorrect.") -- Display text.
  52. goto pin_enter -- Goto "pin_enter"
  53. end
  54. ::correct::
  55. print("Correct.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement