SetVehicleLocked

From Multi Theft Auto: Wiki
Revision as of 20:15, 13 August 2006 by Talidan (talk | contribs)
Jump to navigation Jump to search

This function can be used to set a vehicle to be locked or unlocked

Syntax

bool setVehicleLocked ( element vehicle, bool locked )            

Required Arguments

  • vehicle: The vehicle which you wish to change the lock status of
  • locked: Boolean for the status you wish to set. Set true to lock, false to unlock

Returns

Returns true if the operation was successful, false otherwise.

Example

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

addEventHandler ( "onPlayerSpawn", root, "onPlayerSpawn" ) --add an event handler for onPlayerSpawn
function onPlayerSpawn ( spawnpoint ) --when a player spawns
    bindKey ( source, "l", down, "lockcar", source ) --bind the 'l' key to the 'lockcar' function
end

function lockcar ( player )
    playervehicle = getPlayerOccupiedVehicle ( player ) --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 isnt locked) 
            setVehicleLocked ( playervehicle, true ) --lock it
        end
    end
end

See Also