Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- **********************************************************************************
- Программа для управления двери с помощью кода и исходящего от РС сигнала редстоуна
- **********************************************************************************
- pastebin get pNyqCBm2 name
- Edit by Notepad++
- ]]--
- local pword = "12345" --дефолтный код, поменять обязательно!!!
- local core = "admin" --дефолтный код-лазейка для останова программы, поменять обязательно!!!
- local doorSide = "right" -- укажите, с какой стороны от РС у Вас дверь: "left","right","front","back","bottom","top"
- local xMax, yMax = term.getSize()
- local function clear()
- term.clear()
- term.setCursorPos(1, 1)
- end
- local function saveStartUp() --программа прописывает себя в автозагрузку, создание метки РС
- if not os.getComputerLabel() then
- os.setComputerLabel("CodeDoor-"..os.getComputerID())
- end
- --бэкап файла startup
- if fs.exists("startup") then
- if not fs.exists("startup_backup") then
- fs.copy("startup","startup_backup")
- end
- end
- local file = fs.open ("startup", "w")
- file.writeLine ("--Edit the file to execute the program: <"..shell.getRunningProgram()..">")
- file.writeLine ("--A backup copy of the file: <startup_backup>")
- file.writeLine ("shell.run(\""..shell.getRunningProgram().."\")")
- file.close()
- end
- function WriteCenter(str)
- local xPos, yPos = term.getCursorPos()
- str_long = #str
- term.setCursorPos((xMax/2-str_long/2)+1,yPos)
- term.write(str)
- end
- local function pulse(side, freeze)
- rs.setOutput(side, true)
- for i=1, freeze do
- clear()
- term.setCursorPos(1,yMax/2)
- WriteCenter("OPEN! "..freeze+1-i.." sec")
- sleep(1)
- end
- rs.setOutput(side, false)
- end
- local function Draw()
- clear()
- term.setCursorPos(1,yMax/2-1)
- WriteCenter("+-------------------------+")
- term.setCursorPos(1,yMax/2)
- WriteCenter("| Password: |")
- term.setCursorPos(1,yMax/2+1)
- WriteCenter("+-------------------------+")
- term.setCursorPos(xMax/2,yMax/2)
- end
- function os.pullEvent() -- перехват команды terminate, вызываемой Ctrl+T
- local event, p1, p2, p3, p4, p5 = os.pullEventRaw()
- if event == "terminate" then
- clear()
- term.setCursorPos(1,yMax/2)
- WriteCenter("An attempt to break!")
- sleep(5)
- Draw()
- end
- return event, p1, p2, p3, p4, p5
- end
- local function Main()
- while true do
- Draw()
- input = read("*")
- if input == pword then pulse(doorSide, 5)
- elseif input == core then
- clear()
- print('Stopping the program.')
- break
- elseif input ~= pword then
- clear()
- term.setCursorPos(1,yMax/2)
- WriteCenter("Invalid code!")
- sleep(5)
- Draw()
- end
- end
- end
- saveStartUp()
- Main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement