Synced Vehicle Locks, with Lock all NPC cars

You use from the menu or blowpipe?

It has the same effect with both the blowpipe and the menu. (I think the blowpipe item just calls the same hijack code.)

put

local Plate = GetVehicleNumberPlateText(vehicle)

Same issue, for some reason. The console doesn’t show any errors when the server loads or when I try hijacking. The door opens but the game still treats the car as locked.

			Citizen.CreateThread(function()
				Citizen.Wait(10000)
				if chance <= 66 then
					SetVehicleDoorsLocked(vehicle, 1)
					SetVehicleDoorsLockedForAllPlayers(vehicle, false)
					local Plate = GetVehicleNumberPlateText(vehicle)
					TriggerServerEvent('shorty_slocks:breakIn', Plate)
					ClearPedTasksImmediately(playerPed)
					ESX.ShowNotification(_U('veh_unlocked'))
				else
					ESX.ShowNotification(_U('hijack_failed'))
					ClearPedTasksImmediately(playerPed)

Menu

		elseif data.current.value == 'hijack_vehicle' then
			local playerPed = PlayerPedId()
			local vehicle   = ESX.Game.GetVehicleInDirection()
			local coords    = GetEntityCoords(playerPed)
			local Plate		= GetVehicleNumberPlateText(vehicle)

			if IsPedSittingInAnyVehicle(playerPed) then
				ESX.ShowNotification(_U('inside_vehicle'))
				return
			end

			if DoesEntityExist(vehicle) then
				isBusy = true
				TaskStartScenarioInPlace(playerPed, 'WORLD_HUMAN_WELDING', 0, true)
				Citizen.CreateThread(function()
					Citizen.Wait(120000)

					TriggerServerEvent('shorty_slocks:breakIn', Plate)
					SetVehicleDoorsLocked(vehicle, 1)
					SetVehicleDoorsLockedForAllPlayers(vehicle, false)
					ClearPedTasksImmediately(playerPed)

					ESX.ShowNotification(_U('vehicle_unlocked'))
					isBusy = false
				end)
			else
				ESX.ShowNotification(_U('no_vehicle_nearby'))
			end

Blow pipe (not tested)

RegisterNetEvent('esx_mechanicjob:onHijack')
AddEventHandler('esx_mechanicjob:onHijack', function()
	local playerPed = PlayerPedId()
	local coords    = GetEntityCoords(playerPed)

	if IsAnyVehicleNearPoint(coords.x, coords.y, coords.z, 5.0) then
		local vehicle
		local Plate		= GetVehicleNumberPlateText(vehicle)

		if IsPedInAnyVehicle(playerPed, false) then
			vehicle = GetVehiclePedIsIn(playerPed, false)
		else
			vehicle = GetClosestVehicle(coords.x, coords.y, coords.z, 5.0, 0, 71)
		end

		local chance = math.random(100)
		local alarm  = math.random(100)

		if DoesEntityExist(vehicle) then
			if alarm <= 33 then
				SetVehicleAlarm(vehicle, true)
				StartVehicleAlarm(vehicle)
			end

			TaskStartScenarioInPlace(playerPed, 'WORLD_HUMAN_WELDING', 0, true)

			Citizen.CreateThread(function()
				Citizen.Wait(20000)
				if chance <= 66 then
					--TriggerServerEvent('shorty_slocks:breakIn', Plate)
					SetVehicleDoorsLocked(vehicle, 1)
					SetVehicleDoorsLockedForAllPlayers(vehicle, false)
					ClearPedTasksImmediately(playerPed)
					ESX.ShowNotification(_U('veh_unlocked'))
				else
					ESX.ShowNotification(_U('hijack_failed'))
					ClearPedTasksImmediately(playerPed)
				end
			end)
		end
	end
end)
1 Like

how would i make this standalone and ONLY make it to where all NPC cars are locked automatically with a change of being unlocked or being able to break into because i really dont need the other things and Im not ESX

Thank you so much! Your menu code worked perfectly! The blowpipe code did not, however, I changed the local vehicle code on the blowpipe to match yours from the menu and that fixed it. The blowpipe code that works for me:

RegisterNetEvent('esx_mechanicjob:onHijack')
AddEventHandler('esx_mechanicjob:onHijack', function()
	local playerPed = PlayerPedId()
	local coords    = GetEntityCoords(playerPed)

	if IsAnyVehicleNearPoint(coords.x, coords.y, coords.z, 5.0) then
		local vehicle   = ESX.Game.GetVehicleInDirection()
		local Plate		= GetVehicleNumberPlateText(vehicle)

		if IsPedInAnyVehicle(playerPed, false) then
			vehicle = GetVehiclePedIsIn(playerPed, false)
		else
			vehicle = GetClosestVehicle(coords.x, coords.y, coords.z, 5.0, 0, 71)
		end

		local chance = math.random(100)
		local alarm  = math.random(100)

		if DoesEntityExist(vehicle) then
			if alarm <= 33 then
				SetVehicleAlarm(vehicle, true)
				StartVehicleAlarm(vehicle)
			end

			TaskStartScenarioInPlace(playerPed, 'WORLD_HUMAN_WELDING', 0, true)

			Citizen.CreateThread(function()
				Citizen.Wait(10000)
				if chance <= 66 then
					TriggerServerEvent('shorty_slocks:breakIn', Plate)
					SetVehicleDoorsLocked(vehicle, 1)
					SetVehicleDoorsLockedForAllPlayers(vehicle, false)
					ClearPedTasksImmediately(playerPed)
					ESX.ShowNotification(_U('veh_unlocked'))
				else
					ESX.ShowNotification(_U('hijack_failed'))
					ClearPedTasksImmediately(playerPed)
				end
			end)
		end
	end
end)

I also had an issue where the remote locks stopped working for owned vehicles, but I fixed it by just reinstalling the plugin and moving it to the bottom of my load order. Everything works great now! Cheers.

1 Like

how to do this work for esx_advancedvehicleshop and esx_advancedgarage ?? please help

Put the calls in the correct place on the script that have been provided.

i dont know to put where can you please help me to do that?

I dont use either of those scripts buddy, but pretty sure if you read the comments this has already been addressed.

bug

Double lock does not work :frowning:

Great script :slight_smile:

Yes it does

Thanks Buddy!

How can we do it?

Press the lock button twice while inside a vehicle
Default [ L ]

I do, says locked but not locked.

The you have a script conflicting with this, sorry cant help with what as there are loads that could