[Release][ESX] carlock

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 ?

Does this work with addon and job vehicles?

As long as it is in your owned_vehicles table it’ll work (so it won’t work with job vehicles)

What do you mean ?

unfortunate, like 10 lock scripts but only 1 considers job vehicles

Well, you have to edit your esx_jobs resource

i own the car but seem to be getting this error in console and saying in game i dont own car.

EDIT - disregard, had to start it under es_extended and its working

What would I need to change in there to allow job vehicles to be locked?

You need to change your esx jobs resource