mirror of
https://github.com/citizenfx/cfx-server-data.git
synced 2025-02-14 02:13:23 +08:00
* Update playernames_sv.lua * Update playernames_cl.lua * Update playernames_sv.lua * clean up
47 lines
1.1 KiB
Lua
47 lines
1.1 KiB
Lua
local curTemplate
|
|
local curTags = {}
|
|
|
|
local activePlayers = {}
|
|
|
|
local function detectUpdates()
|
|
SetTimeout(500, detectUpdates)
|
|
|
|
local template = GetConvar('playerNames_template', '[{{id}}] {{name}}')
|
|
|
|
if curTemplate ~= template then
|
|
setNameTemplate(-1, template)
|
|
|
|
curTemplate = template
|
|
end
|
|
|
|
template = GetConvar('playerNames_svTemplate', '[{{id}}] {{name}}')
|
|
|
|
for v, _ in pairs(activePlayers) do
|
|
local newTag = formatPlayerNameTag(v, template)
|
|
if newTag ~= curTags[v] then
|
|
setName(v, newTag)
|
|
|
|
curTags[v] = newTag
|
|
end
|
|
end
|
|
|
|
for i, tag in pairs(curTags) do
|
|
if not activePlayers[i] then
|
|
curTags[i] = nil -- in case curTags doesnt get cleared when the player left, clear it now.
|
|
end
|
|
end
|
|
end
|
|
|
|
AddEventHandler('playerDropped', function()
|
|
curTags[source] = nil
|
|
activePlayers[source] = nil
|
|
end)
|
|
|
|
RegisterNetEvent('playernames:init')
|
|
AddEventHandler('playernames:init', function()
|
|
reconfigure(source)
|
|
activePlayers[source] = true
|
|
end)
|
|
|
|
detectUpdates()
|