Synced Vehicle Locks, with Lock all NPC cars

hello,
i have a problem which is if someone buy a new car he can not lock it untill i restart script or server.

2 Likes

in server/main.lua

Found This

AddEventHandler('onResourceStart', function(resource)
	if resource == GetCurrentResourceName() then
		while not SQLReady do Wait(0) end		
		getvehiclesList()
	end
end)

And replace with this

AddEventHandler('onResourceStart', function(resource)
	if resource == GetCurrentResourceName() then
		Citizen.CreateThread(function()
			while true do
				Citizen.Wait(300000)
				getvehiclesList()
			end
		end)
	end
end)

this will reload plate numbers in 5 min if you want you can change the “Citizen.Wait(300000)” ms section.

1 Like

thanks alot man <3

Please can you help me with lockpick item? Doesnt work for me

hey man, it works fine but it have a problem, after 5 minutes the doors lock automatically, it means if someone steal your car, or you gave your car to a friend and he get out of the car, he cant get back in car after 5 minutes, is there a way to fix it?

Well, thats literally what that piece of code does, every 5 min it will query all the owned vehicles and set them to the default value in config.

I still can’t lock the cars after buying a new one, even with the code change

anyway to fix it?

I wouldn’t use that code that’s been provided anything that makes the server go into an endless loop is not good.

I will be adding a better readme soon, also going to be releasing an updated version not to long away with the option to call the sql, I personally don’t like calling the sql every time you press the unlock button but seems people struggle with small modifications to there scripts.

probably edit the getvehiclelist function and instead of overriding:

vehicle_data[plateStripped] = { owner = result[i].owner, lockstatus = Config.defLock }

try to find that plateStripped first and keep the previous value if it exists

Can you explain your problem step by step I can’t understand.
I can try to help when I understand the problem.

Use my git repo if you can’t replace code.
THIS IS NOT ORIGINAL SCRIPT.

hello, thanks for help.
if i use the default vehicle lock script, the script worked and lock all cars and also owned vehicles, but when someone buy a new vehicle, then the person is not able to lock the vehicle until next restart.
when i use the code you gave me, this problem fixed and they can lock their vehicle after 5 minutes they buy, but the problem of that code is the script lock all car doors each 5 minutes so if i give my car to a friend to do something with it, after 5 minutes it will get auto lock and my friend will not be able to drive it any more.
i hope you understand me now :slight_smile:

in config.lua

if your

Config.defLock = true

then replace with false.

Config.defLock = false

When it is done try after that If you are still getting the error reply this then I will look the code one more time :slight_smile:

thanks bro i will try after players go to sleep cuz if i restart resource my anticheat will kick everyone for injection and resource stop :stuck_out_tongue:
ill let you know soon
thanks again for help

No, problem If you getting any problem with any script.
pm to me I can look when I have free time. :slightly_smiling_face:

I will also try it when the players are not there for the anticheat

hey man, when i use this script, also police officers can not open the lock with hijack menu.

1 Like

same here. I tried adding and modifying the calls and nothing worked.

whats the keybind