SHOW:
|
|
- or go back to the newest paste.
| 1 | -- Rayon de recherche des joueurs | |
| 2 | local range = 200 | |
| 3 | ||
| 4 | -- Déclaration de la variable qui stockera l'Advanced Peripherals Player Detector | |
| 5 | local playerDetector | |
| 6 | ||
| 7 | -- Recherche de l'Advanced Peripherals Player Detector connecté | |
| 8 | for _, peripheralName in ipairs(peripheral.getNames()) do | |
| 9 | if peripheral.getType(peripheralName) == "playerDetector" then | |
| 10 | playerDetector = peripheral.wrap(peripheralName) | |
| 11 | break | |
| 12 | end | |
| 13 | end | |
| 14 | ||
| 15 | -- Vérification que l'Advanced Peripherals Player Detector a été trouvé | |
| 16 | if playerDetector == nil then | |
| 17 | print("Advanced Peripherals Player Detector non trouvé")
| |
| 18 | return | |
| 19 | else | |
| 20 | print("Advanced Peripherals Player Detector trouvé")
| |
| 21 | end | |
| 22 | ||
| 23 | -- Déclaration de la variable qui stockera l'Advanced Peripherals Monitor | |
| 24 | local monitor | |
| 25 | ||
| 26 | -- Recherche de l'Advanced Peripherals Monitor connecté | |
| 27 | for _, peripheralName in ipairs(peripheral.getNames()) do | |
| 28 | if peripheral.getType(peripheralName) == "monitor" and peripheral.wrap(peripheralName).isColour() then | |
| 29 | monitor = peripheral.wrap(peripheralName) | |
| 30 | break | |
| 31 | end | |
| 32 | end | |
| 33 | ||
| 34 | -- Vérification que l'Advanced Peripherals Monitor a été trouvé | |
| 35 | if monitor == nil then | |
| 36 | print("Advanced Peripherals Monitor non trouvé")
| |
| 37 | return | |
| 38 | else | |
| 39 | print("Advanced Peripherals Monitor trouvé")
| |
| 40 | end | |
| 41 | ||
| 42 | ||
| 43 | -- Fonction pour afficher la liste des joueurs détectés | |
| 44 | local function displayPlayerList(playerList) | |
| 45 | -- Définir les couleurs d'arrière-plan et de texte pour l'interface | |
| 46 | monitor.setBackgroundColor(colors.black) | |
| 47 | monitor.setTextColor(colors.white) | |
| 48 | -- Effacer l'écran et afficher l'en-tête de l'interface | |
| 49 | monitor.clear() | |
| 50 | monitor.setCursorPos(1, 1) | |
| 51 | monitor.write("===============================")
| |
| 52 | monitor.setCursorPos(1, 2) | |
| 53 | monitor.write(" PLAYERS IN AREA ")
| |
| 54 | monitor.setCursorPos(1, 3) | |
| 55 | monitor.write(" RANGE: "..range..string.rep(" ", 27 - #tostring(range)).."|")
| |
| 56 | monitor.setCursorPos(1, 4) | |
| 57 | monitor.write("===============================")
| |
| 58 | -- Afficher chaque joueur détecté à partir de la ligne 5 | |
| 59 | for i, playerName in ipairs(playerList) do | |
| 60 | monitor.setCursorPos(1, i + 4) | |
| 61 | monitor.write(" " .. playerName .. string.rep(" ", 27 - #playerName) .. "|")
| |
| 62 | end | |
| 63 | -- Afficher le bas de l'interface | |
| 64 | monitor.setCursorPos(1, #playerList + 5) | |
| 65 | monitor.write("===============================")
| |
| 66 | end | |
| 67 | ||
| 68 | -- Boucle principale du programme | |
| 69 | while true do | |
| 70 | -- Vérification si un joueur est en ligne dans le rayon de recherche | |
| 71 | local playersInRange = playerDetector.getPlayersInRange(range) | |
| 72 | if #playersInRange > 0 then | |
| 73 | -- Si un joueur est détecté, afficher la liste des joueurs | |
| 74 | displayPlayerList(playersInRange) | |
| 75 | -- Activer le signal de redstone pour indiquer qu'un joueur est en ligne | |
| 76 | redstone.setOutput("right", true)
| |
| 77 | else | |
| 78 | -- Si aucun joueur n'est détecté, effacer l'écran et désactiver le signal de redstone | |
| 79 | monitor.clear() | |
| 80 | redstone.setOutput("right", false)
| |
| 81 | end | |
| 82 | - | -- Attendre 1 seconde avant de vérifier à nouveau si un joueur est en ligne |
| 82 | + | -- Attendre 30 seconde avant de vérifier à nouveau si un joueur est en ligne |
| 83 | sleep(30) | |
| 84 | end |