[SOLVED] Trouble with SetEntityAsNoLongerNeeded


#1

Hello. It is time for explain it detailed because in discord i has been ignored.

1) In natives.lua - SetEntityAsNoLongerNeeded (0xB736A491E64A32CF), SetVehicleAsNoLongerNeeded (0x629BFA74418D6239), SetPedAsNoLongerNeeded (0x2595DD4236549CE3) are broken (not usable) many months via classic usage. This natives worked before couple updates, with Invoking like this (for example):

Citizen.InvokeNative(0xB736A491E64A32CF,Citizen.PointerValueIntInitialized(YOUR_ENTITY))

I have been tested it with my gamemodes, blank gamemodes (like map-skater), old gamemodes, where this native worked through invoking before. No results.

Please, tell me! There is a new way to use this natives? Or i don’t know something?
This is stops many works and nice releases for FiveM/pΛ/проектΛ.So please respond!

And yes.
2) no screenshots.
3) It works ~1.5 month ago, till I noticed it.

Thank you in advance.
P.S. Balkan English. Sorry, but i have to post it!


[Develop]Animal system
Set%sAsNoLongerNeeded and some Delete%s do not work with latest manifest version
#2

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.


#3

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.


A questions about animals :-)
#4

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)

#5

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


#6

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


#7

Refer to this


#8

Any solutions for this trouble?


#9

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


#10

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


#11

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


#12

DeleteVehicle?
 


#13

Ease deleting from server. As no longer needed.


#14

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.


#15

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.


#16

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:


#17

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


#18

Has this been fixed yet ?
Thx


#20

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


#21

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