Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[ opencomputers сенсорный кодовый замок by serafim
- Fork from https://youtu.be/r2XaMOI_N9E?t=158
- внешний вид:
- https://i.imgur.com/yHuS42j.gif
- требования:
- монитор и видеокарта 2-го уровня,
- контроллер красного камня
- использование:
- после запуска проги нужно снять клавиатуру с монитора,
- открытие двери по белому списку, нажать * или #
- открытие двери при правильном вводе пароля.
- выдаёт сигнал редстоуна сверху при правильном вводе пароля,
- выдаёт сигнал редстоуна снизу при неправильном вводе пароля.
- пишет логи кто нажимал на экран и что вводил, файл logs
- ]]--
- local password = "123"
- local nicknames = {"serafim","zombi","creper"}
- local com = require("component")
- local sides = require("sides")
- local gpu = com.gpu
- local buttons = {}
- local input,nick
- local keyPad = {
- {"1", "2", "3"},
- {"4", "5", "6"},
- {"7", "8", "9"},
- {"*", "0", "#"},
- }
- if not com.isAvailable("redstone") then
- print("нет контроллера красного камня")
- os.exit()
- end
- local rs = com.redstone
- local function drawKeyPad(x, y)
- local xPos, yPos = x, y
- buttons = {}
- for j = 1, #keyPad do
- xPos = x
- for i = 1, #keyPad[j] do
- gpu.set(xPos + 1, yPos + 1, keyPad[j][i])
- buttons[keyPad[j][i]] = {xPos, yPos, xPos + 4, yPos + 2}
- xPos = xPos + 6
- end
- yPos = yPos + 3
- end
- end
- local function pressButton(x, y, name)
- gpu.setBackground(0xFFFF00)
- gpu.fill(x, y, 3, 3," " )
- gpu.set(x + 1, y + 1, name)
- os.sleep(0.2)
- gpu.setBackground(0x000000)
- gpu.fill(x, y, 3, 3," " )
- drawKeyPad(3,4)
- end
- local function clickedAtArea(x,y,sx,sy,ex,ey)
- if (x >= sx) and (x <= ex) and (y >= sy) and (y <= ey) then return true end
- return false
- end
- local function checkNickname(name)
- for i = 1, #nicknames do
- if name == nicknames[i] then
- return true
- end
- end
- return false
- end
- local function redstone(state)
- if state then
- gpu.setForeground(0x00FF00)
- gpu.set(2,2," доступ разрешён ")
- rs.setOutput(sides.top, 15)
- os.sleep(2)
- rs.setOutput(sides.top, 0)
- else
- gpu.set(2,2," доступ запрещён ")
- rs.setOutput(sides.bottom, 15)
- os.sleep(1)
- rs.setOutput(sides.bottom, 0)
- end
- gpu.setForeground(0xFF0000)
- end
- gpu.setResolution(19,15)
- gpu.setBackground(0x000000)
- gpu.fill(1,1,19,15," ")
- gpu.setForeground(0xFF0000)
- drawKeyPad(3,4)
- gpu.set(2,2," введите пароль ")
- while true do
- local e = {require("event").pull(1,"touch")}
- if e[1] == "touch" then
- nick = e[6]
- for key in pairs(buttons) do
- if clickedAtArea(e[3], e[4], buttons[key][1], buttons[key][2], buttons[key][3], buttons[key][4]) then
- pressButton(buttons[key][1], buttons[key][2], key)
- if key == "*" or key == "#" then
- if checkNickname(nick) then
- redstone(true)
- else
- redstone(false)
- end
- else
- input = (input or "") .. key
- gpu.fill(1, 2, 19, 1, " ")
- gpu.set(11-string.len(input)/2,2,input)
- end
- end
- end
- else
- if input then
- if input == password then
- redstone(true)
- else
- redstone(false)
- end
- file = io.open("logs", "a")
- file:write("Nick: "..nick.." | Key: "..input.."\n")
- file:close()
- input = nil
- end
- gpu.fill(1, 2, 19, 1, " ")
- gpu.set(2,2," введите пароль ")
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement