Hello, I have made I little script here using esx_nocarjack’s help:

Citizen.CreateThread(function()
	while true do
		Citizen.Wait(0)
		local veh = GetVehiclePedIsTryingToEnter(PlayerPedId())
		local window = IsVehicleWindowIntact(veh, 0)
		if window then
			TriggerEvent('esx_nocarjack:setVehicleDoors')
		else
			SetVehicleDoorsLocked(veh, 1)
			SetVehicleDoorsLockedForAllPlayers(veh, false)
		end
	end
end)

My question is how could I make so if you break a player owned vehicles window you can’t enter, but if you break NPC car window you can enter.

Thanks!

1 Like

sames, do you solve your problem ??

I have te solution, you have to receive data from database and then look if the car is owned by someone. You can do it using server callbacks, but dont use server callbacks in loop client side it can cause performance issues. I can help if anything wont work out.

1 Like

Thank you so much, i will try cause i’m really interested about it, athnk you again , i appreciate it

can you share with me your function that’s i can use in esx_nocarjack ??

As I don’t know what you use and have I don’t know how to help you at the moment, are you using ESX?
and have owned_vehicles table in database>

Yes, i have i just want can only break window of npc cars and steal it, but the owned cars no

It is quite a work actually, I have no time to write such thing at the moment. Sorry i’m just working developer at big server :smiley:

I can pay you, if that what you want ,i have no problem, it’s your choice

Okay, what you want players to cant access NPC vehicles if windows are not broken? And it won’t work for player-owned vehicles?

Player can access to NPC vehicles ,broke the window and steal it. but can’t broke owned vehicle i mean the players vehicles .

Okey, take your time !!

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)

Okeey Wait, i will try it now

It’s not working :frowning: and i get a error , this function will only lock all cars

You are not initializing ESX.

Add this to the top of the fail:

ESX = nil;

Citizen.CreateThread(function()
	while ESX == nil do
		TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
		Wait(0)
	end

	Wait(1000)

	while not ESX.IsPlayerLoaded() do
		Wait(10)
	end
end)

You right i forget hahaha .i will try again

Now no errors, but still same problem, didn’t break the windows and get in, nothing to do i think about that .

Make sure other scripts are not interfering with this.
If this doesn’t work then you can figure it out from there I gave you a head start :smiley:

Citizen.CreateThread(function()
    while true do

        local playerPed = PlayerPedId();
        if DoesEntityExist(playerPed) then
            local vehicleHandler = GetVehiclePedIsTryingToEnter(playerPed)

            if (vehicleHandler > 0) and DoesEntityExist(vehicleHandler) then
                SetVehicleDoorsLocked(vehicleHandler, 2);

                ESX.TriggerServerCallback('isVehicleOwned', function(isOwned)
                    if (not isOwned) then
                        local hasWindow = IsVehicleWindowIntact(vehicleHandler, 1); -- Front Left Window AKA Driver Window

                        if (not hasWindow) then
                            SetVehicleDoorsLocked(vehicleHandler, 1);
                        end
                    end
                end)
            end
        end

        Wait(100)
    end
end)

I’m sure that no scripts interfering with this !!
and now i’m getting this

Thank you for your help !! i really appriciate it, i hope if i can get the solution of that .