[SOLVED] Trouble with SetEntityAsNoLongerNeeded

Sometimes, when invoke has been applied - vehicles can not be destroyed with frag grenades, RPG’s and other explosives. And deleting by game ONLY if everyone is leave server.

Odd - do you have a script to reproduce this? It might be this is caused by fixes to make DELETE_VEHICLE work from all scripts a few updates ago.

here, for example.

Citizen.CreateThread(function()
	while true do
		Wait(0)
		if IsControlJustPressed(1, 51) then -- E
			local model = GetHashKey("buzzard")
			RequestModel(model)
			while not HasModelLoaded(model) do
				Citizen.Wait(0)
			end
			local coords = GetOffsetFromEntityInWorldCoords(GetPlayerPed(-1), 0, 5.0, 0)
			local spawned_c = CreateVehicle(model, coords, 0.0, true, false)
			SetModelAsNoLongerNeeded(model)
			Citizen.InvokeNative(0xB736A491E64A32CF,Citizen.PointerValueIntInitialized(spawned_c))
		end
	end
end)

or for ped (animals):

Citizen.CreateThread(function()
	while true do
		Wait(0)
		if IsControlJustPressed(1, 51) then -- E
			local coords = GetOffsetFromEntityInWorldCoords(GetPlayerPed(-1), 2.0, 2.0, 0.0)
			local amodel = GetHashKey("a_c_coyote", _r)
			RequestModel(amodel)
			while not HasModelLoaded(amodel) do
				Wait(0)
			end
			local rndanimal = CreatePed(28, amodel, coords, 0.0, false, false)
			Citizen.InvokeNative(0xB736A491E64A32CF,Citizen.PointerValueIntInitialized(rndanimal))
			SetModelAsNoLongerNeeded(amodel)
		end
	end
end)

any way to fix it or need to wait for update?

Trying to get NetworkGetNetworkIdFromEntity for spawned car and suspects CreateVehicle - does not return entity id.

Refer to this

Any solutions for this trouble?

I meant that population shouldnt be coded, but actually implemented by us?

To add new features, like animals, jobs, missions this natives must work. Or this is all about cuffing eachother…

How can i spawn peds/cars for missions, jobs and etc. without deleting them after completing/failing?

DeleteVehicle?
 

Ease deleting from server. As no longer needed.

It was usable for few updates ago. Why it is not usable now?
How can i explain to you, how much this native is useful?
It is hard to me, cause i do not know your language well.

I can confirm, the behavior of SetEntityAsNoLongerNeeded changed some updates ago. I don’t know if it fully doesn’t work for me anymore, but the entities didn’t despawn when they would have when the native worked flawlessly (more or less) for me before.

2 Likes

This workaround has indeed been confirmed as causing this type of bug, the next update will have a fix for this and other issues caused by this change in DELETE_[ENTITY/VEHICLE/OBJECT] handling, by patching each instance out separately. Thanks for the report! :snail:

4 Likes

Thank you. I have wait for this answer! Keep it up!

Has this been fixed yet ?
Thx

No. It’s not working again or maybe was never fixed.

Had to implement my own workaround for that.

local function loop(ent,mypos,positions)
    local vehpos=GetEntityCoords(ent)
    local dist_to_me=math.abs(vehpos.x-mypos.x)+math.abs(vehpos.y-mypos.y)+math.abs(vehpos.z-mypos.z)
    if dist_to_me<400 then return end
    for i,playerpos in pairs(positions) do
        local dist_to_player=math.abs(vehpos.x-playerpos.x)+math.abs(vehpos.y-playerpos.y)+math.abs(vehpos.z-playerpos.z)
        if dist_to_player<dist_to_me then
            return
        end
    end
    SetEntityAsMissionEntity(ent,true,true)
    DeleteEntity(ent)
end

Citizen.CreateThread(function()
    DecorRegister("NoLongerNeeded",2)
    while true do
        Wait(500)
        local mypos
        local positions={}
        local myped=PlayerPedId()
        for i=0,31 do
            if NetworkIsPlayerActive(i) then
                local ped=GetPlayerPed(i)
                if(ped==myped) then
                    mypos=GetEntityCoords(myped)
                else
                    positions[i]=GetEntityCoords(ped)
                end
            end
        end
        for veh in EnumerateVehicles() do
            if not IsVehicleDriveable(veh) and GetVehicleEngineHealth(veh)<0
            or DecorExistOn(veh,"NoLongerNeeded") and GetPedInVehicleSeat(veh,-1)==0 then
                loop(veh,mypos,positions)
            end
        end
        for ped in EnumeratePeds() do
            if DecorExistOn(ped,"NoLongerNeeded") then
                loop(ped,mypos,positions)
            end
        end
    end
end)

local function NoLongerNeeded(ent)
    --print("no longer needed")
    if DoesEntityExist(ent) then
        DecorSetBool(ent,"NoLongerNeeded",true)
        Citizen.InvokeNative(0xB736A491E64A32CF,Citizen.PointerValueIntInitialized(ent),true,true)
    end
end

Manifest version 44febabe-d386-4d18-afbe-5e627f4af937 (2017-06-07)

  • The natives.lua file natives_universal.lua will be used for client-side Lua. This is a universal natives.lua file, which should be able to be switched to without having to change your scripts. It also represents a more recent (2017-06-05) snapshot of NativeDB.

Manifest version 05cfa83c-a124-4cfa-a768-c24a5811d8f9 (2017-06-04)

  • Scripts will now be registered as a game network script. This is required for networking entities.
  • [CREATE_VEHICLE](file:///N:/AF35D0D2583051B0) and similar functions behave differently when passing true, true as network object flags. See network objects for more information.

For some reason, SetVehicleAsNoLongerNeeded is not working with manifest version 44febabe-d386-4d18-afbe-5e627f4af937 but works with manifest version 05cfa83c-a124-4cfa-a768-c24a5811d8f9 using exactly same code. I think function definitions are same for both manifest, it’s something else that broke it.