Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Déclaration de la variable qui stockera l'Advanced Peripherals Player Detector
- local playerDetector
- -- Recherche de l'Advanced Peripherals Player Detector connecté
- for _, peripheralName in ipairs(peripheral.getNames()) do
- if peripheral.getType(peripheralName) == "playerDetector" then
- playerDetector = peripheral.wrap(peripheralName)
- break
- end
- end
- -- Vérification que l'Advanced Peripherals Player Detector a été trouvé
- if playerDetector == nil then
- print("Advanced Peripherals Player Detector non trouvé")
- return
- else
- print("Advanced Peripherals Player Detector trouvé")
- end
- -- Déclaration de la variable qui stockera l'Advanced Peripherals Monitor
- local monitor
- -- Recherche de l'Advanced Peripherals Monitor connecté
- for _, peripheralName in ipairs(peripheral.getNames()) do
- if peripheral.getType(peripheralName) == "monitor" and peripheral.wrap(peripheralName).isColour() then
- monitor = peripheral.wrap(peripheralName)
- break
- end
- end
- -- Vérification que l'Advanced Peripherals Monitor a été trouvé
- if monitor == nil then
- print("Advanced Peripherals Monitor non trouvé")
- return
- else
- print("Advanced Peripherals Monitor trouvé")
- end
- -- Rayon de recherche des joueurs
- local range = 500
- -- Fonction pour afficher la liste des joueurs détectés
- local function displayPlayerList(playerList)
- -- Définir les couleurs d'arrière-plan et de texte pour l'interface
- monitor.setBackgroundColor(colors.blue)
- monitor.setTextColor(colors.white)
- -- Effacer l'écran et afficher l'en-tête de l'interface
- monitor.clear()
- monitor.setCursorPos(1, 1)
- monitor.write("===============================")
- monitor.setCursorPos(1, 2)
- monitor.write("| PLAYER LIST |")
- monitor.setCursorPos(1, 3)
- monitor.write("===============================")
- -- Afficher chaque joueur détecté à partir de la ligne 4
- for i, playerName in ipairs(playerList) do
- monitor.setCursorPos(1, i + 3)
- monitor.write("| " .. playerName .. string.rep(" ", 27 - #playerName) .. "|")
- end
- -- Afficher le bas de l'interface
- monitor.setCursorPos(1, #playerList + 4)
- monitor.write("===============================")
- end
- -- Fonction pour afficher l'interface de configuration du rayon
- local function displayConfigInterface()
- -- Définir les couleurs d'arrière-plan et de texte pour l'interface
- monitor.setBackgroundColor(colors.gray)
- monitor.setTextColor(colors.white)
- -- Effacer l'écran et afficher l'en-tête de l'interface
- monitor.clear()
- monitor.setCursorPos(1, 1)
- monitor.write("===============================")
- monitor.setCursorPos(1, 2)
- monitor.write("| CONFIGURER LE RAYON |")
- monitor.setCursorPos(1, 3)
- monitor.write("===============================")
- -- Afficher le champ de saisie pour le rayon
- monitor.setCursorPos(1, 5)
- monitor.write("RAYON (en blocs): ")
- monitor.setCursorPos(1, 6)
- monitor.write(string.rep(" ", 27 - #tostring(range)) .. range)
- -- Afficher les instructions pour configurer le rayon
- monitor.setCursorPos(1, 8
- monitor.write("===============================")
- monitor.setCursorPos(1, 10)
- monitor.write("Appuyez sur [ENTRER] pour valider")
- monitor.setCursorPos(1, 11)
- monitor.write("ou sur [ECHAP] pour annuler.")
- end
- -- Afficher l'interface de configuration du rayon pour la première fois
- displayConfigInterface()
- -- Boucle principale du programme
- while true do
- -- Vérifier si un joueur est présent dans le rayon de recherche
- local playerList = playerDetector.getPlayersInRange(range)
- -- Si un joueur est présent, émettre un signal de redstone et afficher la liste des joueurs détectés
- if #playerList > 0 then
- redstone.setOutput("back", true)
- displayPlayerList(playerList)
- else
- redstone.setOutput("back", false)
- monitor.clear()
- end
- -- Attendre 0,5 seconde avant de recommencer la boucle
- sleep(0.5)
- -- Lire les événements clavier pour permettre à l'utilisateur de configurer le rayon
- local event, key = os.pullEvent("key")
- if key == keys.enter then
- -- Si l'utilisateur appuie sur [ENTRER], enregistrer le nouveau rayon et afficher l'interface de détection de joueur
- displayConfigInterface()
- elseif key == keys.escape then
- -- Si l'utilisateur appuie sur [ECHAP], quitter le programme
- monitor.clear()
- return
- elseif key == keys.backspace then
- -- Si l'utilisateur appuie sur [RETOUR ARRIERE], supprimer le dernier chiffre du rayon
- range = math.floor(range / 10)
- displayConfigInterface()
- else
- -- Si l'utilisateur appuie sur une touche numérique, ajouter le chiffre au rayon
- local newRange = tonumber(tostring(range) .. tostring(key))
- if newRange <= 500 then
- range = newRange
- displayConfigInterface()
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement