Advertisement
BigBlow_

Spawner-Slave-3

Mar 6th, 2025 (edited)
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.95 KB | None | 0 0
  1. -- Fonction pour demander un ID et le stocker
  2. local function demanderID()
  3. local fichierID = "id_spawner.txt"
  4.  
  5. -- Verifier si l'ID existe deja
  6. if fs.exists(fichierID) then
  7. -- Lire l'ID du fichier
  8. local fichier = fs.open(fichierID, "r")
  9. local id = tonumber(fichier.readAll())
  10. fichier.close()
  11. return id
  12. else
  13. -- Si le fichier n'existe pas, demander un ID
  14. write("Entrez l'ID du spawner: ")
  15. local id = tonumber(read())
  16.  
  17. -- Sauvegarder l'ID dans un fichier
  18. local fichier = fs.open(fichierID, "w")
  19. fichier.write(tostring(id))
  20. fichier.close()
  21.  
  22. return id
  23. end
  24. end
  25.  
  26. -- Demander l'ID du spawner (et le sauvegarder si c'est le premier démarrage)
  27. local SPAWNER_ID = demanderID()
  28.  
  29. local modem = peripheral.find("modem")
  30. if not modem then
  31. error("Aucun modem detecte")
  32. end
  33.  
  34. modem.open(100) -- Ecoute sur le canal 100
  35. redstone.setOutput("bottom", false) -- Desactive la redstone au depart
  36.  
  37. -- Fonction pour obtenir la date et l'heure au format HH:mm:ss_DD/MM
  38. local function getDateHeure()
  39. local heure, minute, seconde = os.date("*t").hour, os.date("*t").min, os.date("*t").sec
  40. local jour, mois = os.date("*t").day, os.date("*t").month
  41. return string.format("%02d:%02d:%02d_%02d/%02d", heure, minute, seconde, jour, mois)
  42. end
  43.  
  44. print("Attente des commandes pour le spawner ID: " .. SPAWNER_ID)
  45.  
  46. while true do
  47. local event, side, senderChannel, replyChannel, message = os.pullEvent("modem_message")
  48.  
  49. if type(message) == "table" and message.id == SPAWNER_ID then
  50. -- Active ou desactive la redstone en bas
  51. redstone.setOutput("bottom", message.state)
  52.  
  53. -- Affichage avec la date et l'heure
  54. local dateHeure = getDateHeure()
  55. print("[" .. dateHeure .. "] Spawner " .. SPAWNER_ID .. " " .. (message.state and "active" or "desactive"))
  56. end
  57. end
  58.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement