Advertisement
glitchdetector

priority person whatever

Dec 31st, 2019
254
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.49 KB | None | 0 0
  1. --- SERVER.LUA
  2. -- Current priority person, stored for re-use
  3. local currentPriority = nil
  4.  
  5. -- Send priority update to everyone
  6. function UpdatePriority()
  7.     TriggerClientEvent("priority:update", -1, currentPriority)
  8. end
  9.  
  10. -- New player asks for current priority, send it to them
  11. RegisterServerEvent("priority:request")
  12. AddEventHandler("priority:request", function()
  13.     TriggerClientEvent("priority:update", source, currentPriority)
  14. end)
  15.  
  16. -- Command to change priority person
  17. RegisterCommand("priority", function(source, args, rawCommand)
  18.     local player = source
  19.     local name = GetPlayerName(player)
  20.     print("Setting priority to:", name)
  21.     currentPriority = player
  22.     UpdatePriority()
  23. end)
  24.  
  25. --- CLIENT.LUA
  26.  
  27. -- Ask for current priority person on connect / join
  28. Citizen.CreateThread(function()
  29.     TriggerServerEvent("priority:request")
  30. end)
  31.  
  32. -- Current priority person, stored for use in your draw code
  33. local currentPriority = nil
  34.  
  35. -- New / changed priority person, or the request was returned, at least save the current new one
  36. RegisterNetEvent("priority:update")
  37. AddEventHandler("priority:update", function(serverId)
  38.     -- Convert from server to client player id
  39.     local player = GetPlayerFromServerId(serverId)
  40.     currentPriority = player
  41. end)
  42.  
  43. -- Your draw code in the same script
  44. ...
  45. -- make sure the current priority person is set
  46. if currentPriority then
  47.     local name = GetPlayerName(currentPriority)
  48.     DrawText("da current priority person is: " .. name)
  49. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement