Help making chatMessage for policejob only

Hey Im fairly new to LUA and I need help making esx_outlaw and my 911 command that I made display a chat notification (not esx notification) to policejob and ambulance job only. Currently they display to the whole server.

AddEventHandler('esx_outlawalert:carJackInProgress', function(targetCoords, streetName, vehicleLabel, playerGender)
	if playerGender == 0 then
		playerGender = _U('male')
		playerGender = _U('female')

	TriggerClientEvent('esx_outlawalert:outlawNotify', -1, _U('carjack', playerGender, vehicleLabel, streetName))
	TriggerClientEvent('chat:addMessage', police, {
	          template = '<div class="chat-message emergency"><div class="chat-message-header">[Dispatch]: A {1} has been seen stealing a {2} near {3} </div><div class="chat-message-body"></div></div>',
	          args = { playerGender, vehicleLabel, streetName }

and for the 911 (policejob and ambulance)

RegisterCommand('911', function(source, args, rawCommand)
    local playerName = GetPlayerName(source)
    local msg = rawCommand:sub(5)
    local name = getIdentity(source)
    fal = name.firstname .. " " .. name.lastname

    TriggerClientEvent('chat:addMessage', -1, {
      template = '<div class="chat-message emergency"><div class="chat-message-header">[Dispatch]: [911] | Caller : {0} | Message : {1}</div><div class="chat-message-body"></div></div>',
      args = { fal, msg }
end, false)

What it looks like

If you only want it to go to specific players, you’ll need to send an event to the server, then allow it to determine which players have which jobs, then send another event back down to those clients specifically, who can then run the chat event locally.

I know that, I just dont know how to do that lol.

I have them working so they pop-up in chat, but I dont understand how to make it only show for police…

Instead of entering -1, loop trough all players and check if their job is police and then trigger it on their source

1 Like

Tried everything I could find, Im still a begginer and this is really hard haha. Could anybody create the function/event I would need to use? Im soo confused :woozy_face:

I figured out how to display the notification for police only, but now getting the message to display in the chat box is my issue? Any help would be appreciated

AddEventHandler('esx_outlawalert:outlawNotify', function(alert)
	if isPlayerWhitelisted then
		TriggerEvent('chat:addMessage', {
			template = '<div class="chat-message emergency"><div class="chat-message-header">[Dispatch]:</div><div class="chat-message-body"></div></div>',


Specifcally I need to somehow include these messages into the chat from locales:

Locales['en'] = {
  ['male'] = 'male',
  ['female'] = 'female',
  ['carjack'] = '~o~Carjack in progress~s~: a ~r~%s~s~ was spotted jacking an ~o~%s~s~ at ~y~%s~s~',
  ['combat'] = '~o~Fight in progress~s~: a ~r~%s~s~ has been spotted fighting at ~y~%s~s~',
  ['gunshot'] = '~o~Shootout in progress~s~: a ~r~%s~s~ has been spotted firing a weapon at ~y~%s~s~',

Did you ever figure this out?