Advertisement
BigBlow_

Untitled

Apr 2nd, 2023
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.03 KB | None | 0 0
  1. -- Déclaration de la variable qui stockera l'Advanced Peripherals Player Detector
  2. local playerDetector
  3.  
  4. -- Recherche de l'Advanced Peripherals Player Detector connecté
  5. for _, peripheralName in ipairs(peripheral.getNames()) do
  6. if peripheral.getType(peripheralName) == "playerDetector" then
  7. playerDetector = peripheral.wrap(peripheralName)
  8. break
  9. end
  10. end
  11.  
  12. -- Vérification que l'Advanced Peripherals Player Detector a été trouvé
  13. if playerDetector == nil then
  14. print("Advanced Peripherals Player Detector non trouvé")
  15. return
  16. else
  17. print("Advanced Peripherals Player Detector trouvé")
  18. end
  19.  
  20. -- Déclaration de la variable qui stockera l'Advanced Peripherals Monitor
  21. local monitor
  22.  
  23. -- Recherche de l'Advanced Peripherals Monitor connecté
  24. for _, peripheralName in ipairs(peripheral.getNames()) do
  25. if peripheral.getType(peripheralName) == "monitor" and peripheral.wrap(peripheralName).isColour() then
  26. monitor = peripheral.wrap(peripheralName)
  27. break
  28. end
  29. end
  30.  
  31. -- Vérification que l'Advanced Peripherals Monitor a été trouvé
  32. if monitor == nil then
  33. print("Advanced Peripherals Monitor non trouvé")
  34. return
  35. else
  36. print("Advanced Peripherals Monitor trouvé")
  37. end
  38.  
  39. -- Rayon de recherche des joueurs
  40. local range = 500
  41.  
  42. -- Fonction pour afficher la liste des joueurs détectés
  43. local function displayPlayerList(playerList)
  44. -- Définir les couleurs d'arrière-plan et de texte pour l'interface
  45. monitor.setBackgroundColor(colors.blue)
  46. monitor.setTextColor(colors.white)
  47. -- Effacer l'écran et afficher l'en-tête de l'interface
  48. monitor.clear()
  49. monitor.setCursorPos(1, 1)
  50. monitor.write("===============================")
  51. monitor.setCursorPos(1, 2)
  52. monitor.write("| PLAYER LIST |")
  53. monitor.setCursorPos(1, 3)
  54. monitor.write("===============================")
  55. -- Afficher chaque joueur détecté à partir de la ligne 4
  56. for i, playerName in ipairs(playerList) do
  57. monitor.setCursorPos(1, i + 3)
  58. monitor.write("| " .. playerName .. string.rep(" ", 27 - #playerName) .. "|")
  59. end
  60. -- Afficher le bas de l'interface
  61. monitor.setCursorPos(1, #playerList + 4)
  62. monitor.write("===============================")
  63. end
  64.  
  65. -- Fonction pour afficher l'interface de configuration du rayon
  66. local function displayConfigInterface()
  67. -- Définir les couleurs d'arrière-plan et de texte pour l'interface
  68. monitor.setBackgroundColor(colors.gray)
  69. monitor.setTextColor(colors.white)
  70. -- Effacer l'écran et afficher l'en-tête de l'interface
  71. monitor.clear()
  72. monitor.setCursorPos(1, 1)
  73. monitor.write("===============================")
  74. monitor.setCursorPos(1, 2)
  75. monitor.write("| CONFIGURER LE RAYON |")
  76. monitor.setCursorPos(1, 3)
  77. monitor.write("===============================")
  78. -- Afficher le champ de saisie pour le rayon
  79. monitor.setCursorPos(1, 5)
  80. monitor.write("RAYON (en blocs): ")
  81. monitor.setCursorPos(1, 6)
  82. monitor.write(string.rep(" ", 27 - #tostring(range)) .. range)
  83. -- Afficher les instructions pour configurer le rayon
  84. monitor.setCursorPos(1, 8
  85. monitor.write("===============================")
  86. monitor.setCursorPos(1, 10)
  87. monitor.write("Appuyez sur [ENTRER] pour valider")
  88. monitor.setCursorPos(1, 11)
  89. monitor.write("ou sur [ECHAP] pour annuler.")
  90. end
  91.  
  92. -- Afficher l'interface de configuration du rayon pour la première fois
  93. displayConfigInterface()
  94.  
  95. -- Boucle principale du programme
  96. while true do
  97. -- Vérifier si un joueur est présent dans le rayon de recherche
  98. local playerList = playerDetector.getPlayersInRange(range)
  99.  
  100. -- Si un joueur est présent, émettre un signal de redstone et afficher la liste des joueurs détectés
  101. if #playerList > 0 then
  102. redstone.setOutput("back", true)
  103. displayPlayerList(playerList)
  104. else
  105. redstone.setOutput("back", false)
  106. monitor.clear()
  107. end
  108.  
  109. -- Attendre 0,5 seconde avant de recommencer la boucle
  110. sleep(0.5)
  111.  
  112. -- Lire les événements clavier pour permettre à l'utilisateur de configurer le rayon
  113. local event, key = os.pullEvent("key")
  114. if key == keys.enter then
  115. -- Si l'utilisateur appuie sur [ENTRER], enregistrer le nouveau rayon et afficher l'interface de détection de joueur
  116. displayConfigInterface()
  117. elseif key == keys.escape then
  118. -- Si l'utilisateur appuie sur [ECHAP], quitter le programme
  119. monitor.clear()
  120. return
  121. elseif key == keys.backspace then
  122. -- Si l'utilisateur appuie sur [RETOUR ARRIERE], supprimer le dernier chiffre du rayon
  123. range = math.floor(range / 10)
  124. displayConfigInterface()
  125. else
  126. -- Si l'utilisateur appuie sur une touche numérique, ajouter le chiffre au rayon
  127. local newRange = tonumber(tostring(range) .. tostring(key))
  128. if newRange <= 500 then
  129. range = newRange
  130. displayConfigInterface()
  131. end
  132. end
  133. end
  134.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement