How to lock all cars (parked, with drivers etc) on the map at the start of the server without possibility to hijack it?
We can use
SetVehicleDoorsLocked(car, 2)
SetVehicleDoorsLockedForPlayer(car, PlayerId(), 2)
To lock doors for players, but how can we apply it to ALL cars on the map except personal?
Where did you find this dude ?
Nowhere, I found those natives, but still don’t know how to lock cars all cars at server start. Help is needed.
I was asking myself the same question or quite. What would be awesome would be letting only players’s car open. So no more free ride except if you steal a car from a player
Yet still no solution except scanning all cars around player and locking them, which is totally bad for perfomance.
Did you find how to do it?
I have find a native function which could be interesting :
void SET_PLAYER_MAY_ONLY_ENTER_THIS_VEHICLE(Player player, Vehicle vehicle)
A more easier way would to do a loop through all the entities in the game or just the vehicles in the game and loop and lock them all. Hope it helps!, Good Luck
And never sit in friend’s car or a taxi
You do realize that cars spawn and despawn all the time?
Just loop the script each X minutes/ seconds?
And eventually kill tickrate with all the loops that server uses. I was hoping there is a rule that we can set on map init.
You do know you can set a timer on the loop?? Bloody hell some people really are dumb. Just do it every 5 mins.
One man said: “Sometimes, when you look into mirror, it talks to you”.
So, all cars spawned between 5 mins will be unlocked. And there will be a lot of them. Loop is the poorest choice here, actually, that’s why I am asking all the devs about different approach, if any.
So any news on this ?
Unfortunatly no. I am asking again for some help
anybody find any info on this yet .1 of the main thangs im looking for right now
The only way I see now is to constantly scan area around player, detect every car and lock it. RIP server.
Or (if you can), detect when a player is about to enter a car. If it’s not owned by a player stop them from entering and lock the car for all players…
I don’t know how viable this is but, it would be better than a constant scan
Yeah, just found this native
function GetVehiclePedIsTryingToEnter(ped)
return _in(0x814FA8BE5449445D, ped, _r)
end
Didn’t know that existed
So, you could do something like (haven’t tested) this. It should stop players from entering vehicles that aren’t owned by them.
Note: It means that spawned cars need to have their owner set (maybe N_0x97ce68cb032583f0
?)
Example..
Citizen.CreateThread(function()
Citizen.Wait(500) -- Run every half a seond
local enterVeh = GetVehiclePedIsTryingToEnter( GetPlayerPed(-1) ) -- Get the vehicle player is trying to enter (nil if not trying to enter?)
if (enterVeh ~= nil) then -- If they're trying to enter one
local playerOwned = false -- Replace with Citizen.Invoke for "GET_VEHICLE_HAS_BEEN_PLAYER_OWNED" (can't find it)
local ownerOfVehicle = GetVehicleOwner(enterVeh) -- Get the owner of the vehicle
if (ownerOfVehicle ~= GetPlayerId()) then -- They don't own the car, don't let them enter
SetVehicleDoorsLockedForPlayer(enterVeh, PlayerId(), true) -- Lock the doors of the car.
end
if not playerOwned then -- If this hasn't been owned by a player
SetVehicleDoorsLockedForPlayer(enterVeh, PlayerId(), true) -- Lock the doors of the car.
end
end
end)
There is a way to tell if the vehicle has been owned by the player (there’s a SetVehicleHasBeenOwnedByPlayer
so, there has to be a getter native) but, I can’t find the native that get’s the value .
Edit:
You can then also check if the vehicle is being driven (or, if there’s someone in the drivers seat) by using the GetPedInVehicleSeat
native (I think 0 is the driver seat).