Advertisement
Ceziy

enter_pin.lua

Nov 27th, 2023 (edited)
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.55 KB | None | 0 0
  1. os.loadAPI("ATMApi.lua")
  2.  
  3. rednet.open("top")
  4.  
  5.  
  6.  
  7. os.pullEvent = os.pullEventRaw
  8.  
  9. local w,h = term.getSize()
  10.  
  11. function printCentered( y,s )
  12.    local x = math.floor((w - string.len(s)) / 2)
  13.    term.setCursorPos(x,y)
  14.    term.clearLine()
  15.    term.write(s)
  16. end
  17.  
  18. password = ""
  19. display = ""
  20. nOption = ""
  21.  
  22. function menu(pass)
  23.     term.clear()
  24.     printCentered( math.floor(h/2) - 3, "Enter password")
  25.     printCentered( math.floor(h/2) - 1, pass)
  26. end
  27.  
  28. menu(display)
  29.  
  30.    
  31. while true do
  32.     local event, key = os.pullEvent("key")
  33.     if key == keys.one then
  34.         password = password .. "1"
  35.         display = display .. "*"
  36.         menu(display)
  37.     elseif key == keys.two then
  38.         password = password .. "2"
  39.         display = display .. "*"
  40.         menu(display)
  41.     elseif key == keys.three then
  42.         password = password .. "3"
  43.         display = display .. "*"
  44.         menu(display)
  45.     elseif key == keys.four then
  46.         password = password .. "4"
  47.         display = display .. "*"
  48.         menu(display)
  49.     elseif key == keys.five then
  50.         password = password .. "5"
  51.         display = display .. "*"
  52.         menu(display)
  53.     elseif key == keys.six then
  54.         password = password .. "6"
  55.         display = display .. "*"
  56.         menu(display)
  57.     elseif key == keys.seven then
  58.         password = password .. "7"
  59.         display = display .. "*"
  60.         menu(display)
  61.     elseif key == keys.eight then
  62.         password = password .. "8"
  63.         display = display .. "*"
  64.         menu(display)
  65.     elseif key == keys.nine then
  66.         password = password .. "9"
  67.         display = display .. "*"
  68.         menu(display)
  69.     elseif key == keys.zero then
  70.         password = password .. "0"
  71.         display = display .. "*"
  72.         menu(display)
  73.     elseif key == keys.backspace then
  74.         password = password:sub(1, #password - 1)
  75.         display = display:sub(1, #display - 1)
  76.         menu(display)
  77.     elseif key == keys.enter then
  78.         if ATMApi.cardIn() == true then
  79.             message = ATMApi.getCardData()
  80.             if message == nil then print("no") end
  81.             if message ~= nil then
  82.             --print(message.pass, password)
  83.                 if tostring(message.pass) == tostring(password) then
  84.                     nOption = "true_pass"
  85.                     break
  86.                 end
  87.             end
  88.         else shell.run("main")
  89.         end
  90.     end
  91.         --if ATMApi.cardIn() == true then break end
  92. end
  93.  
  94. if nOption == "true_pass" then shell.run("main_menu")
  95. else shell.run("main") end
  96.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement