Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- svennp is awesome!
- --variables
- for k,v in pairs(rs.getSides()) do
- if peripheral.getType(v) == "monitor" then
- mon = peripheral.wrap(v)
- break
- end
- end
- side = "front"
- unterminatable = false
- timeout = 3
- input = ""
- if fs.exists(".pass") then
- f = fs.open(".pass","r")
- pass = f.readLine()
- f.close()
- else write("input new code (4 digits): ")
- pass = read("*")
- if tonumber(pass) and #pass == 4 then
- f = fs.open(".pass","w")
- f.writeLine(pass)
- f.close()
- else error("please use numbers only! (4 digits!)")
- end
- end
- --functions
- function resetcolor()
- mon.setTextColor(colors.white)
- mon.setBackgroundColor(colors.black)
- end
- function numcolor(num)
- mon.setTextColor(colors.blue)
- mon.setBackgroundColor(colors.black)
- mon.write(num)
- end
- function linecolor(line)
- mon.setTextColor(colors.brown)
- mon.setBackgroundColor(colors.brown)
- mon.write(line)
- end
- function getnum()
- e,p1,p2,p3 = os.pullEvent("monitor_touch")
- if p3 == 2 then
- if p2 == 2 then
- return 1
- elseif p2 == 4 then
- return 2
- elseif p2 == 6 then
- return 3
- end
- elseif p3 == 3 then
- if p2 == 2 then
- return 4
- elseif p2 == 4 then
- return 5
- elseif p2 == 6 then
- return 6
- end
- elseif p3 == 4 then
- if p2 == 2 then
- return 7
- elseif p2 == 4 then
- return 8
- elseif p2 == 6 then
- return 9
- end
- elseif p3 == 5 then
- if p2 == 1 or p2 == 2 or p2 == 3 then
- return "cancel"
- elseif p2 == 5 or p2 == 6 or p2 == 7 then
- return "ok"
- end
- else return getnum()
- end
- end
- function printinterface()
- mon.setCursorPos(1,1)
- resetcolor()
- mon.write("> ")
- mon.setCursorPos(1,2)
- linecolor("|") numcolor("1") linecolor("|") numcolor("2") linecolor("|") numcolor("3") linecolor("|")
- mon.setCursorPos(1,3)
- linecolor("|") numcolor("4") linecolor("|") numcolor("5") linecolor("|") numcolor("6") linecolor("|")
- mon.setCursorPos(1,4)
- linecolor("|") numcolor("7") linecolor("|") numcolor("8") linecolor("|") numcolor("9") linecolor("|")
- mon.setCursorPos(1,5)
- mon.setBackgroundColor(colors.red) mon.write(" ") mon.setBackgroundColor(colors.black) mon.write(" ") mon.setBackgroundColor(colors.green) mon.write(" ")
- end
- function printcorrect()
- mon.setBackgroundColor(colors.green)
- mon.setTextColor(colors.green)
- for i = 1,5 do
- mon.setCursorPos(1,i)
- mon.write(" ")
- end
- resetcolor()
- end
- function printwrong()
- mon.setBackgroundColor(colors.red)
- mon.setTextColor(colors.red)
- for i = 1,5 do
- mon.setCursorPos(1,i)
- mon.write(" ")
- end
- resetcolor()
- end
- -- other stuff
- term.clear()
- term.setCursorPos(1,1)
- print("running svennp's lock program")
- if unterminatable then
- print("termination of program not possible!")
- else
- print("termination of program possible!")
- end
- if unterminatable then
- os.pullEvent = os.oullEventRaw
- end
- --main loop
- printinterface()
- while true do
- mon.setCursorPos(1,1)
- resetcolor()
- mon.write("> ")
- mon.setCursorPos(3,1)
- for i = 1,#input do
- mon.write("*")
- end
- q = nil
- while q == nil do
- q = getnum()
- end
- if type(q) == "string" then
- if q == "cancel" then
- input = ""
- elseif q == "ok" then
- if input == pass then
- printcorrect()
- rs.setOutput(side,true)
- sleep(timeout)
- rs.setOutput(side,false)
- else
- printwrong()
- sleep(timeout)
- end
- input = ""
- printinterface()
- end
- elseif type(q) == "number" then
- if #input < 4 then
- input = input..tostring(q)
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment