Advertisement
BigBlow_

Untitled

Apr 2nd, 2023
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.31 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. -- Couleurs utilisées dans l'interface graphique
  43. local backgroundColor = colors.black
  44. local foregroundColor = colors.white
  45. local titleColor = colors.blue
  46. local playerColor = colors.green
  47.  
  48. -- Largeur et hauteur de l'écran
  49. local width, height = monitor.getSize()
  50.  
  51. -- Fonction pour afficher l'interface graphique
  52. local function drawInterface(title, players)
  53. -- Effacer l'écran avec la couleur de fond
  54. monitor.setBackgroundColor(backgroundColor)
  55. monitor.clear()
  56.  
  57. -- Afficher le titre de l'interface
  58. monitor.setBackgroundColor(titleColor)
  59. monitor.setTextColor(foregroundColor)
  60. monitor.setCursorPos(1, 1)
  61. monitor.write(string.rep(" ", width))
  62. monitor.setCursorPos((width - #title) / 2 + 1, 1)
  63. monitor.write(title)
  64.  
  65. -- Afficher la liste des joueurs
  66. monitor.setBackgroundColor(backgroundColor)
  67. monitor.setTextColor(playerColor)
  68. for i, playerName in ipairs(players) do
  69. monitor.setCursorPos(2, i + 2)
  70. monitor.write(playerName)
  71. end
  72.  
  73. -- Afficher le cadre de l'interface
  74. monitor.setBackgroundColor(foregroundColor)
  75. monitor.setTextColor(backgroundColor)
  76. monitor.setCursorPos(1, 1)
  77. monitor.write(string.rep(" ", width))
  78. monitor.setCursorPos(1, height)
  79. monitor.write(string.rep(" ", width))
  80. for i = 2, height - 1 do
  81. monitor.setCursorPos(1, i)
  82. monitor.write(" ")
  83. monitor.setCursorPos(width, i)
  84. monitor.write(" ")
  85. end
  86. end
  87.  
  88. -- Boucle principale du programme
  89. while true do
  90. -- Vérification si un joueur est en ligne dans le rayon de recherche
  91. local playersInRange = playerDetector.getPlayersInRange(range)
  92. if #playersInRange > 0 then
  93. -- Si un joueur est en ligne dans le rayon de recherche, émettre un signal de redstone sur le côté arrière
  94. redstone.setOutput("back", true)
  95. -- Afficher l'interface graphique avec la liste des joueurs à l'écran
  96. drawInterface("Joueurs en ligne", playersInRange)
  97. else
  98. --
  99.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement