Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if fs.exists("bigfont") == false then
- shell.run("pastebin get 3LfWxRWh bigfont")
- end
- term.setBackgroundColor(colors.white)
- term.setTextColor(colors.black)
- term.clear()
- term.setCursorPos(1,1)
- mon = peripheral.find("monitor")
- mon.setBackgroundColor(colors.white)
- mon.setTextColor(colors.black)
- mon.setTextScale(0.5)
- mon.clear()
- os.loadAPI("bigfont")
- bigfont.writeOn(mon,1,"Welcome!",nil,5)
- btns = {}
- btns[1] = {name="Unlock",color=colors.lime}
- btns[2] = {name="Change Password",color=colors.orange}
- cY = 10
- w,h = mon.getSize()
- for t=1,#btns do
- btns[t].len = string.len(btns[t].name)+6
- mon.setBackgroundColor(btns[t].color)
- for a=1,3 do
- mon.setCursorPos(math.ceil(w/2)-math.floor(btns[t].len/2),cY+(a-1))
- for l=1,btns[t].len do
- mon.write(" ")
- end
- end
- mon.setCursorPos(math.ceil(w/2)-math.floor(btns[t].len/2),cY+1)
- mon.write(" "..btns[t].name)
- cY = cY+5
- end
- mon.setTextColor(colors.gray)
- mon.setCursorPos(math.ceil(w/2)-string.len("apartment 00")/2,2)
- mon.setBackgroundColor(colors.white)
- mon.write("Apartment 01")
- function monevent()
- while true do
- e = {os.pullEvent()}
- mon.setCursorPos(3,h)
- mon.clearLine()
- mon.setCursorPos(3,h)
- for a=1,#e do
- mon.write(tostring(e[a]).." ")
- end
- if e[1] == "monitor_touch" then
- cY = 10
- for b=1,#btns do
- if e[4] >= cY and e[4] <= cY+2 then
- if btns[b].name == "Unlock" and mode ~= "password" then
- --shell.run("opendoor.lua")
- x,y = term.getCursorPos()
- term.setCursorPos(1,2)
- term.clearLine()
- write("Enter password:")
- term.setCursorPos(x,y)
- _G.mode = "password"
- elseif btns[b].name == "Change Password" and mode ~= "change" then
- x,y = term.getCursorPos()
- term.setCursorPos(1,2)
- term.clearLine()
- write("Enter old password:")
- term.setCursorPos(x,y)
- _G.mode = "change"
- end
- mon.write(btns[b].name)
- end
- cY = cY+5
- end
- end
- end
- end
- _G.mode = "password"
- function password()
- term.clear()
- term.setCursorPos(1,2)
- print("Enter password:\n")
- _G.pass = read("*")
- end
- function fread(file)
- f = fs.open(file,"r")
- r = f.readAll()
- f.close()
- return r
- end
- function fwrite(file,content)
- f = fs.open(file,"w")
- f.write(content)
- f.close()
- return true
- end
- parallel.waitForAny(monevent,password)
- if pass == fread("password") then
- if mode == "change" then
- print("\nEnter new password:")
- newpass = read("*")
- print("\nConfirm new password:")
- newpass2 = read("*")
- if newpass == newpass2 then
- fwrite("password",newpass)
- print("\nNew password set!")
- os.sleep(2)
- os.reboot()
- else
- print("\nPasswords do not match!")
- os.sleep(2)
- os.reboot()
- end
- else
- print("\nDoor unlocked!")
- shell.run("opendoor.lua")
- os.reboot()
- end
- else
- print("\nPassword incorrect!")
- os.sleep(10)
- os.reboot()
- end
- os.reboot()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement