tommy2805

porta di accesso con lista

Nov 3rd, 2025 (edited)
630
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.12 KB | None | 0 0
  1. local USERS_FILE = "allowed_users"
  2.  
  3. local function load_allowed()
  4.     if fs.exists(USERS_FILE) then
  5.         local fh = fs.open(USERS_FILE, "r")
  6.         local content = fh.readAll()
  7.         fh.close()
  8.         local ok, t = pcall(textutils.unserialize, content)
  9.         if ok and type(t) == "table" then
  10.             return t
  11.         end
  12.     else
  13.         print("ERRORE! nessuna lista utenti trovata...")
  14.         return {}
  15.     end
  16. end
  17.  
  18. local function is_allowed(tbl, name)
  19.     if not name then return false end
  20.     for _, v in ipairs(tbl) do
  21.         if v == name then return true end
  22.     end
  23.     return false
  24. end
  25.  
  26. -- Carica lista utenti all'avvio
  27. local allowed = load_allowed()
  28.  
  29. print("Sistema attivo. In attesa...")
  30. while true do
  31.     local ev, playerName = os.pullEvent(player)
  32.     if is_allowed(allowed, playerName) then
  33.         print("Accesso consentito per: "..playerName)
  34.         redstone.setOutput("left", true)
  35.         redstone.setOutput("right", true)
  36.         sleep(2)
  37.         redstone.setOutput("left", false)
  38.         redstone.setOutput("right", false)
  39.     else
  40.         print("Accesso negato")
  41.     end
  42. end
  43.  
Add Comment
Please, Sign In to add comment