Advertisement
Leprofourbus

ClientHabitants

Feb 8th, 2025 (edited)
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.17 KB | None | 0 0
  1. -- Chemin du dossier des habitants
  2. local inhabitantsFolder = "inhabitants/"
  3.  
  4. -- Créer un habitant
  5. function createInhabitant(nickname, notes)
  6.     local filePath = inhabitantsFolder .. nickname
  7.     local file = fs.open(filePath, "w")
  8.     file.write(notes)
  9.     file.close()
  10.     print("Habitant " .. nickname .. " créé.")
  11. end
  12.  
  13. -- Rechercher un habitant par pseudo (lettres)
  14. function searchInhabitant(letter)
  15.     for _, file in pairs(fs.list(inhabitantsFolder)) do
  16.         if string.match(file, letter) then
  17.             print("Trouvé: " .. file)
  18.             local fileData = fs.open(inhabitantsFolder .. file, "r")
  19.             print("Notes: " .. fileData.readAll())
  20.             fileData.close()
  21.         end
  22.     end
  23. end
  24.  
  25. -- Supprimer un habitant
  26. function deleteInhabitant(nickname)
  27.     local filePath = inhabitantsFolder .. nickname
  28.     if fs.exists(filePath) then
  29.         fs.delete(filePath)
  30.         print("Habitant " .. nickname .. " supprimé.")
  31.     else
  32.         print("L'habitant " .. nickname .. " n'existe pas.")
  33.     end
  34. end
  35.  
  36. -- Exemples d'utilisation
  37. createInhabitant("JohnDoe", "Notes pour JohnDoe.")
  38. searchInhabitant("John")
  39. deleteInhabitant("JohnDoe")
  40.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement