[Release] PD Impound [ESX]

hey!

Whats the standar key?

Can’t find it :frowning:

how can i impound an vehcile as an officer?

can this be adapted to vrp?

its code, so yes… most likely :wink:

What key to open the impound menu?

Do you have to be in the car or??

Hello,
I allow myself to post this thread. For people who have updated their servers to the latest artifact and have also updated es_extended, it is possible that the HorizonPls addon will no longer work. (not really sure for this plugins)

The error obtained could be of the kind :

...math.lua 15: bad argument #1 to 'gsub' string expected, got nill

After a few hours of research, I found a “fix”.


Client

In client.lua, in this function, the json.decode can not retrieve the vehicle info.

RegisterNUICallback('impound', function(data, cb)
	local v = _ESX.Game.GetClosestVehicle();
	local veh = _ESX.Game.GetVehicleProperties(v);

	veh.engineHealth = GetVehicleEngineHealth(v);
	veh.bodyHealth = GetVehicleBodyHealth(v);
	veh.fuelLevel = GetVehicleFuelLevel(v);
	veh.oilLevel = GetVehicleOilLevel(v);
	veh.petrolTankHealth = GetVehiclePetrolTankHealth(v);
	veh.tyresburst = {};
	for i = 1, 7 do
		res = IsVehicleTyreBurst(v, i, false);
		if res ~= nil then
			veh.tyresburst[#veh.tyresburst+1] = res;
			if res == false then
				res = IsVehicleTyreBurst(v, i, true);
				veh.tyresburst[#veh.tyresburst] = res;
			end
		else
			veh.tyresburst[#veh.tyresburst+1] = false;
		end
	end

	veh.windows = {};
	for i = 1, 13 do
		res = IsVehicleWindowIntact(v, i);
		if res ~= nil then
			veh.windows[#veh.windows+1] = res;
		else
			veh.windows[#veh.windows+1] = true;
		end
	end

	if (veh.plate:gsub("%s+", "") ~= data.plate:gsub("%s+", "")) then
		_ESX.ShowNotification("The processed vehicle, and nearest vehicle do not match");
		return
	end

	data.vehicle = json.encode(veh);
	data.identifier = _VehicleAndOwner.identifier;

	TriggerServerEvent('HRP:Impound:ImpoundVehicle', data)

	_ESX.Game.DeleteVehicle(_ESX.Game.GetClosestVehicle());

	DisableImpoundMenu()
    -- cb('ok')
end)

You need to replace :

local v = _ESX.Game.GetClosestVehicle();
local veh = _ESX.Game.GetVehicleProperties(v);

and

data.vehicle = json.encode(veh);

Like this (complet function) :

RegisterNUICallback('impound', function(data, cb)

	local playerPed = PlayerPedId()
	local coords    = GetEntityCoords(playerPed)

	local v = GetClosestVehicle(coords.x, coords.y, coords.z, 5.0, 0, 71)

	local veh = _ESX.Game.GetVehicleProperties(v)

	veh.engineHealth = GetVehicleEngineHealth(v)
	veh.bodyHealth = GetVehicleBodyHealth(v)
	veh.fuelLevel = GetVehicleFuelLevel(v)
	veh.oilLevel = GetVehicleOilLevel(v)
	veh.petrolTankHealth = GetVehiclePetrolTankHealth(v)
	veh.tyresburst = {}
	for i = 1, 7 do
		res = IsVehicleTyreBurst(v, i, false)
		if res ~= nil then
			veh.tyresburst[#veh.tyresburst+1] = res
			if res == false then
				res = IsVehicleTyreBurst(v, i, true)
				veh.tyresburst[#veh.tyresburst] = res
			end
		else
			veh.tyresburst[#veh.tyresburst+1] = false
		end
	end
	
	veh.windows = {}
	for i = 1, 13 do
		res = IsVehicleWindowIntact(v, i)
		if res ~= nil then
			veh.windows[#veh.windows+1] = res
		else
			veh.windows[#veh.windows+1] = true
		end
	end
	
	if (veh.plate:gsub("%s+", "") ~= data.plate:gsub("%s+", "")) then
		_ESX.ShowNotification(_U('vehicle_plate_error'))
		return
	end
	
	data.vehicle = veh;
	data.identifier = VehicleAndOwner.identifier;
	
	TriggerServerEvent('HRP:Impound:ImpoundVehicle', data)
	
	_ESX.Game.DeleteVehicle(ESX.Game.GetClosestVehicle())
	
	DisableImpoundMenu()
	-- cb('ok')
end)

Server
In server.lua, you need to replace :

['@vehicle']		= form.vehicle,

By

['@vehicle']		= json.encode(form.vehicle),

Complet function :

AddEventHandler('HRP:Impound:ImpoundVehicle', function (form)
	Citizen.Trace("HRP: Impounding vehicle: " .. form.plate);
	_source = source;
	MySQL.Async.execute('INSERT INTO `h_impounded_vehicles` VALUES (@plate, @officer, @mechanic, @releasedate, @fee, @reason, @notes, CONCAT(@vehicle), @identifier, @hold_o, @hold_m)',
		{
			['@plate'] 			= form.plate,
			['@officer']     	= form.officer,
			['@mechanic']       = form.mechanic,
			['@releasedate']	= form.releasedate,
			['@fee']			= form.fee,
			['@reason']			= form.reason,
			['@notes']			= form.notes,
			['@vehicle']		= json.encode(form.vehicle),
			['@identifier']		= form.identifier,
			['@hold_o']			= form.hold_o,
			['@hold_m']			= form.hold_m
		}, function(rowsChanged)
			if (rowsChanged == 0) then
				TriggerClientEvent('esx:showNotification', _source, 'Could not impound')
			else
				TriggerClientEvent('esx:showNotification', _source, 'Vehicle Impounded')
			end
	end)
end)

Download for interested :
I modified his files to include folders and a language file. I also integrate markers and blips for parking.

Sure, I did it according to my desires. I have disable some things and add checks. It’s up to you to make your changes.

The code is not necessarily the cleanest. I am not a great developer.

hrp_pd_impound.zip (13.4 KB)

3 Likes

Im also having the same issue, please help

someone got make it work with [RE-RELEASE] esx_eden garage

how can i impound an vehicle?

way under 30 minute job with little programming knowledge. If you don’t know anything about programming why do you even bother making server

I’m learning, brother, but thanks for the help.

was wondering if you can help me out. I am using your version (Note: I havent done anything to my garage script yet)
but the script works but i do not get any menus when I go to “Unimpound” my vehicle, and when I go impound my vehicle it just goes to the actual impound.

Did you modify this script for this to happen or am I doing something wrong (Not editing my script)

YOUR A BIT OF A **** TO BE FAIR takes 20 seconds to be helpful if you are not then why bother answering

1 Like

Also took 20 secs to make this work with the esx Eden Garage two lines of code acutally

wanna share ?? or you going to be like everyother coder and brag!

when the player impounds the vehicle trigger the change mecano state to true or whatever its called can’t remember off hand. Then when they pay to get it out trigger it false. I’d share my scripts but they are doing alot more then just that. then remove the impound marker from the garage mod. Now they cant retrieve it until it paid for.

good man thank you :slight_smile:

Jay, did you get a fix for this bud?

Hey i have my server down just becouse this problem
Thanks in advance

[ERROR] [MySQL] An critical error happens on MySQL for query “select * from owned_vehicles LEFT JOIN users ON users.identifier = owned_vehicles.owner WHERE plate = rtrim(@plate) {@plate=EZB 130}”: An item with the same key has already been added. at System.ThrowHelper.ThrowArgumentException (System.ExceptionResource resource) [0x0000b] in <0123fd5b1a1040fe9d70a7e0d4b28acb>:0
at System.Collections.Generic.Dictionary2[TKey,TValue].Insert (TKey key, TValue value, System.Boolean add) [0x0007c] in <0123fd5b1a1040fe9d70a7e0d4b28acb>:0 at System.Collections.Generic.Dictionary2[TKey,TValue].Add (TKey key, TValue value) [0x00000] in <0123fd5b1a1040fe9d70a7e0d4b28acb>:0
at MySQLAsync.FetchAll+d__2.MoveNext () [0x000e9] in <25ffe552fd484023b5b41531f38bf148>:0
— End of stack trace from previous location where exception was thrown —
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <0123fd5b1a1040fe9d70a7e0d4b28acb>:0
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0003e] in <0123fd5b1a1040fe9d70a7e0d4b28acb>:0
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00028] in <0123fd5b1a1040fe9d70a7e0d4b28acb>:0
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00008] in <0123fd5b1a1040fe9d70a7e0d4b28acb>:0
at System.Runtime.CompilerServices.TaskAwaiter1[TResult].GetResult () [0x00000] in <0123fd5b1a1040fe9d70a7e0d4b28acb>:0 at MySQLAsync.Operation1+d__7[TResult].MoveNext () [0x00169] in <25ffe552fd484023b5b41531f38bf148>:0
Sending heartbeat to live-internal.fivem.net:30110

I have the same issue as many others before me. When I want to impound a vehicle it tells me: Unknown vehicle owner, can not impound.

I’ve tried setting up the vehicle_owner table as suggested above, but it either didn’t work, or I must have done something wrong

I have the most recent version of Mysql-async and esx_migrate installed. And the start esx_migrate is in the dependencies section on my server.cfg. Does anyone have any idea’s what it could be?

2 Likes