glitchdetector icon

priority person whatever

glitchdetector | PRO | 12/31/19 08:00:25 PM UTC | 0 ⭐ | 496 👁️ | Never ⏰ | []
Lua |

1.49 KB

|

None

|

0 👍

/

0 👎

--- 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