setVehicleLocked | Multi Theft Auto: Wiki Skip to content

setVehicleLocked

Client-side
Server-side
Shared

Pair: isVehicleLocked

This page is incomplete! Help wanted!

Please finish this page using the corresponding Old Wiki article.
Go to Contribution guidelines for more information.


This function can be used to set the vehicle's doors to be locked or unlocked. Locking a vehicle restricts access to the vehicle.

Caution

This function only prevents the player from opening the vehicle doors. It means that a player can still access a locked vehicle if there's an opened door. Also, vehicles that doesn't have doors can still be accessed aswell.

Syntax

setVehicleLocked ( )

Code Examples

server

This example allows a player to lock his vehicle when he is inside it.

function lockcar ( thePlayer )
playervehicle = getPlayerOccupiedVehicle ( thePlayer ) -- define 'playervehicle' as the vehicle the player is in
if ( playervehicle ) then -- if a player is in a vehicle
if isVehicleLocked ( playervehicle ) then -- and if the vehicle is already locked
setVehicleLocked ( playervehicle, false ) -- unlock it
else -- otherwise (if it isn't locked)
setVehicleLocked ( playervehicle, true ) -- lock it
end
end
end
function bindLockOnSpawn ( theSpawnpoint ) -- when a player spawns
bindKey ( source, "l", "down", lockcar ) -- bind the 'l' key to the 'lockcar' function
end
addEventHandler ( "onPlayerSpawn", root, bindLockOnSpawn ) -- add an event handler for onPlayerSpawn

See Also

Vehicle Functions