diff --git a/VEHICLE/SetVehicleDoorsLocked.md b/VEHICLE/SetVehicleDoorsLocked.md index 08025e475..050b79624 100644 --- a/VEHICLE/SetVehicleDoorsLocked.md +++ b/VEHICLE/SetVehicleDoorsLocked.md @@ -8,22 +8,86 @@ ns: VEHICLE void SET_VEHICLE_DOORS_LOCKED(Vehicle vehicle, int doorLockStatus); ``` +Locks the doors of a specified vehicle to a defined lock state, affecting how players and NPCs can interact with the vehicle. + +``` +NativeDB Introduced: v323 ``` -// Source GTA VC miss2 leak, matching constants for 0/2/4, testing -// They use 10 in am_mp_property_int, don't know what it does atm. -enum eCarLock { - CARLOCK_NONE = 0, - CARLOCK_UNLOCKED = 1, - CARLOCK_LOCKED = 2, - CARLOCK_LOCKOUT_PLAYER_ONLY = 3, - CARLOCK_LOCKED_PLAYER_INSIDE = 4, - CARLOCK_LOCKED_INITIALLY = 5, - CARLOCK_FORCE_SHUT_DOORS = 6, - CARLOCK_LOCKED_BUT_CAN_BE_DAMAGED = 7 + +```c +enum eVehicleLockState { + VEHICLELOCK_NONE = 0, // No specific lock state, vehicle behaves according to the game's default settings. + VEHICLELOCK_UNLOCKED = 1, // Vehicle is fully unlocked, allowing free entry by players and NPCs. + VEHICLELOCK_LOCKED = 2, // Vehicle is locked, preventing entry by players and NPCs. + VEHICLELOCK_LOCKOUT_PLAYER_ONLY = 3, // Vehicle locks out only players, allowing NPCs to enter. + VEHICLELOCK_LOCKED_PLAYER_INSIDE = 4, // Vehicle is locked once a player enters, preventing others from entering. + VEHICLELOCK_LOCKED_INITIALLY = 5, // Vehicle starts in a locked state, but may be unlocked through game events. + VEHICLELOCK_FORCE_SHUT_DOORS = 6, // Forces the vehicle's doors to shut and lock. + VEHICLELOCK_LOCKED_BUT_CAN_BE_DAMAGED = 7, // Vehicle is locked but can still be damaged. + VEHICLELOCK_LOCKED_BUT_BOOT_UNLOCKED = 8, // Vehicle is locked, but its trunk/boot remains unlocked. + VEHICLELOCK_LOCKED_NO_PASSENGERS = 9, // Vehicle is locked and does not allow passengers, except for the driver. + VEHICLELOCK_CANNOT_ENTER = 10 // Vehicle is completely locked, preventing entry entirely, even if previously inside. }; + ``` ## Parameters -* **vehicle**: -* **doorLockStatus**: +* **vehicle**: The vehicle whose doors are to be locked. +* **doorLockStatus**: The lock state to apply to the vehicle's doors, see `eVehicleLockState`. + +## Examples +```lua +-- Command to lock the car of the player for everyone. +RegisterCommand("lockcar", function() + local playerPed = PlayerPedId() -- Get the player ped + local vehicle = GetVehiclePedIsIn(playerPed, false) -- Get the vehicle the player is in + if (vehicle == 0) then return end -- If the player is not in a vehicle, return + SetVehicleDoorsLocked(vehicle, 2) -- Lock the doors of the vehicle +end, false) + +-- Command to unlock the car of the player for everyone. +RegisterCommand("unlockcar", function() + local playerPed = PlayerPedId() -- Get the player ped + local vehicle = GetVehiclePedIsIn(playerPed, false) -- Get the vehicle the player is in + if (vehicle == 0) then return end -- If the player is not in a vehicle, return + SetVehicleDoorsLocked(vehicle, 1) -- Unlock the doors of the vehicle +end, false) +``` + +```js +// Command to lock the car of the player for everyone. +RegisterCommand("lockcar", () => { + const playerPed = PlayerPedId(); // Get the player ped + const vehicle = GetVehiclePedIsIn(playerPed, false); // Get the vehicle the player is in + if (vehicle === 0) return; // If the player is not in a vehicle, return + SetVehicleDoorsLocked(vehicle, 2); // Lock the doors of the vehicle +}, false); + +// Command to unlock the car of the player for everyone. +RegisterCommand("unlockcar", () => { + const playerPed = PlayerPedId(); // Get the player ped + const vehicle = GetVehiclePedIsIn(playerPed, false); // Get the vehicle the player is in + if (vehicle === 0) return; // If the player is not in a vehicle, return + SetVehicleDoorsLocked(vehicle, 1); // Unlock the doors of the vehicle +}, false); +``` +```csharp +using static CitizenFX.Core.Native.API; + +// Command to lock the car of the player for everyone. +RegisterCommand("lockcar", () => { + Ped playerPed = PlayerPedId(); // Get the player ped + Vehicle vehicle = GetVehiclePedIsIn(playerPed, false); // Get the vehicle the player is in + if (vehicle == 0) return; // If the player is not in a vehicle, return + SetVehicleDoorsLocked(vehicle, 2); // Lock the doors of the vehicle +}, false); + +// Command to unlock the car of the player for everyone. +RegisterCommand("unlockcar", () => { + Ped playerPed = PlayerPedId(); // Get the player ped + Vehicle vehicle = GetVehiclePedIsIn(playerPed, false); // Get the vehicle the player is in + if (vehicle == 0) return; // If the player is not in a vehicle, return + SetVehicleDoorsLocked(vehicle, 1); // Unlock the doors of the vehicle +}, false); +```