Guest User

startup

a guest
Oct 25th, 2015
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.05 KB | None | 0 0
  1. loginTable = {
  2.     {username="the cat", pw="password"},
  3.     {username="example", pw="example"},
  4. }
  5. letters = {"A", "a", "B", "b", "C", "c", "D", "d", "E", "e", "F", "f", "G", "g", "H", "h", "I", "i", " ", "J", "j", "K", "k", "L", "l", "M", "m", "N", "n", "O", "o", "P", "p", "Q", "q", "R", "r", "S", "s", "T", "t", "U", "u", "V", "v", "W", "w", "X", "x", "Y", "y", "Z", "z", "_"}
  6. usernameLetters = {}
  7.  
  8. function breakString() -- This Breaks up the string the userenters so it can be compard induvidually
  9.     for i = 1, username:len() do
  10.         table.insert(usernameLetters, username:sub(i, i))
  11.     end
  12. end
  13.  
  14. function welcome() -- This compares the strings from letters with the username that was entered by the user
  15.     breakString()
  16.     term.clear()
  17.     term.setCursorPos(1, 1)
  18.     write("Welcome:")
  19.     for userNum = 1, #username do
  20.         for i = 1, #letters do
  21.             term.setCursorPos(9+userNum, 1)
  22.             if letters[i] == usernameLetters[userNum] then
  23.                 write(letters[i])
  24.                 break
  25.             else
  26.                 write(letters[i])
  27.             end
  28.             os.sleep(0.001)
  29.         end
  30.     end
  31. end
  32.  
  33. function printLine(bgColour, fgColour, x, y, length, text) -- This is used to print the text with the coloured box to the right of it example: printLine(colors.green, colors.red, 10, 4, 12, "Username:")
  34.     term.setBackgroundColour(colors.black)
  35.     term.setTextColour(fgColour)
  36.     term.setCursorPos(x, y)
  37.     for i = 0, length do
  38.         term.setBackgroundColour(bgColour)
  39.         write(" ")
  40.     end
  41.     term.setBackgroundColour(colors.black)
  42.     term.setCursorPos(x-#text, y)
  43.     write(text)
  44. end
  45.  
  46. function readInput(bgColour, fgColour, x, y, inRead) -- This is simply a read() but with background and forground color
  47.     term.setBackgroundColour(bgColour)
  48.     term.setTextColour(fgColour)
  49.     term.setCursorPos(x, y)
  50.     local input = read(inRead)
  51.     term.setBackgroundColour(colors.black)
  52.     return input
  53. end
  54.  
  55. function login()
  56.     repeat
  57.         isCorrect = false
  58.         term.clear()
  59.         term.setBackgroundColour(colors.black)
  60.         term.setCursorPos(1,1)
  61.        
  62.         printLine(colors.green, colors.red, usernameX, usernameY, 14, "Username:")
  63.         printLine(colors.green, colors.red, passwordX, passwordY, 14, "Password:")
  64.         username = readInput(colors.green, colors.red, usernameX, usernameY)
  65.         password = readInput(colors.green, colors.red, passwordX, passwordY, "*")
  66.         for i = 1, #loginTable do
  67.             if loginTable[i].username == username and loginTable[i].pw == password then
  68.                 isCorrect = true
  69.             end
  70.         end
  71.     until isCorrect
  72. end
  73.  
  74. function loading()
  75.     --Enter here for loading feel free to change what its currently doing
  76.     for i = 0, 100 do
  77.         term.clear()
  78.         term.setCursorPos(1,1)
  79.         print("Loading: "..i.."%")
  80.         os.sleep(.1)
  81.     end
  82. end
  83.  
  84. -- [[ Change these values to change the pos of the login screen (mess around with the values to see what happens) ]]
  85. usernameX = 20
  86. usernameY = 5
  87. passwordX = 20
  88. passwordY = 7
  89. term.clear()
  90.  
  91. login() -- calling login method
  92. loading() --if you want loading so after the login you can write loading: 20% going up so on then when it ends it will do the welcome scrolling text
  93. welcome() -- welcomes the user (scrolls through text)
  94.  
  95.  
  96. term.setCursorPos(1,10)
Advertisement
Add Comment
Please, Sign In to add comment