Make entity blip working for everyone

Hi there,

My intention is that people who fly in a helicopter or airplane will get a blip. As soon as they get off this must disappear.
This code works now . But it only works at 1 person in the server (I think the one who first joined)

How can I make this work for everyone in the server? Regardless of when you joined?

local blips = {
    -- Example {title="", colour=, id=, x=, y=, z=},

     {title="Example 1", colour=5, id=446, x = -347.291, y = -133.370, z = 38.009}
  }
     
Citizen.CreateThread(function()
	a = 10
	
	while( a > 0 ) do
	ped = PlayerPedId()
	lastUnit = GetVehiclePedIsIn(PlayerPedId(), true)
	blip = GetBlipFromEntity(lastUnit)

	Citizen.Wait(1000)
	if IsPedInAnyPlane(GetPlayerPed(id)) then
			for _, info in pairs(blips) do
				RemoveBlip(GetBlipFromEntity(ped))
				info.blip = AddBlipForEntity(ped)
				SetBlipSprite(info.blip, 251) -- Blip Sprite
				SetBlipColour(info.blip, 68)
				Citizen.InvokeNative(0x5FBCA48327B914DF, info.blip, true) -- Player Blip indicator
				SetBlipRotation(info.blip, math.ceil(GetEntityHeading(veh))) -- update rotation
				SetBlipNameToPlayerName(info.blip, id) -- update info.blip name
				SetBlipScale(info.blip, 1.00) -- set scale
				SetBlipAsShortRange(info.blip, true)
			end
	elseif IsPedInAnyHeli(ped) then
			for _, info in pairs(blips) do
				RemoveBlip(GetBlipFromEntity(ped))
				info.blip = AddBlipForEntity(ped)
				SetBlipSprite(info.blip, 43) -- Blip Sprite
				SetBlipColour(info.blip, 69)
				Citizen.InvokeNative(0x5FBCA48327B914DF, info.blip, true) -- Player Blip indicator
				SetBlipRotation(info.blip, math.ceil(GetEntityHeading(veh))) -- update rotation
				SetBlipNameToPlayerName(info.blip, id) -- update info.blip name
				SetBlipScale(info.blip, 1.00) -- set scale
				SetBlipAsShortRange(info.blip, true)
			end
	else
			for _, info in pairs(blips) do
				
				RemoveBlip(GetBlipFromEntity(ped))
			end
    end
	
	a = a+1
    end	
end)
1 Like

Try putting or instead of else if

have you found any solution?

Yes, with the server side native GetPlayers
https://docs.fivem.net/docs/scripting-reference/runtimes/lua/functions/GetPlayers/

for _, playerId in ipairs(GetPlayers()) do
  local name = GetPlayerName(playerId)
  print(('Player %s with id %i is in the server'):format(name, playerId))
  -- ('%s'):format('text') is same as string.format('%s', 'text)
end