Okay, I have done it but I don’t know if it works, I didn’t have time to test it. It should do the work, but if you want better performance then you can check if the player has pressed the F key and is entering any vehicles, also set a little timeout to prevent server spam. If so the script won’t spam server as much
Server side:
ESX.RegisterServerCallback('isVehicleOwned', function(playerId, cb, vehiclePlate)
local xPlayer = ESX.GetPlayerFromId(playerId);
if (not xPlayer) then return end;
MySQL.Async.fetchScalar('SELECT `owner` FROM `owned_vehicles` WHERE @plate = `plate`;', {
['@plate'] = vehiclePlate;
}, function(Owner)
cb(Owner ~= nil)
end)
end)
Client Side:
Citizen.CreateThread(function()
while true do
local playerPed = PlayerPedId();
if DoesEntityExist(playerPed) then
local vehicleHandler = GetVehiclePedIsTryingToEnter(playerPed)
if (vehicleHandler > 0) and DoesEntityExist(vehicleHandler) then
ESX.TriggerServerCallback('isVehicleOwned', function(isOwned)
if (not isOwned) then
local hasWindow = IsVehicleWindowIntact(vehicleHandler, 1); -- Front Left Window AKA Driver Window
if hasWindow then
SetVehicleDoorsLocked(vehicleHandler, 2)
else
SetVehicleDoorsLocked(vehicleHandler, 1)
end
end
end)
end
end
Wait(100)
end
end)