[Release] No more NPC/parked vehicle stealing

This is a slightly simpler version that can be expanded on as needed. It does two things.

  1. If entering a vehicle, set the driver “CanBeDraggedOut” to false, preventing car jacking. Players/peds can no longer drag someone out and steal the vehicle.

  2. If the vehicle is locked and requires the window to be broken, lock the doors (2 vs 7), protecting the vehicle. Windows can no longer be broken to get into the vehicle. I think 80% of the vehicles spawn locked.

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)
6 Likes

so does this work properly or?

nice one now i need some lockpicks for vdk_inventory xD
like 20% chance or something not 2 high

Where does the 7 from lock == 7 comes from ?

local lock GetVehicleDoorLockStatus(veh)

7 seems to be spawned, locked, but can be entered by breaking the windows. setting it to 2, means its locked and windows won’t be broken to gain entry. if you have a system that locks/unlocks cars, it probably uses 1 unlock 2 lock, so this code won’t interfere with that.

made lockpick real quick xD

add into your vdkinv.lua


function DrawMissionText(m_text, showtime)
    ClearPrints()
	SetTextEntry_2("STRING")
	AddTextComponentString(m_text)
	DrawSubtitleTimed(showtime, 1)
end

function ShowNotification(text)
	SetNotificationTextEntry("STRING")
	AddTextComponentString(text)
	DrawNotification(false, false)
end

function use(item)
    if (ITEMS[item].quantity - 1 >= 0) then
        -- Nice var swap for nothing
        TriggerEvent("player:looseItem", item, 1)
        -- Calling the Hunger/Thirst
        if ITEMS[item].type == 2 then
            TriggerEvent("food:eat", ITEMS[item])
        elseif ITEMS[item].type == 1 then
            TriggerEvent("food:drink", ITEMS[item])
        elseif ITEMS[item].type == 3 then
            RepairVehicle()
	        elseif ITEMS[item].type == 4 then
            lockpick()

	        else
            -- Any other type? Drugs??????
            Toxicated()
            Citizen.Wait(3000)
            ClearPedTasks(GetPlayerPed(-1))
            Reality()
        end
    end
end


Citizen.CreateThread(function()
 
  -- Load the animation 
  RequestAnimDict("mini@repair")
  while not HasAnimDictLoaded("mini@repair") do
    Wait(1)
  end
end)

--------------------------------------------------------
function asd()
	  Citizen.Wait(5000)
			SetVehicleFixed(GetVehiclePedIsUsing(GetPlayerPed(-1)))
			SetVehicleDeformationFixed(GetVehiclePedIsUsing(GetPlayerPed(-1)))
			SetVehicleUndriveable(GetVehiclePedIsUsing(GetPlayerPed(-1)), false)
		    ShowNotification("~g~Vehicle is fully Repaired.")
end

function RepairVehicle()
		Citizen.CreateThread(function()
		local ply = GetPlayerPed(-1)
		local plyCoords = GetEntityCoords(ply, 0)
		veh = GetClosestVehicle(plyCoords["x"], plyCoords["y"], plyCoords["z"], 5.001, 0, 70)
		--ClearPedTasksImmediately(GetPlayerPed(-1))
	    --TaskStartScenarioInPlace(GetPlayerPed(-1), "WORLD_HUMAN_VEHICLE_MECHANIC", 0, true)  
        TaskPlayAnim(GetPlayerPed(-1),"mini@repair","fixing_a_player", 8.0, 0.0, -1, 1, 0, 0, 0, 0)		
	    Citizen.Wait(20000)
		SetVehicleFixed(veh, 1)
		SetVehicleDeformationFixed(veh, 1)
		SetVehicleUndriveable(veh, 1)
		ClearPedTasksImmediately(GetPlayerPed(-1))
	  --  ShowNotification("~g~Vehicle is fully Repaired~r~Turn on Engine via Vehicle Menu Key:M or select")
		DrawMissionText("~g~Vehicle is fully Repaired. ~y~Turn on Engine via Vehicle Menu Key:M or select", 30000)
	end)
end

function lockpick()
		Citizen.CreateThread(function()
		local ply = GetPlayerPed(-1)
		local plyCoords = GetEntityCoords(ply, 0)
		veh = GetClosestVehicle(plyCoords["x"], plyCoords["y"], plyCoords["z"], 5.001, 0, 70)
        TaskPlayAnim(GetPlayerPed(-1),"mini@repair","fixing_a_player", 8.0, 0.0, -1, 1, 0, 0, 0, 0)		
		--StartVehicleAlarm(veh)
		StartVehicleAlarm(vehicle)
		StartVehicleAlarm(veh)
	    Citizen.Wait(20000)
        SetVehicleDoorsLocked(veh, 1)
		ClearPedTasksImmediately(GetPlayerPed(-1))
	    --ShowNotification("~g~test")
		DrawMissionText("~y~You unlocked the vehicle", 15000)
		
	end)
end

add item id 19 value 0 type 3, for repair kit can use it on [Release] Car damage system
if u use car dmg better use the code of [Release] Car damage system
additem id 20 value 0 type 4 ,for lockpick into your db and if use gb_foodshops add em into it

u also need MissionText.rar (393 Bytes)

or remove the – on ShowNotification and add em @ DrawMissionText

1 Like

Where are you putting that that?

Tried this, but when i hit use item it closes my menu and nothing happens, i then can not reopen the menu?

How do we make it worth with the garages script im not following your wiki very well

I don’t have a wiki. Stopping ped jacking should have no effect on any other script. And it only stops the window from being broken then locks it.

A garage car should spawn 1 unlocked or 2 locked, which excludes my script from effecting it.

Anywhere? Make a resource. Add it to a resource.

Yep I got it. Somewhere this post got hijacked and I got confused which is which.

if you own a vehicle and someone is trying to steal it and does not success - it gets locked for everyone?

May be add some animation for trying open door?

I have a problem, this is a great plugin but on the lastVeh.GetNetworkID() always return 0, there should be a delay. Soo every car return as locked and only for luck or only if you spawn inside a car that car will be unlocked for you.
I tried to add an away after the lastVeh.GetNetworkID() this work a bit but inside the update the problem is when you retrieve the car from the networkid, I have some error.

Try to write a debug.write(lastVeh.GetNetworkID()) to see if you have the same problem.

If the NPC leaves the car or dies the doors should unlock and stay unlocked

I did exacly as instructed but i got the error: Could not load resource: NoCarJack

Is there a __resource.lua , without it the server isn’t going to load it. @Jao_Seara

No there isn’t, what should I do?l @Knight_Marshal

Im using it but i can still enter into some vehicles on parking.