Squanou

test

Jun 22nd, 2024 (edited)
416
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.99 KB | None | 0 0
  1. local monitor = peripheral.find("monitor")
  2. if monitor == nil then
  3.     print("Aucun moniteur disponible")
  4.     return
  5. end
  6.  
  7. local detector = peripheral.find("playerDetector")
  8. if detector == nil then
  9.     print("Aucun détecteur de joueur disponible")
  10.     return
  11. end
  12.  
  13. local function centerText(text, width)
  14.     local textLength = string.len(text)
  15.     local padding = math.floor((width - textLength) / 2)
  16.     return string.rep(" ", padding) .. text
  17. end
  18.  
  19. local function displayPlayerList()
  20.     monitor.clear()
  21.     monitor.setCursorPos(1, 2)
  22.     monitor.write("Fetching Players...")
  23.  
  24.     local players = detector.getOnlinePlayers()
  25.  
  26.     monitor.setTextScale(1.5)
  27.     monitor.clear()
  28.  
  29.     local title = string.format("Liste des joueurs connectés : (%d/9999)", #players)
  30.     local monX, monY = monitor.getSize()
  31.     local centeredTitle = centerText(title, monX)
  32.     monitor.setCursorPos(1, 1)
  33.     monitor.write(centeredTitle)
  34.  
  35.     local startY = math.floor((monY - #players) / 2) + 1
  36.  
  37.     for i, player in ipairs(players) do
  38.         local playerInfo = detector.getPlayerPos(player)
  39.         print(playerInfo.x, playerInfo.y, playerInfo.z, playerInfo.life, playerInfo.health)
  40.         if playerInfo then
  41.             local formattedText = string.format("%s | Coords: X: %d, Y: %d, Z: %d", player, playerInfo.x, playerInfo.y, playerInfo.z)
  42.             local centeredText = centerText(formattedText, monX)
  43.             monitor.setCursorPos(1, startY + i)
  44.             monitor.write(centeredText)
  45.         else
  46.             local centeredText = centerText(player .. " | Position inconnue", monX)
  47.             monitor.setCursorPos(1, startY + i)
  48.             monitor.write(centeredText)
  49.         end
  50.     end
  51.  
  52.     if #players == 0 then
  53.         local noPlayersText = "Aucun joueur connecté"
  54.         local centeredText = centerText(noPlayersText, monX)
  55.         monitor.setCursorPos(1, startY)
  56.         monitor.write(centeredText)
  57.     end
  58. end
  59.  
  60. while true do
  61.     displayPlayerList()
  62.     sleep(1)
  63. end
  64.  
Advertisement
Add Comment
Please, Sign In to add comment