Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- tArgs = {...}
- local monitor = term
- local side = "front"
- local input = ""
- local code = "1234"
- local countdown = 3
- local r = false
- local unlocked = false
- if tArgs[1] ~= nil then
- if tArgs[1] == "term" then monitor = tArgs[1] else
- monitor = peripheral.wrap(tArgs[1]) end
- end
- if tArgs[2] ~= nil then code = tostring(tArgs[2]) end
- if tArgs[3] ~= nil then side = tArgs[3] end
- local function render_keypad()
- monitor.setBackgroundColor(colors.gray)
- monitor.setTextColor(colors.lightGray)
- monitor.clear()
- monitor.setCursorPos(1,1)
- monitor.write(" 1 2 3")
- monitor.setCursorPos(1,2)
- monitor.write(" 4 5 6")
- monitor.setCursorPos(1,3)
- monitor.write(" 7 8 9")
- monitor.setCursorPos(1,4)
- monitor.setTextColor(colors.red)
- monitor.write(" C")
- monitor.setTextColor(colors.lightGray)
- monitor.write(" 0")
- monitor.setTextColor(colors.green)
- monitor.write(" E")
- if string.len(tostring(input)) < 8 then
- monitor.setCursorPos(1,5)
- monitor.setTextColor(colors.white)
- monitor.write(input)
- end
- monitor.setTextColor(colors.lightGray)
- end
- local function render_error()
- monitor.setBackgroundColor(colors.red)
- monitor.setTextColor(colors.white)
- monitor.clear()
- monitor.setCursorPos(1,3)
- monitor.write(" ERROR")
- os.sleep(3)
- return true
- end
- local function render_success()
- local cd = countdown
- if cd > 9 then cd = 9 end
- monitor.setBackgroundColor(colors.blue)
- monitor.setTextColor(colors.white)
- monitor.clear()
- monitor.setCursorPos(1,2)
- monitor.write("CORRECT")
- monitor.setCursorPos(1,4)
- monitor.write("Tap To")
- while cd > 0 do
- monitor.setCursorPos(1,5)
- monitor.write("Lock(" .. cd .. ")")
- os.sleep(1)
- cd = cd - 1
- end
- monitor.setCursorPos(1,5)
- monitor.write("Lock ")
- return true
- end
- local function render_tv(b)
- if b == nil then b = false end
- monitor.setBackgroundColor(colors.white)
- monitor.setTextColor(colors.white)
- monitor.clear()
- monitor.setCursorPos(1,1)
- monitor.setBackgroundColor(colors.cyan)
- monitor.write(" ")
- monitor.setCursorPos(1,2)
- monitor.setBackgroundColor(colors.lightBlue)
- monitor.write(" ")
- monitor.setCursorPos(1,2)
- monitor.setBackgroundColor(colors.cyan)
- monitor.write(" ")
- monitor.setCursorPos(7,2)
- monitor.write(" ")
- monitor.setBackgroundColor(colors.lightBlue)
- monitor.setCursorPos(1,3)
- monitor.write(" ")
- monitor.setCursorPos(3,3)
- monitor.setBackgroundColor(colors.yellow)
- monitor.write(" ") --sun
- monitor.setCursorPos(1,4)
- monitor.setBackgroundColor(colors.lime)
- monitor.write(" ")
- monitor.setCursorPos(1,5)
- monitor.setBackgroundColor(colors.green)
- monitor.write(" ")
- monitor.setCursorPos(1,1)
- monitor.setBackgroundColor(colors.cyan)
- if r == false then
- monitor.write(" ")
- else
- monitor.write(" RELAX ")
- end
- if b == true then os.sleep(1) end
- r = not r
- end
- local function get_keys()
- local event, eside, x, y = os.pullEvent("monitor_touch")
- local keys = {
- {1, 2, 1 },
- {1, 4, 2 },
- {1, 6, 3 },
- {2, 2, 4 },
- {2, 4, 5 },
- {2, 6, 6 },
- {3, 2, 7 },
- {3, 4, 8 },
- {3, 6, 9 },
- {4, 2, 10},
- {4, 4, 0 },
- {4, 6, 11},
- }
- for _, i in pairs(keys) do
- if y == i[1] and x == i[2] then return i[3] end
- end
- return 12
- end
- local function check_code()
- if input == code then
- redstone.setOutput(side, true)
- render_success()
- input = ""
- return true
- else
- render_error()
- input = ""
- render_keypad()
- return false
- end
- end
- local function chkfile(cnffile)
- if not fs.exists(cnffile) then
- local h = fs.open(cnffile, "w")
- h.write("f")
- h.close()
- end
- end
- local function save(modeo)
- local cnffile = "keypad.reg"
- chkfile(cnffile)
- local h = nil
- if modeo == "t" then
- h = fs.open(cnffile , "w")
- h.write("t")
- elseif modeo == "f" then
- h = fs.open(cnffile , "w")
- h.write("f")
- elseif modeo == "c" then
- h = fs.open(cnffile , "r")
- local r = h.readLine()
- h.close()
- return r
- else
- h = fs.open(cnffile , "w")
- if modeo == nil then modeo = "" end
- h.write(modeo)
- end
- h.close()
- return true
- end
- local function unlock()
- save("t")
- local event, eside, x, y = os.pullEvent("monitor_touch")
- save("f")
- redstone.setOutput(side, false)
- --render_keypad()
- unlocked = false
- end
- local function main()
- local st = save("c")
- if st == "t" then
- redstone.setOutput(side, true)
- render_success()
- unlock()
- elseif st ~= "f" and st ~= "t" then
- input = st
- end
- while (true) do
- if unlocked == false then
- while(true) do
- local timeup = os.startTimer(1)
- local bb = false
- (function()
- render_tv()
- local event, par1, x, y = os.pullEvent()
- if event == "timer" and par1 == timeup then return
- elseif event == "monitor_touch" then bb = true end
- end)()
- if bb == true then break end
- end
- unlocked = true
- else
- render_keypad()
- local p = get_keys()
- if p <= 9 then
- if input == nil then input = "" end
- input = input .. tostring(p)
- if string.len(tostring(input)) > 7 then input = string.sub(input, 2) end
- save(input)
- elseif p == 10 then
- input = ""
- save(input)
- elseif p == 11 then
- if check_code() == true then
- save(input)
- unlock()
- end
- else end
- end
- end
- end
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement