vRP | Delete Vehicle with group/role permissions

Well to start of with I couldn’t post this in the correct direction due it didn’t allow me to so here we go again, just move this thread!

This is a very simple script but that I’ve got a lot of questions about. This script will allow only groups that you’ve added to use /dv.
By default the groups is “Police Officer”, “Chief of Police”, and “EMS”.
They can simply write /dv to delete their vehicles.

You are allowed to edit this script however you want but always keep the credit to me and don’t claim this script as your own.

There is a installation guide included in vrp_dvcar.rar file! Report any bugs that should be fixed. Thank you!

vrp_dvcar.rar (2.3 KB)

The lua files:
client.lua

-- Register a network event 
RegisterNetEvent( 'wk:deleteVehicle' )

-- The distance to check in front of the player for a vehicle
-- Distance is in GTA units, which are quite big  
local distanceToCheck = 5.0

-- Add an event handler for the deleteVehicle event. 
-- Gets called when a user types in /dv in chat (see server.lua)
AddEventHandler( 'wk:deleteVehicle', function()
    local ped = GetPlayerPed( -1 )

    if ( DoesEntityExist( ped ) and not IsEntityDead( ped ) ) then 
        local pos = GetEntityCoords( ped )

        if ( IsPedSittingInAnyVehicle( ped ) ) then 
            local vehicle = GetVehiclePedIsIn( ped, false )

            if ( GetPedInVehicleSeat( vehicle, -1 ) == ped ) then 
                SetEntityAsMissionEntity( vehicle, true, true )
                deleteCar( vehicle )

                if ( DoesEntityExist( vehicle ) ) then 
                	ShowNotification( "~r~Please try again." )
                else 
                	ShowNotification( "The vehicle is deleted." )
                end 
            else 
                ShowNotification( "You need to be the driver of the vehicle!" )
            end 
        else
            local playerPos = GetEntityCoords( ped, 1 )
            local inFrontOfPlayer = GetOffsetFromEntityInWorldCoords( ped, 0.0, distanceToCheck, 0.0 )
            local vehicle = GetVehicleInDirection( playerPos, inFrontOfPlayer )

            if ( DoesEntityExist( vehicle ) ) then 
                SetEntityAsMissionEntity( vehicle, true, true )
                deleteCar( vehicle )

                if ( DoesEntityExist( vehicle ) ) then 
                	ShowNotification( "~r~Please try again." )
                else 
                	ShowNotification( "The vehicle is deleted." )
                end 
            else 
                ShowNotification( "You need to be the driver of the vehicle!" )
            end 
        end 
    end 
end )

-- Delete car function borrowed frtom Mr.Scammer's model blacklist, thanks to him!
function deleteCar( entity )
    Citizen.InvokeNative( 0xEA386986E786A54F, Citizen.PointerValueIntInitialized( entity ) )
end

-- Gets a vehicle in a certain direction
-- Credit to Konijima
function GetVehicleInDirection( coordFrom, coordTo )
    local rayHandle = CastRayPointToPoint( coordFrom.x, coordFrom.y, coordFrom.z, coordTo.x, coordTo.y, coordTo.z, 10, GetPlayerPed( -1 ), 0 )
    local _, _, _, _, vehicle = GetRaycastResult( rayHandle )
    return vehicle
end

-- Shows a notification on the player's screen 
function ShowNotification( text )
    SetNotificationTextEntry( "STRING" )
    AddTextComponentString( text )
    DrawNotification( false, false )
end

server.lua

local Tunnel = module("vrp", "lib/Tunnel")
local Proxy = module("vrp", "lib/Proxy")

vRP = Proxy.getInterface("vRP")
vRPclient = Tunnel.getInterface("vRP","vRP_fixcar")

AddEventHandler('chatMessage', function(source, name, msg)
	if msg == "/dv" then
	  local user_id = vRP.getUserId({source})
	  local player = vRP.getUserSource({user_id})
	  if vRP.hasGroup({user_id,"Police Officer"}) then
		CancelEvent();
		TriggerClientEvent('wk:deleteVehicle', source);
	  elseif vRP.hasGroup({user_id,"Chief of Police"}) then
		CancelEvent();
		TriggerClientEvent('wk:deleteVehicle', source);
	  elseif vRP.hasGroup({user_id,"EMS"}) then
		CancelEvent();
		TriggerClientEvent('wk:deleteVehicle', source);
	  end
	end
end)

Have a wonderful day! <3

1 Like

Moved it for ya :wink:

1 Like

This very good P4NDA, but instead of using vRP.hasGroup 3 times you could use vRP.hasPermission, I think it would be easier.

Ex:

local Tunnel = module("vrp", "lib/Tunnel")
local Proxy = module("vrp", "lib/Proxy")

vRP = Proxy.getInterface("vRP")
vRPclient = Tunnel.getInterface("vRP","vRP_fixcar")

AddEventHandler('chatMessage', function(source, name, msg)
	if msg == "/dv" then
	  local user_id = vRP.getUserId({source})
	  local player = vRP.getUserSource({user_id})
	  if vRP.hasPermission({user_id,"dv.vehicle"}) then
		CancelEvent();
		TriggerClientEvent('wk:deleteVehicle', source);
	  end
	end
end)
1 Like

That’s true, didn’t think about that. Thank you! :heart:

What do i set so every CIV in the game is able to /DV ? Not only groups? :wink:

1 Like

Add “user” in the code and everyone will be able to use it.

Edit your server.lua to:

local Tunnel = module("vrp", "lib/Tunnel")
local Proxy = module("vrp", "lib/Proxy")

vRP = Proxy.getInterface("vRP")
vRPclient = Tunnel.getInterface("vRP","vRP_fixcar")

AddEventHandler('chatMessage', function(source, name, msg)
	if msg == "/dv" then
	  local user_id = vRP.getUserId({source})
	  local player = vRP.getUserSource({user_id})
	  if vRP.hasGroup({user_id,"user"}) then
		CancelEvent();
		TriggerClientEvent('wk:deleteVehicle', source);
	  end
	end
end)

and it will work as you requested it to be.

And i edit nothing inside the Client.lua ? Because it still gives me the notification i have no permission

How do i allow everyone to use /dv?

for me says : no such command /dv and i added in resources and in server.cfg like start vrp_dvcar … what can i do ?

Double check that the script actually is running by typing the following two commands into your CMD prompt:

start vrp_dvcar
restart vrp_dvcar

If it mentions any errors then that’s the issue else I’ve no clue right now.

CMD prompt is console of the server ? and i have to write every time these commands ? :))) i’m new in this so sorry if i ask :))

how could i fix this?
Could not find dependency vrp for resource vrp_dvcar.
Couldn’t start resource vrp_dvcar.

this works with ESX?

no it’s only for vrp.

works for vrp framework v2?

How to delete all cars for vrp

Stolen code https://www.diffchecker.com/96H1Ci0B