Skip to content

Commit

Permalink
tweak: car and dv commands
Browse files Browse the repository at this point in the history
- Delete current vehicle when you're spawning a car and in a vehicle
- Add an option to disable that as an arg
- Add radius to dv command
- Fix delete when you're next to the car
  • Loading branch information
BerkieBb committed Jan 22, 2024
1 parent 0e38b21 commit 386e7a3
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 17 deletions.
10 changes: 7 additions & 3 deletions client/events.lua
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,14 @@ lib.callback.register('qbx_core:client:vehicleSpawned', function(netId, props)
end
end)

lib.callback.register('qbx_core:client:getNearestVehicle', function()
local vehicle = lib.getClosestVehicle(GetEntityCoords(cache.ped), 5)
lib.callback.register('qbx_core:client:getVehiclesInRadius', function(radius)
local vehicles = lib.getNearbyVehicles(GetEntityCoords(cache.ped), radius or 5, true)

return vehicle and VehToNet(vehicle)
for i = 1, #vehicles do
vehicles[i] = VehToNet(vehicles[i].vehicle)
end

return vehicles
end)

-- Other stuff
Expand Down
8 changes: 7 additions & 1 deletion locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,13 @@
"model": { "name": "model", "help": "Model name of the vehicle" }
}
},
"dv": { "help": "Delete Vehicle (Admin Only)" },
"dv": {
"help": "Delete Vehicle (Admin Only)",
"params": {
"radius": { "name": "radius", "help": "Radius to delete vehicles in (meters)" },
"keepCurrentVehicle": { "name": "keepCurrentVehicle", "help": "Keep the vehicle you're in right now (leave empty to delete current vehicle)" }
}
},
"givemoney": {
"help": "Give A Player Money (Admin Only)",
"params": {
Expand Down
8 changes: 7 additions & 1 deletion locales/nl.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,13 @@
"model": { "name": "model", "help": "Model van het voertuig" }
}
},
"dv": { "help": "Voertuig verwijderen (Admin Only)" },
"dv": {
"help":"Voertuig verwijderen (Admin Only)",
"params": {
"radius": { "name": "radius", "help": "Radius om voertuigen in te verwijderen (meters)" },
"keepCurrentVehicle": { "name": "keepCurrentVehicle", "help": "Hou het huidige voertuig waar je in zit (laat leeg om huidige voertuig te laten verwijderen)" }
}
},
"givemoney": {
"help": "Geef geld aan een speler (Admin Only)",
"params": {
Expand Down
38 changes: 26 additions & 12 deletions server/commands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -137,33 +137,47 @@ end)
lib.addCommand('car', {
help = locale("command.car.help"),
params = {
{ name = locale("command.car.params.model.name"), help = locale("command.car.params.model.help") }
{ name = locale("command.car.params.model.name"), help = locale("command.car.params.model.help") },
{ name = locale("command.car.params.keepCurrentVehicle.name"), help = locale("command.car.params.keepCurrentVehicle.help"), optional = true },
},
restricted = "group.admin"
}, function(source, args)
if not args then return end
local keepCurrentVehicle = args[locale("command.car.params.keepCurrentVehicle.name")]
local currentVehicle = GetVehiclePedIsIn(GetPlayerPed(source), false)
if not keepCurrentVehicle then
DeleteVehicle(currentVehicle)
end

local netId = SpawnVehicle(source, args[locale("command.car.params.model.name")], nil, true)
local plate = GetPlate(NetworkGetEntityFromNetworkId(netId))
config.giveVehicleKeys(source, plate)
end)

lib.addCommand('dv', {
help = locale("command.dv.help"),
help = locale('command.dv.help'),
params = {
{ name = locale('command.dv.params.radius.name'), type = 'number', help = locale('command.dv.params.radius.help'), optional = true }
},
restricted = 'group.admin'
}, function(source)
}, function(source, args)
local ped = GetPlayerPed(source)
local pedCar = GetVehiclePedIsIn(ped, false)
local pedCars = {GetVehiclePedIsIn(ped, false)}
local radius = args[locale('command.dv.params.radius.name')]

if not pedCar then
local vehicle = lib.callback.await('qbx_core:client:getNearestVehicle', source)

if vehicle then
pedCar = NetworkGetEntityFromNetworkId(vehicle)
end
if pedCars[1] == 0 or radius then -- Only execute when player is not in a vehicle or radius is explicitly defined
pedCars = lib.callback.await('qbx_core:client:getVehiclesInRadius', source, radius)
else
pedCars[1] = NetworkGetNetworkIdFromEntity(pedCars[1])
end

if pedCar and DoesEntityExist(pedCar) then
DeleteEntity(pedCar)
if #pedCars ~= 0 then
for i = 1, #pedCars do
local pedCar = NetworkGetEntityFromNetworkId(pedCars[i])
if pedCar and DoesEntityExist(pedCar) then
DeleteEntity(pedCar)
end
end
end
end)

Expand Down

0 comments on commit 386e7a3

Please sign in to comment.