Onesync Vehicles/Objects Refuse To Be Deleted

Artifacts: 5181
Build: 2545

Server Cfg:
set onesync on
set onesync_workaround763185 true

Force Migration Is Also Set to On

recently i turned on onesync after adjusting all my scripts to work with onesync

and i have been experiencing alot of problems regarding vehicles/objects

impounding vehicles / deleteing placed objects just won’t work

despite the client having Network Control Over These Entities

They refuse to be deleted

Code Used To Delete Entity

if(DoesEntityExist(vehicle)) then

        while not NetworkHasControlOfEntity(vehicle) do

            Citizen.Wait(250)

            NetworkRequestControlOfEntity(vehicle)

        end

        --NetworkFadeOutEntity(vehicle) Not Used Anymore

        --Citizen.Wait(500) Not Used Anymore

        ESX.Game.DeleteVehicle(vehicle)

    end

ESX.Game.DeleteVehicle = function(vehicle)
	SetEntityAsMissionEntity(vehicle, false, true)
	DeleteVehicle(vehicle)
end

our server was running onesync legacy up untill now and the bug didn’t happen there

You shouldn’t request control of an entity, instead just tell the owner to do whatever thing you want to do. In that case you could just ask the server to delete the entity.

you are mostly right about that,
problem is it would allow hackers to use that server event to delete vehicles aswell which kind of worries me

Then add some checks in this event. You can for example check if the client is the one that is supposed to trigger this event, you need to keep track of that yourself.

1 Like

were you ever able to find a more stable way to remove sync’d entities
half the time i have it where it works but its literally 50/50 if it even works

DeleteEntity on the server.

1 Like

Would this work in a clear area way without a specific entity referenced? For instance in my case its a bunch of props spawned by a prop spawer menu that I’m trying to clear. So not just one entity at a time.

I’ve tried this which has a 50% success rate it would seem and even my vMenu’s Clear Area wont work if the props decide to be stubborn

RegisterCommand("cleanup", function(source, args)
	local radius = 30
	local x, y, z = table.unpack(GetEntityCoords(GetPlayerPed(-1), true))
	TriggerEvent('zc:clearZone', x, y, z, radius)
end, false) -- false = everyone can use this (not recommended)

RegisterNetEvent('zc:clearZone')
AddEventHandler('zc:clearZone', function(x, y, z, radius)
	local fRadius = radius + 0.0
	ClearAreaOfObjects(x, y, z, fRadius, 1)
	ClearAreaOfCops(x, y, z, fRadius, 1)
	ClearAreaOfPeds(x, y, z, fRadius, 1)
	ClearAreaOfProjectiles(x, y, z, fRadius, 1)
	ClearAreaOfVehicles(x, y, z, fRadius, false, false, false, false, false)
	ShowNotification("~g~Area Cleaned Up.~b~ You successfully cleared various objects within ".. radius .." meters.")
end)

For reference here is the CreateObject code for said props. Maybe its got something to do with them not always wanting to delete. Now, the reason why NetworkRegisterEntityAsNetworked(obj) is here is because I noticed items despawning randomly when someone would place them and also only the person who placed them could see them. Not sure if that was just good ol’ desync or not. But since I added the Network native it seemed to fix that. But would that effect deleting items using a ClearArea?

function SpawnItem(object)
	local Player = GetPlayerPed(-1)
    local heading = GetEntityHeading(Player)
    local x, y, z = table.unpack(GetEntityCoords(Player, true))

	RequestModel(object)
	while not HasModelLoaded(object) do
		Citizen.Wait(1)
	end
	local obj = CreateObject(GetHashKey(object), x, y, z, true, false, false);
	table.insert(spawned, object)
	NetworkRegisterEntityAsNetworked(obj)	
	PlaceObjectOnGroundProperly(obj)
	SetEntityHeading(obj, heading)
	FreezeEntityPosition(obj, true)
	return
end

GET_ALL_OBJECTS and a GetEntityCoords check, perhaps.

1 Like