Blip for everyone

Hello, Im trying to do a crate drop and for that i need blip for everyone to see if event is triggered.
Here is what i have client side:

function RemoveBlip()
Citizen.Wait(30000)
RemoveBlip(crateblip)
end

----
RegisterNetEvent('item:drop')
AddEventHandler('item:drop', function()
        print("crate")
        local coords = GetEntityCoords(GetPlayerPed(-1))
        
        RequestWeaponAsset(GetHashKey("weapon_flare")) 
        while not HasWeaponAssetLoaded(GetHashKey("weapon_flare")) do
            Wait(0)
        end
        
        ShootSingleBulletBetweenCoords(coords, coords - vector3(0.0001, 0.0001, 0.0001), 0, false, GetHashKey("weapon_flare"), 0, true, false, -1.0)
        Citizen.Wait(10000)
        crate = CreateObject(GetHashKey("prop_box_wood02a_pu"), coords.x,coords.y,coords.z+70, true, true, true)
        crateblip = AddBlipForEntity(crate)
        SetBlipFlashes(crateblip, true)
        SetBlipFlashInterval(crateblip, 250)
        SetBlipSprite(crateblip, 501)
        SetBlipColour(crateblip, 15)
        SetEntityDynamic(crate, true)
        Citizen.Wait(4500)
        pickup =  CreateAmbientPickup(GetHashKey("PICKUP_WEAPON_SMG"), coords.x, coords.y, coords.z, 0, 400, 1, false, true)
        RemoveBlip()
        ActivatePhysics(pickup)
end)

I have there blip created for crate but how to make it for everyone to see if that event is triggered? I know it needs to trigger server event or something but how to start it correctly?

Funnily enough, I was going to ask about the exact same thing. I am trying to also add blips to entities, namely vehicles that are spawned all around the map by the network host on start of a mission. I was able to partially do it, with the limitation that on the other clients only blips are created for entities that are close to them as for other entities, the other clients cannot find an entity with a certain network id.

So, you need to network the crate in such a way that the other clients are able to find the crate and put a blip on it. Here is a snippet of my code where I was able to achieve the behavior described above:


After creating a vehicle (in your case crate), pass the vehicle handle to this helper function which returns the netId

private static int GetNetworkedVehicle(int vehicleHandle)
{
    Logger.Debug("Attempting GetNetworkedVehicle");
    NetworkRegisterEntityAsNetworked(vehicleHandle);
    var netId = NetworkGetNetworkIdFromEntity(vehicleHandle);
    SetNetworkIdExistsOnAllMachines(netId, true);
    SetNetworkIdCanMigrate(netId, true);

    if(NetworkGetEntityIsNetworked(vehicleHandle))
    {
        return netId;
    }
    Logger.Debug("NOPE");
    return 0;
}

I then send all netId together in a list to the server side, who then sends them back to ALL clients (including who spawned the vehicles).

In side the eventhandler for receiving the network IDs, I get the entity handle so that I can attach a blip on it.

private static int GetEntityIdFromNetworkedVehicle(int netId)
{
    Logger.Debug($"netId {netId}");
    if (NetworkDoesEntityExistWithNetworkId(netId))
    {
        return NetworkGetEntityFromNetworkId(netId);
    }

    return 0;
}

With the returned entity handle I attach a blip like you do with AddBlipForEntity (only if the returned handle isn’t 0).

Unfortunately, this works on the client who spawned the vehicles, but on other clients ONLY the entities that are close to ped can find an entity ID from the network ID. My theory is that the entities aren’t spawned in the world for the other clients, so their game can’t find it. For example, I spawn a helicopter on top of the Mission Row PD. While standing at Legion Square, the other client will see the blip. But for vehicles spawned at the airport or up at Sandy Shores, he will not.

Perhaps this is some information that may give you an idea on how to fix it. I’ve searched the forums and found information regarding networking the entities (which was achieved with the helper functions above), but not how I want it.

If you find a solution, please let us know.

Prob’s not the best way but what about triggering a client event? Or making a thread that enables when its passed as true? I did not read your post @d0p3t, mainly going for the first post…

Also I think blips need to be in a loop lemme check a script I just made…

Hi,

I’m interested too, I found this: https://runtime.fivem.net/doc/natives/#_0x2B1813ABA29016C5 maybe it can help

And this: https://runtime.fivem.net/doc/natives/#_0xA8A024587329F36A

-- Display blips on map
Citizen.CreateThread(function()
	if (cfg.displayBlips == true) then
		for _, item in pairs(repairCfg.mechanics) do
			item.blip = AddBlipForCoord(item.x, item.y, item.z)
			SetBlipSprite(item.blip, item.id)
			SetBlipAsShortRange(item.blip, true)
			BeginTextCommandSetBlipName("STRING")
			AddTextComponentString(item.name)
			EndTextCommandSetBlipName(item.blip)
		end
	end
end)

-- World 3D Blips
local markerAlpha = 10
local markerRange = 0.6
local markerTable =
{
	-- X, Y, Z
	{450.85, -978.72, 30.69}, -- Downtown PD
	{371.39, -1612.87, 29.29}, -- Davis PD
	{-1112.83, -848.37, 13.44},	-- Vespucci PD
	{2475.86, -384.05, 94.40},	-- HP HQ
	{1852.77, 3691.92, 34.27},	-- Sandy Shores PD
	{-449.97, 6016.30, 31.72},	-- Paleto Bay PD
}

Citizen.CreateThread(function()
	local ped = GetPlayerPed(-1)
    while true do
        Citizen.Wait(0)
        local ped = GetPlayerPed(-1)
			if DoesEntityExist(ped) and not IsEntityDead(ped) then
				local ppos = GetEntityCoords(ped, true)
				for k = 1, #markerTable, 1 do
					if GetDistanceBetweenCoords(markerTable[k][1],markerTable[k][2],markerTable[k][3],ppos) < 15 then
						DrawMarker(1, markerTable[k][1], markerTable[k][2], markerTable[k][3]-1.1, 0, 0, 0, 0.0, 0.0, 0, 0.801, 0.801, 0.6, 2, 80, 206, 200, false, true, true, true, 0, 0)
						DrawMarker(1, markerTable[k][1], markerTable[k][2], markerTable[k][3]-1.1, 0, 0, 0, 0.0, 0.0, 0, 0.8, 0.8, 1.0, 2, 80, 206, markerAlpha, false, true, true, true, 0, 0)
					end
				end
			end
	end
end)

Unless you mean another type of blip… I have done most so lemme know…

If it is gonna show only for nearby players there is no point for doing it at all :frowning:
But @FAXES as you said i dont think it is possible triggering one server event and setting any value to true to make run thread for everyone but anyway ill try.

Well a hard complicated way…

RegisterNetEvent("showForAll")
AddEventHandler("showForAll", function()
   blipThing = true
end)

Citizen.CreateThread(function()
    while true do
        Citizen.Wait(0)
           if blipThing then
              -- do blip shit
           end
    end
end)

lol. Kinda hard complicated way but should work.

The problem isn’t creating blips, the problem is finding an entity on the other clients to attach a blip to. It must be possible and if I don’t get it to work, adding a blip for a coordinate is probably the workaround although not ideal.

Should be poissible. I have done a ton of blip shit lemme dig around files…

  • Mark as mission entity. This’ll not be persisted on migration as there’s no support for script handlers to associate mission entities with.
  • Use 0xA8A024587329F36A to force sending to a specific player (or loop for all). This’ll not work with 1s, since on that end players aren’t responsible for what entities get sent where.
  • Just don’t rely on the entity always existing, but use the entity if it does exist.

Also, what the fuck is with those helper routines - they’re just setting flags that are default already, and you shouldn’t get an entity for a network ID only once as that’ll potentially get deleted again: R* only ever stores the network ID and fetches the entity every time they use the entity in their scripts.

1 Like

I had no idea. I’ve seen these natives called in resources that I found looking around. Thanks :christmas_tree:

I’ll try all tips and keep you all updated.

So, I had a good intuition :yum: