--- SERVER.LUA
-- Current priority person, stored for re-use
local currentPriority = nil
-- Send priority update to everyone
function UpdatePriority()
TriggerClientEvent("priority:update", -1, currentPriority)
end
-- New player asks for current priority, send it to them
RegisterServerEvent("priority:request")
AddEventHandler("priority:request", function()
TriggerClientEvent("priority:update", source, currentPriority)
end)
-- Command to change priority person
RegisterCommand("priority", function(source, args, rawCommand)
local player = source
local name = GetPlayerName(player)
print("Setting priority to:", name)
currentPriority = player
UpdatePriority()
end)
--- CLIENT.LUA
-- Ask for current priority person on connect / join
Citizen.CreateThread(function()
TriggerServerEvent("priority:request")
end)
-- Current priority person, stored for use in your draw code
local currentPriority = nil
-- New / changed priority person, or the request was returned, at least save the current new one
RegisterNetEvent("priority:update")
AddEventHandler("priority:update", function(serverId)
-- Convert from server to client player id
local player = GetPlayerFromServerId(serverId)
currentPriority = player
end)
-- Your draw code in the same script
...
-- make sure the current priority person is set
if currentPriority then
local name = GetPlayerName(currentPriority)
DrawText("da current priority person is: " .. name)
end
Comments