[Help] Send blip to online players with ambulance job and a notification

Hello
When a player dies, he gets to press Button ‘G’, I want ambulance to be informed by a notification and a blip shows up

I did it this way :

			if IsControlPressed(0, Keys['G']) then
				SendDistressSignal()
				getEMSNotified()
				Citizen.CreateThread(function()
					Citizen.Wait(1000 * 60 * 5)
					if IsDead then
						StartDistressSignal()
					end
				end)

				break
			end
function getEMSNotified()
		local blips = {
			 {title= "Attention required" , colour=3, id=1, x = PedPosition.x, y = PedPosition.y, z = PedPosition.z }
		}
		Citizen.CreateThread(function()
			for _, info in pairs(blips) do
			  info.blip = AddBlipForCoord(info.x, info.y, info.z)
			  SetBlipSprite(info.blip, info.id)
			  SetBlipDisplay(info.blip, 4)
			  SetBlipScale(info.blip, 1.0)
			  SetBlipColour(info.blip, info.colour)
			  SetBlipAsShortRange(info.blip, true)
			  BeginTextCommandSetBlipName("STRING")
			  AddTextComponentString(info.title)
			  EndTextCommandSetBlipName(info.blip)
			end
		end)
		TriggerEvent("chatMessage", "DISPATCH ", 3, 'a medic should be informed by now, you can still use /me')
end

The blip shows only to me when I revive my self and not to any medic

I can’t give you an answer to fixing this but It does look like you haven’t defined who EMS is, which you probably need to do through the server. The reason its only giving it to you is because it’s not being sent out to other clients I believe.

@Aidenszl, I have tried doing this

function getEMSNotified()
	ESX = nil
	local xPlayer = ESX.GetPlayerFromId(source)
	if xPlayer.job.name == 'ambulance' then
		local blips = {
			 {title= "Attention required" , colour=3, id=1, x = PedPosition.x, y = PedPosition.y, z = PedPosition.z }
		}
		Citizen.CreateThread(function()
			for _, info in pairs(blips) do
			  info.blip = AddBlipForCoord(info.x, info.y, info.z)
			  SetBlipSprite(info.blip, info.id)
			  SetBlipDisplay(info.blip, 4)
			  SetBlipScale(info.blip, 1.0)
			  SetBlipColour(info.blip, info.colour)
			  SetBlipAsShortRange(info.blip, true)
			  BeginTextCommandSetBlipName("STRING")
			  AddTextComponentString(info.title)
			  EndTextCommandSetBlipName(info.blip)
			end
		end)
		TriggerEvent("chatMessage", "DISPATCH ", 3, 'a medic should be informed by now, you can still use /me')
end
end

this one worked, but showed the blip and message only to me when I set my job to ambulance

is it possible to notify the closest player with ESX.PlayerData.job.name == ‘ambulance’ ?

The problem here is that you’re doing all of this for xPlayer. If you want to do this for more than just one person you need to Trigger a Server event which will then trigger, for every player, a client event.

You would need to change your current code to this

function getEMSNotified()
	ESX = nil
	local xPlayer = ESX.GetPlayerFromId(source)
	if xPlayer.job.name == 'ambulance' then
		local blips = {
			 {title= "Attention required" , colour=3, id=1, x = PedPosition.x, y = PedPosition.y, z = PedPosition.z }
		}

		--[[Citizen.CreateThread(function()
			for _, info in pairs(blips) do
			  info.blip = AddBlipForCoord(info.x, info.y, info.z)
			  SetBlipSprite(info.blip, info.id)
			  SetBlipDisplay(info.blip, 4)
			  SetBlipScale(info.blip, 1.0)
			  SetBlipColour(info.blip, info.colour)
			  SetBlipAsShortRange(info.blip, true)
			  BeginTextCommandSetBlipName("STRING")
			  AddTextComponentString(info.title)
			  EndTextCommandSetBlipName(info.blip)
			end
		end)]]
		TriggerServerEvent("esx_ambulancejob:helpblip", blips)
		TriggerEvent("chatMessage", "DISPATCH ", 3, 'a medic should be informed by now, you can still use /me')
end
end

Then create an event handler in the server side part of the script:

RegisterServerEvent('esx_ambulancejob:helpblip')
AddEventHandler('esx_ambulancejob:helpblip', function(blips)

	local _source = source
	local xPlayer = ESX.GetPlayerFromId(_source)
	local Players = ESX.GetPlayers()

	for i=1, #Players, 1 do
		TriggerClientEvent('esx_ambulancejob:sendhelpblip', Players[i], blips)
	end
end)

And finally create an event handler in the client side part of the script:

RegisterNetEvent('esx_ambulancejob:sendhelpblip')
AddEventHandler('esx_ambulancejob:sendhelpblip', function(blips)


    Citizen.CreateThread(function()
			for _, info in pairs(blips) do
			  info.blip = AddBlipForCoord(info.x, info.y, info.z)
			  SetBlipSprite(info.blip, info.id)
			  SetBlipDisplay(info.blip, 4)
			  SetBlipScale(info.blip, 1.0)
			  SetBlipColour(info.blip, info.colour)
			  SetBlipAsShortRange(info.blip, true)
			  BeginTextCommandSetBlipName("STRING")
			  AddTextComponentString(info.title)
			  EndTextCommandSetBlipName(info.blip)
			end
		end)
	
end)

I’ve copy pasted and written this 100% in the forum’s text editor and haven’t tested it. I might even add it to my server if it works. Tell me :smile:

Error in this line :
local xPlayer = ESX.GetPlayerFromId(source)
Global ESX undefined !!

On the top of your server sided script you need to have

ESX = nil

TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)

Do I need to create an event to automatically remove the blip when the player is revived? Or it will be automatic

emm I want to make it automated, once player is revived the blip should disappear is it possible ?

Well I think your code is a bit messy, I have done it, now I want to make it disappear once player is revived

Not sure how to do that, sorry

I think that you can make it with this two things, but i don’t know where to put them

displayTime = 120

	Wait(displayTime * 1000)

Where to write this code?

This is a client-side code

And whta is the cliant side code? I wnat Just to my ambulance job add this

Can someone please help! I have tried all these suggestions and I cannot get staff notified when someone down

did you know if this works? Ive tried pasting but not getting anything