Advertisement
Dimensional

Minecraft OpenSecurity Keypad

Mar 28th, 2016
635
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.75 KB | None | 0 0
  1. function counter(tbl) --Gets the length of the table/array.
  2.   local c=0
  3.   for k in pairs(tbl) do c=c+1 end
  4.   return c
  5. end
  6.  
  7. local code = {"1","2", "3", "4", "5"} --Change to however you want, as long as you want.
  8. local numbers = {"3","6","1","4","5","8","7","2","9","*","0","#"}
  9.  
  10. length = counter(code)  --Used to get the length of the code. Hence why it can be as long as you want.
  11.  
  12. local component = component or require("component")
  13. local keypad = component.os_keypad
  14. keypad.setEventName("DoorEntry")
  15.  
  16. function generator()  --Randomizes the keypad after each press.
  17.   for i=1,11
  18.   do
  19.     j = i+1
  20.     math.randomseed((os.time() * 2147483647) / 7)
  21.     x = math.random(j,12)
  22.     temp = numbers[i]
  23.     numbers[i] = numbers[x]
  24.     numbers[x] = temp
  25.   end
  26.   keypad.setKey(numbers,customButtonColor)
  27. end
  28.  
  29. local event = event or require("event")
  30. local doorcontroller = component.os_door
  31.  
  32. if (doorcontroller.isOpen())   --Checks to make sure the door is closed.
  33. then
  34.   doorcontroller.toggle()
  35. end
  36.  
  37. customButtonColor = {"1", "1", "1" ,"1", "1", "1", "1", "1", "1", "1", "1", "1",}
  38.  
  39. local running = true
  40.  
  41. while running do
  42. ::restart::              --Label for repeating the loop
  43. keypad.setDisplay("Enter ###")
  44. local entry = {}
  45. for i=1,length
  46. do
  47.   generator()
  48.   local event, address, button, button_label = event.pull("DoorEntry")
  49.   entry[i] = button_label
  50. end
  51.  
  52. for i=1,length
  53. do
  54.   if (table.concat(entry) ~= table.concat(code))  --If Code entered doesn't match one on record
  55.   then
  56.     keypad.setDisplay("Bad ###")
  57.     os.sleep(5)
  58.     goto restart      --Then you go back to the beginning and re-enter it all again. Sucka!
  59.   end
  60. end
  61. keypad.setDisplay("Enter")
  62. doorcontroller.toggle()
  63. os.sleep(2)
  64. doorcontroller.toggle()
  65. goto restart
  66. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement