/dv command changes (see desc)

- Added optional /dv argument for deleting vehicles in proximity
- Use RequestControlOfEntity native to properly delete entities
This commit is contained in:
ElPumpo
2019-12-27 14:49:29 +01:00
parent 756a13f3bb
commit 4187675148
2 changed files with 41 additions and 11 deletions
+33 -7
View File
@@ -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)
+8 -4
View File
@@ -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