-1 always return driver.
Also, funny thing: if I use among other natives
SetVehicleDoorsLocked(targetcar, 2)
Ped driver teleports through car outside, tries to open and leaves on foot. If I don’t use it, my character tries to open and then just breaks the glass and opens the door.
God damn.
Citizen.CreateThread(function()
while true do
Citizen.Wait(0)
local playerPed = GetPlayerPed(-1)
if IsPedGettingIntoAVehicle(playerPed) then
veh = GetVehiclePedIsTryingToEnter(playerPed)
if GetVehicleClass(veh)== 18 then
SetVehicleDoorsLocked(veh,0)
SetVehicleNeedsToBeHotwired(veh,false)
end
end
end
end)
Works like a charm actually. But each class needs to be added that you want locked. and change to (veh, 3) for players only and (veh, 2) to lock for all, including peds I think.
Pleasa try to add your change and let me know … when i’m will be back at my home. .I will try to debug with veh for ped-1 if in your side you don’t have succes
-- Define a function that locks a given vehicle
function lock_vehicle(vehicle)
-- Set the vehicle's door lock state to locked
SetVehicleDoorsLocked(vehicle, 2)
-- Print a message
print("Vehicle " .. vehicle.name .. " locked")
end
-- Register a "resource ready" event handler
AddEventHandler("onClientResourceReady", function()
-- Get a list of all vehicles in the game world
local vehicles = GetAllVehicles()
-- Iterate over the list of vehicles
for _, vehicle in ipairs(vehicles) do
-- Lock the vehicle
lock_vehicle(vehicle)
end
end)
This script defines a lock_vehicle() function that takes a vehicle argument and locks the vehicle by calling the SetVehicleDoorsLocked() function with a value of 2 (which means locked). It then registers an event handler for the onClientResourceReady event, which is triggered when the script is loaded and all required resources are ready. The event handler iterates over a list of all vehicles in the game world and calls the lock_vehicle() function for each vehicle to lock it.
After running this script, all vehicles in the game world will be locked on world start. This can be useful for preventing players from accessing or stealing vehicles in certain situations, such as when vehicles are being transported or when they are being used in a specific game mode.