Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function counter(tbl) --Gets the length of the table/array.
- local c=0
- for k in pairs(tbl) do c=c+1 end
- return c
- end
- local code = {"1","2", "3", "4", "5"} --Change to however you want, as long as you want.
- local numbers = {"3","6","1","4","5","8","7","2","9","*","0","#"}
- length = counter(code) --Used to get the length of the code. Hence why it can be as long as you want.
- local component = component or require("component")
- local keypad = component.os_keypad
- keypad.setEventName("DoorEntry")
- function generator() --Randomizes the keypad after each press.
- for i=1,11
- do
- j = i+1
- math.randomseed((os.time() * 2147483647) / 7)
- x = math.random(j,12)
- temp = numbers[i]
- numbers[i] = numbers[x]
- numbers[x] = temp
- end
- keypad.setKey(numbers,customButtonColor)
- end
- local event = event or require("event")
- local doorcontroller = component.os_door
- if (doorcontroller.isOpen()) --Checks to make sure the door is closed.
- then
- doorcontroller.toggle()
- end
- customButtonColor = {"1", "1", "1" ,"1", "1", "1", "1", "1", "1", "1", "1", "1",}
- local running = true
- while running do
- ::restart:: --Label for repeating the loop
- keypad.setDisplay("Enter ###")
- local entry = {}
- for i=1,length
- do
- generator()
- local event, address, button, button_label = event.pull("DoorEntry")
- entry[i] = button_label
- end
- for i=1,length
- do
- if (table.concat(entry) ~= table.concat(code)) --If Code entered doesn't match one on record
- then
- keypad.setDisplay("Bad ###")
- os.sleep(5)
- goto restart --Then you go back to the beginning and re-enter it all again. Sucka!
- end
- end
- keypad.setDisplay("Enter")
- doorcontroller.toggle()
- os.sleep(2)
- doorcontroller.toggle()
- goto restart
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement