local display = false -- Event variables to track UI state local uiInitialized = false local pendingPlayerData = nil -- Otevření/zavření scoreboardu RegisterCommand("toggleScoreboard", function() display = not display if display then -- Požádej server o aktuální data o hráčích TriggerServerEvent('requestPlayerList') end SetDisplay(display) end) RegisterNUICallback("close", function(data, cb) SetDisplay(false) cb('ok') end) -- Inicializace UI a nastavení viditelnosti function SetDisplay(bool) display = bool SetNuiFocus(bool, bool) SendNUIMessage({ type = "ui", display = bool }) -- If we're showing the scoreboard and we already have pending data, send it now if bool and pendingPlayerData then SendNUIMessage({ type = "updatePlayers", players = pendingPlayerData.players, playerCount = pendingPlayerData.playerCount }) pendingPlayerData = nil end -- Mark UI as initialized after first display if bool then uiInitialized = true end end -- Funkce pro aktualizaci seznamu rolí function UpdatePlayerRoles(players) local playerWithRoles = {} for _, player in ipairs(players) do -- This is where we would process player data if needed -- The role data now comes directly from the server table.insert(playerWithRoles, player) end return playerWithRoles end -- Přijímání dat o hráčích ze serveru RegisterNetEvent('updatePlayerList') AddEventHandler('updatePlayerList', function(players) -- Apply any client-side processing to the player data local processedPlayers = UpdatePlayerRoles(players) -- If UI is initialized and displayed, update it immediately if uiInitialized and display then SendNUIMessage({ type = "updatePlayers", players = processedPlayers, playerCount = #processedPlayers }) else -- Otherwise store the data for when the UI becomes visible pendingPlayerData = { players = processedPlayers, playerCount = #processedPlayers } end end) -- Initialize Citizen.CreateThread(function() -- This thread can be used for any initialization logic -- For now, we're just ensuring the UI state is properly set Wait(1000) SetDisplay(false) end)