From 418767514876674161fd7088bad2c1ba58fe8ea4 Mon Sep 17 00:00:00 2001 From: ElPumpo Date: Fri, 27 Dec 2019 14:49:29 +0100 Subject: [PATCH] /dv command changes (see desc) - Added optional /dv argument for deleting vehicles in proximity - Use RequestControlOfEntity native to properly delete entities --- client/main.lua | 40 +++++++++++++++++++++++++++++++++------- server/commands.lua | 12 ++++++++---- 2 files changed, 41 insertions(+), 11 deletions(-) diff --git a/client/main.lua b/client/main.lua index 8e7d3a4a..cc23ba5f 100644 --- a/client/main.lua +++ b/client/main.lua @@ -323,16 +323,42 @@ AddEventHandler('esx:pickupWeapon', function(weaponPickup, weaponName, ammo) end) RegisterNetEvent('esx:deleteVehicle') -AddEventHandler('esx:deleteVehicle', function() +AddEventHandler('esx:deleteVehicle', function(radius) local playerPed = PlayerPedId() - local vehicle = ESX.Game.GetVehicleInDirection() - if IsPedInAnyVehicle(playerPed, true) then - vehicle = GetVehiclePedIsIn(playerPed, false) - end + if radius and tonumber(radius) then + radius = tonumber(radius) + 0.01 + local vehicles = ESX.Game.GetVehiclesInArea(GetEntityCoords(playerPed), radius) - if DoesEntityExist(vehicle) then - ESX.Game.DeleteVehicle(vehicle) + for k,entity in ipairs(vehicles) do + local attempt = 0 + + while not NetworkHasControlOfEntity(entity) and attempt < 100 and DoesEntityExist(entity) do + Citizen.Wait(100) + NetworkRequestControlOfEntity(entity) + attempt = attempt + 1 + end + + if DoesEntityExist(entity) and NetworkHasControlOfEntity(entity) then + ESX.Game.DeleteVehicle(entity) + end + end + else + local vehicle, attempt = ESX.Game.GetVehicleInDirection(), 0 + + if IsPedInAnyVehicle(playerPed, true) then + vehicle = GetVehiclePedIsIn(playerPed, false) + end + + while not NetworkHasControlOfEntity(vehicle) and attempt < 100 and DoesEntityExist(vehicle) do + Citizen.Wait(100) + NetworkRequestControlOfEntity(vehicle) + attempt = attempt + 1 + end + + if DoesEntityExist(vehicle) and NetworkHasControlOfEntity(vehicle) then + ESX.Game.DeleteVehicle(vehicle) + end end end) diff --git a/server/commands.lua b/server/commands.lua index b240f84d..32e8447f 100644 --- a/server/commands.lua +++ b/server/commands.lua @@ -43,16 +43,20 @@ end, function(source, args, user) end, {help = _U('spawn_car'), params = {{name = 'car', help = _U('spawn_car_param')}}}) TriggerEvent('es:addGroupCommand', 'cardel', 'admin', function(source, args, user) - TriggerClientEvent('esx:deleteVehicle', source) + TriggerClientEvent('esx:deleteVehicle', source, args[1]) end, function(source, args, user) TriggerClientEvent('chat:addMessage', source, { args = { '^1SYSTEM', 'Insufficient Permissions.' } }) -end, {help = _U('delete_vehicle')}) +end, {help = _U('delete_vehicle'), params = { + {name = 'radius', help = 'Optional, delete every vehicle within the specified radius'} +}}) TriggerEvent('es:addGroupCommand', 'dv', 'admin', function(source, args, user) - TriggerClientEvent('esx:deleteVehicle', source) + TriggerClientEvent('esx:deleteVehicle', source, args[1]) end, function(source, args, user) TriggerClientEvent('chat:addMessage', source, { args = { '^1SYSTEM', 'Insufficient Permissions.' } }) -end, {help = _U('delete_vehicle')}) +end, {help = _U('delete_vehicle'), params = { + {name = 'radius', help = 'Optional, delete every vehicle within the specified radius'} +}}) TriggerEvent('es:addGroupCommand', 'setmoney', 'admin', function(source, args, user) local playerId = source