Advertisement
Maksandra

Untitled

Jan 23rd, 2019
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.91 KB | None | 0 0
  1. local accessCode = "1111"
  2.  
  3. local isOpened = false
  4.  
  5. local component = require("component")
  6. local gpu = component.gpu
  7. local event = require("event")
  8. local ser = require("serialization")
  9. local computer = component.computer
  10. local door = component.os_door
  11. keypad = component.os_keypad
  12.  
  13. customButtons = {"1", "2", "3", "4", "5", "6", "7", "8", "9", "<-", "0", "OK"}
  14. customButtonColor = {"1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1"}
  15. keypad.setKey(customButtons, customButtonColor)
  16.  
  17. if door.isOpen()
  18. then
  19.     door.toggle()
  20. end
  21.  
  22. local inputStr = ""
  23. while true do
  24.     ev, address, button, button_label = event.pull("keypad")
  25.     if ev then
  26.         if (button_label == "OK")
  27.         then
  28.             if inputStr == accessCode
  29.             then
  30.                 inputStr = "OK!"
  31.                 keypad.setDisplay(inputStr)
  32.                 computer.beep()
  33.                 door.toggle()
  34.                 isOpened = true
  35.             else
  36.                 inputStr = "Invalid!"
  37.                 keypad.setDisplay(inputStr)
  38.                 os.sleep(2)
  39.             end
  40.             inputStr = ""
  41.         elseif (button_label == "<-")
  42.         then
  43.             if (isOpened == false)
  44.             then
  45.                 if string.len(inputStr) > 0
  46.                 then
  47.                     tmpStr = string.sub(inputStr, 1 , string.len(inputStr) -1)
  48.                     inputStr = tmpStr
  49.                 end
  50.             else
  51.                 door.toggle()
  52.                 isOpened = false
  53.                 keypad.setDisplay("Locked!")
  54.                 inputStr = ""
  55.                 os.sleep(2)
  56.                 keypad.setDisplay(inputStr)
  57.             end
  58.         else
  59.             inputStr = inputStr .. button_label
  60.         end
  61.         a = inputStr.len(inputStr)
  62.         b = ""
  63.         for i = a,1,-1
  64.         do
  65.             b = b .. "*"
  66.         end
  67.         keypad.setDisplay(b)
  68.     end
  69.     os.sleep(0)
  70. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement