Advertisement
Frekvens1

CC Doorlock for selected players

Nov 25th, 2013
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.61 KB | None | 0 0
  1. -- Made by Frekvens1, doorlock for selected players
  2.  
  3. -- pastebin get LU7Xezn8 startup
  4.  
  5. local AllowedUsers = {"Frekvens1","abaxcool","XEpicPirateX"}
  6.  
  7. local MaxTries = 4
  8. local CurrentAttempt = 0
  9.  
  10. local Username = ""
  11.  
  12. local Status = "Offline"
  13.  
  14. local monitor = peripheral.wrap("left")
  15. local redstoneOutput = "top"
  16.  
  17. function DoJob()
  18.    if fs.exists("Online") then
  19.        file = io.open("Online", "r")
  20.        Status = file:read()
  21.        file:close()
  22.     end
  23.    
  24.         term.redirect(monitor)
  25.     if Status == "Online" then
  26.        print("Open!")
  27.        redstone.setOutput(redstoneOutput, false)
  28.     else
  29.        print("Closed!")
  30.        redstone.setOutput(redstoneOutput, true)
  31.     end
  32. end
  33.  
  34. function GetUsername()
  35. event, Username = os.pullEvent("player")
  36. CurrentAttempt = 0
  37. checkUsers()
  38. GetUsername()
  39. end
  40.  
  41. function checkUsers()
  42.    if Username == AllowedUsers[CurrentAttempt] then
  43.    if fs.exists("Online") then
  44.           file = io.open("Online", "r")
  45.           Status = file:read()
  46.           file:close()
  47.           if Status == "Online" then
  48.              file = io.open("Online", "w")
  49.                      file:write("Offline")
  50.                      file:close()
  51.           else
  52.              file = io.open("Online", "w")
  53.                      file:write("Online")
  54.                     file:close()
  55.           end
  56.        else
  57.           file = io.open("Online", "w")
  58.               file:write("Offline")
  59.               file:close()
  60.     end
  61.       os.reboot()
  62.    else
  63.       if CurrentAttempt == MaxTries then
  64.       else
  65.       Looper()
  66.       end
  67.    end
  68. end
  69.  
  70. function Looper()
  71.    CurrentAttempt = CurrentAttempt + 1
  72.    checkUsers()
  73. end
  74.  
  75. DoJob()
  76. term.restore()
  77. GetUsername()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement