Advertisement
Guest User

startup.lua

a guest
Apr 5th, 2020
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.48 KB | None | 0 0
  1. if fs.exists("bigfont") == false then
  2.     shell.run("pastebin get 3LfWxRWh bigfont")
  3. end
  4. term.setBackgroundColor(colors.white)
  5. term.setTextColor(colors.black)
  6. term.clear()
  7. term.setCursorPos(1,1)
  8. mon = peripheral.find("monitor")
  9. mon.setBackgroundColor(colors.white)
  10. mon.setTextColor(colors.black)
  11. mon.setTextScale(0.5)
  12. mon.clear()
  13. os.loadAPI("bigfont")
  14. bigfont.writeOn(mon,1,"Welcome!",nil,5)
  15. btns = {}
  16. btns[1] = {name="Unlock",color=colors.lime}
  17. btns[2] = {name="Change Password",color=colors.orange}
  18. cY = 10
  19. w,h = mon.getSize()
  20. for t=1,#btns do
  21.     btns[t].len = string.len(btns[t].name)+6
  22.     mon.setBackgroundColor(btns[t].color)
  23.     for a=1,3 do
  24.         mon.setCursorPos(math.ceil(w/2)-math.floor(btns[t].len/2),cY+(a-1))
  25.         for l=1,btns[t].len do
  26.             mon.write(" ")
  27.         end
  28.     end
  29.     mon.setCursorPos(math.ceil(w/2)-math.floor(btns[t].len/2),cY+1)
  30.     mon.write("   "..btns[t].name)
  31.     cY = cY+5
  32. end
  33. mon.setTextColor(colors.gray)
  34. mon.setCursorPos(math.ceil(w/2)-string.len("apartment 00")/2,2)
  35. mon.setBackgroundColor(colors.white)
  36. mon.write("Apartment 01")
  37. function monevent()
  38.     while true do
  39.         e = {os.pullEvent()}
  40.         mon.setCursorPos(3,h)
  41.         mon.clearLine()
  42.         mon.setCursorPos(3,h)
  43.         for a=1,#e do
  44.             mon.write(tostring(e[a]).." ")
  45.         end
  46.         if e[1] == "monitor_touch" then
  47.             cY = 10
  48.             for b=1,#btns do
  49.                 if e[4] >= cY and e[4] <= cY+2 then
  50.                     if btns[b].name == "Unlock" and mode ~= "password" then
  51.                         --shell.run("opendoor.lua")
  52.                         x,y = term.getCursorPos()
  53.                         term.setCursorPos(1,2)
  54.                         term.clearLine()
  55.                         write("Enter password:")
  56.                         term.setCursorPos(x,y)
  57.                         _G.mode = "password"
  58.                     elseif btns[b].name == "Change Password" and mode ~= "change" then
  59.                         x,y = term.getCursorPos()
  60.                         term.setCursorPos(1,2)
  61.                         term.clearLine()
  62.                         write("Enter old password:")
  63.                         term.setCursorPos(x,y)
  64.                         _G.mode = "change"
  65.                     end
  66.                     mon.write(btns[b].name)
  67.                 end
  68.                 cY = cY+5
  69.             end
  70.         end
  71.     end
  72. end
  73. _G.mode = "password"
  74. function password()
  75.     term.clear()
  76.     term.setCursorPos(1,2)
  77.     print("Enter password:\n")
  78.     _G.pass = read("*")
  79. end
  80. function fread(file)
  81.     f = fs.open(file,"r")
  82.     r = f.readAll()
  83.     f.close()
  84.     return r
  85. end
  86. function fwrite(file,content)
  87.     f = fs.open(file,"w")
  88.     f.write(content)
  89.     f.close()
  90.     return true
  91. end
  92. parallel.waitForAny(monevent,password)
  93. if pass == fread("password") then
  94.     if mode == "change" then
  95.         print("\nEnter new password:")
  96.         newpass = read("*")
  97.         print("\nConfirm new password:")
  98.         newpass2 = read("*")
  99.         if newpass == newpass2 then
  100.             fwrite("password",newpass)
  101.             print("\nNew password set!")
  102.             os.sleep(2)
  103.             os.reboot()
  104.         else
  105.             print("\nPasswords do not match!")
  106.             os.sleep(2)
  107.             os.reboot()
  108.         end
  109.     else
  110.         print("\nDoor unlocked!")
  111.         shell.run("opendoor.lua")
  112.         os.reboot()
  113.     end
  114. else
  115.     print("\nPassword incorrect!")
  116.     os.sleep(10)
  117.     os.reboot()
  118. end
  119. os.reboot()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement