Advertisement
Sir_Popsilots

KeyPad

Jul 18th, 2021 (edited)
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.32 KB | None | 0 0
  1. print()
  2. local function drawKeyPad()
  3.     for i = 1 ,9 do
  4.         write("|")
  5.         term.setTextColor(colors.lightBlue)
  6.         write(i)
  7.         term.setTextColor(1)
  8.         if i%3==0 then write("|\n") end
  9.      end
  10.      write("[Enter]")
  11. end
  12.  
  13. local CorrectPassword = 1242
  14.  
  15. local IncorrectString = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
  16.  
  17. local function correctAnimation()
  18.     shell.execute("clear")
  19.     print()
  20.     print()
  21.     term.setTextColor(colors.lime)
  22.     print("Correct")
  23.     term.setTextColor(1)
  24.     local event, button, x, y = os.pullEvent("mouse_click")
  25.     shell.execute("clear")
  26. end
  27.  
  28. local function IncorrectAnimation()
  29.     for i=1,3 do
  30.         shell.execute("clear")
  31.         term.setTextColor(colors.red)
  32.         write(IncorrectString)
  33.         sleep(0.2)
  34.         shell.execute("clear")
  35.         term.setTextColor(colors.white)
  36.         write(IncorrectString)
  37.         sleep(0.2)
  38.         shell.execute("clear")
  39.         term.setTextColor(colors.red)
  40.         write(IncorrectString)
  41.         sleep(0.2)
  42.         shell.execute("clear")
  43.     end
  44.     term.setTextColor(1)
  45. end
  46.  
  47. local function findWhichNum(x,y)
  48.     if y == 5 then
  49.         return 10
  50.     elseif x==2 or x==4 or x==6 then
  51.         if y==2 then
  52.             return x/2
  53.         elseif y==3 then
  54.             return x/2 + 3
  55.         elseif y==4 then
  56.             return x/2 + 6
  57.         end
  58.     end
  59.     return 0
  60. end
  61.  
  62. while true do
  63.     shell.execute("clear")
  64.     print("")
  65.     drawKeyPad()
  66.     local length = 0
  67.     local enteredPassword = 0
  68.     repeat
  69.         local event, button, x, y = os.pullEvent("mouse_click")
  70.         local num = findWhichNum(x,y)
  71.         if num == 10 then
  72.             length = 7
  73.         elseif num ~= 0 then
  74.             enteredPassword = enteredPassword*10 + num
  75.             length = length + 1
  76.         end
  77.         shell.execute("clear")
  78.         if enteredPassword == 69 then
  79.             print(enteredPassword,"nice")
  80.         elseif enteredPassword == 1337 then
  81.             print(enteredPassword,"lit")
  82.         else
  83.             print(enteredPassword)
  84.         end
  85.         drawKeyPad()
  86.     until length > 6
  87.     if enteredPassword == CorrectPassword then
  88.         redstone.setOutput("bottom",true)
  89.         correctAnimation()
  90.     else
  91.         IncorrectAnimation()
  92.     end
  93.     redstone.setOutput("bottom",false)
  94.  
  95. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement