oh yes i realized that once I implemented it. However I found a bug. Sometimes script breaks (a lot) and the system won’t work if you buy a car. But it will work perfectly on stolen cars.
Deed, You should impliment this into your code, It locks all NPC vehicles (to a point) but needs to be worked upon
That way we can one, Only get keys to vehicles we have either spawned or purchased
two, It adds for some realism
Citizen.CreateThread(function()
while true do
if DoesEntityExist(GetVehiclePedIsTryingToEnter(PlayerPedId())) then
local veh = GetVehiclePedIsTryingToEnter(PlayerPedId())
local lock = GetVehicleDoorLockStatus(veh)
if lock == 7 then
SetVehicleDoorsLocked(veh, 2)
end
local pedd = GetPedInVehicleSeat(veh, -1)
if pedd then
SetPedCanBeDraggedOut(pedd, false)
end
end
Citizen.Wait(0)
end
end)
just realized that your not using interact sounds PlayWithinDistance setting to have everyone in the local area hear the lock , could you possibly make your next version use that method so everyone in the area can hear the locks? (will help when people are trying to get into a car and you have to tell them wait im unlocking it , theyl just hear it and know like in irl ) much thanks as always
I made a mistake in the script for random messages. I’m not here on the weekend so I’ll correct that when I come back.
I think adding PlayWithinDistance is a good idea but for other suggestions it should not be forgotten that it is a public script for lock / unlock. I can possibly do another version of the script for those who want the NPC cars to lock but that’s all.
If I limit the script too much by a percentage of steal or forbidding police cars then this may displease a lot of people. I hope you understand. For this you will have to code it yourself
For those who want to fix the bug that sometimes prevents the player from having the keys. Replace the randomMsg function in server.lua with :
function RandomMsg()
random = math.random(1, 5)
if random == 1 then randomMsg = "You have found the keys on the sun-shield." end
if random == 2 then randomMsg = "You found the keys in the glove box." end
if random == 3 then randomMsg = "You found the keys on the passenger seat." end
if random == 4 then randomMsg = "You found the keys on the floor." end
if random == 5 then randomMsg = "The keys were already on the contact, you took them." end
return randomMsg
end
I’ve tested some situation for this plugin.
I’ve tried to spawn a vehicule take the keys, drive a little bit, go out and lock the car.
Then, i’ve spawned a second car and done the same actions.
I have the key for the two car so, i can lock/unlock them, but engine doesnt turn on.
I have the same problem. I can get out and get back in and it starts right back up but if i get out, lock the car, unlock the car, and then get back in it won’t start. I have tried it with several different vehicles and it’s always the same results.