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