[Release][ESX] carlock

Hello, here’s a carlock script for esx.
You need esx (you need the latest version !) and esx_vehicleshop to make it work.
U to lock/unlock your vehicle.
You can lock it even if multiple vehicles are near you and your vehicle is not the closest one. If you have multiple vehicles that you own out, it’ll lock the closest.
Showcase (added an animation when you lock your vehicle) : https://youtu.be/lzvkP8heivw
The default radius is 30, you can change it in the clienten.lua or clientfr.lua. This script is available in two languages, english and french, it is in english by default. Change the clienten.lua to clientfr.lua in __resource.lua if you want it in french.
Edit (05/2020) : This script is nearly one year old now, and I haven’t updated it since. Therefore, it is likely that the script is now outdated and unfortunately I don’t have time to make any update, I’ll let it on the forum if someone want to update it.

21 Likes

Ummm… Look again…

1 Like

Not job vehicles. Only vehicles that you own. And yes that includes addons. It just looks up the plate in the database to see if you own it

1 Like

not vehicle lock, the topic script.

Yeah the name may not be so good x) I made this script to train, and I just named it esx carlock, but it is different from esx_vehiclelock. Also it works with any vehicle as long as it is in your owned_vehicles table (so probably not with job vehicles, maybe i’ll try to find a way to do it)

Not working for me, but i think it might be because i have another action binded to “U”.

Where in the files do i change hotkey to lock the vehicles?

if (IsControlJustPressed(1, 303)) then
Change the 303

Yeah, find the issue that i cannot open my Police car as Police officer. Would be an amazing feature!

Brilliant scrip! Thank you so much. Works flawlessly

I could do it, but it won’t be so good since you can lock/unlock every police vehicle even if you’re not the one who made it spawn.

is there away you can add a animation to this so it looks like he is pressing his key kinda thing when ever you lock / unlock your car

1 Like

Going to check animations

New version : I have added this animation when you lock/unlock your vehicle [RELEASE] Animation Doorlock Car
Thanks to @Yozza

1 Like

Does this work with esx_kashacters ?

I can confirm it works fine with Kashacters.

got it running with it my self works great.

it is possible to add car block for police cars ? like : policeman can block and unlock car with this script ?

Update it with pNotify. Thank!

I need help I can not make it work and tried with several different control keys and it never works for me can someone help me

ok i update https://github.com/ESX-Org/es_extended and work per me

As I am a good human just like you, I gave you client.lua working in Spanish
so you can add another language to your resource

ESX                           = nil

Citizen.CreateThread(function()
	while ESX == nil do
		TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
		Citizen.Wait(0)
	end

end)



Citizen.CreateThread(function()
  local dict = "anim@mp_player_intmenu@key_fob@"
  RequestAnimDict(dict)
  while not HasAnimDictLoaded(dict) do
      Citizen.Wait(0)
  end
  while true do
    Citizen.Wait(0)
	if (IsControlJustPressed(1, 303)) then
		local coords = GetEntityCoords(GetPlayerPed(-1))
		local hasAlreadyLocked = false
		cars = ESX.Game.GetVehiclesInArea(coords, 30)
		local carstrie = {}
		local cars_dist = {}		
		notowned = 0
		if #cars == 0 then
			ESX.ShowNotification("No hay vehículos para bloquear cerca.")
		else
			for j=1, #cars, 1 do
				local coordscar = GetEntityCoords(cars[j])
				local distance = Vdist(coordscar.x, coordscar.y, coordscar.z, coords.x, coords.y, coords.z)
				table.insert(cars_dist, {cars[j], distance})
			end
			for k=1, #cars_dist, 1 do
				local z = -1
				local distance, car = 999
				for l=1, #cars_dist, 1 do
					if cars_dist[l][2] < distance then
						distance = cars_dist[l][2]
						car = cars_dist[l][1]
						z = l
					end
				end
				if z ~= -1 then
					table.remove(cars_dist, z)
					table.insert(carstrie, car)
				end
			end
			for i=1, #carstrie, 1 do
				local plate = ESX.Math.Trim(GetVehicleNumberPlateText(carstrie[i]))
				ESX.TriggerServerCallback('carlock:isVehicleOwner', function(owner)
					if owner and hasAlreadyLocked ~= true then
						local vehicleLabel = GetDisplayNameFromVehicleModel(GetEntityModel(carstrie[i]))
						vehicleLabel = GetLabelText(vehicleLabel)
						local lock = GetVehicleDoorLockStatus(carstrie[i])
						if lock == 1 or lock == 0 then
							SetVehicleDoorShut(carstrie[i], 0, false)
							SetVehicleDoorShut(carstrie[i], 1, false)
							SetVehicleDoorShut(carstrie[i], 2, false)
							SetVehicleDoorShut(carstrie[i], 3, false)
							SetVehicleDoorsLocked(carstrie[i], 2)
							PlayVehicleDoorCloseSound(carstrie[i], 1)
							ESX.ShowNotification('Tienes ~r~cerrado~s~ tu ~y~'..vehicleLabel..'~s~.')
							if not IsPedInAnyVehicle(PlayerPedId(), true) then
								TaskPlayAnim(PlayerPedId(), dict, "fob_click_fp", 8.0, 8.0, -1, 48, 1, false, false, false)
							end
							hasAlreadyLocked = true
						elseif lock == 2 then
							SetVehicleDoorsLocked(carstrie[i], 1)
							PlayVehicleDoorOpenSound(carstrie[i], 0)
							ESX.ShowNotification('Tienes ~g~abierto~s~ tu ~y~'..vehicleLabel..'~s~.')
							if not IsPedInAnyVehicle(PlayerPedId(), true) then
								TaskPlayAnim(PlayerPedId(), dict, "fob_click_fp", 8.0, 8.0, -1, 48, 1, false, false, false)
							end
							hasAlreadyLocked = true
						end
					else
						notowned = notowned + 1
					end
					if notowned == #carstrie then
						ESX.ShowNotification("No hay vehículos para bloquear cerca.")
					end	
				end, plate)
			end			
		end
	end
  end
end)

i added in github to

and added manual

Installation:

  1. Download zip from here https://github.com/sprixGG/esx_carlock/archive/master.zip
  2. Extract the zip
  3. Rename the folder esx_carlock
  4. Put in the esx directory
  5. Add in your file server.cfg start esx_carlock

change sound ?