SetVehicleLocked: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 1: Line 1:
__NOTOC__  
__NOTOC__
{{Server client function}}
This function can be used to set a vehicle to be locked or unlocked
This function can be used to set a vehicle to be locked or unlocked


==Syntax==  
==Syntax==  
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
bool setVehicleLocked ( element vehicle, bool locked )             
bool setVehicleLocked ( vehicle theVehicle, bool locked )             
</syntaxhighlight>  
</syntaxhighlight>


===Required Arguments===  
===Required Arguments===  
*'''vehicle:''' The vehicle which you wish to change the lock status of
*'''theVehicle:''' 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
*'''locked:''' Boolean for the status you wish to set. Set ''true'' to lock, ''false'' to unlock


Line 14: Line 15:
Returns ''true'' if the operation was successful, ''false'' otherwise.
Returns ''true'' if the operation was successful, ''false'' otherwise.


==Example==  
==Example==
This example allows a player to lock is vehicle when he is inside it.
This example allows a player to lock his vehicle when he is inside it.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
addEventHandler ( "onPlayerSpawn", root, "onPlayerSpawn" ) --add an event handler for onPlayerSpawn
function lockcar ( thePlayer )
function onPlayerSpawn ( spawnpoint ) --when a player spawns
    playervehicle = getPlayerOccupiedVehicle ( thePlayer )   -- define 'playervehicle' as the vehicle the player is in
    bindKey ( source, "l", down, "lockcar", source ) --bind the 'l' key to the 'lockcar' function
    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
end


function lockcar ( player )
function onPlayerSpawn ( theSpawnpoint )                     -- when a player spawns
    playervehicle = getPlayerOccupiedVehicle ( player ) --define 'playervehicle' as the vehicle the player is in
     bindKey ( source, "l", "down", "Lock car", lockcar )     -- bind the 'l' key to the 'lockcar' function
     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
end
addEventHandler ( "onPlayerSpawn", root, onPlayerSpawn )    -- add an event handler for onPlayerSpawn
</syntaxhighlight>
</syntaxhighlight>


==See Also==
==See Also==
{{Vehicle functions}}
{{Vehicle functions}}

Revision as of 19:46, 15 August 2007

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

Syntax

bool setVehicleLocked ( vehicle theVehicle, bool locked )            

Required Arguments

  • theVehicle: 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 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 onPlayerSpawn ( theSpawnpoint )                     -- when a player spawns
    bindKey ( source, "l", "down", "Lock car", lockcar )     -- bind the 'l' key to the 'lockcar' function
end
addEventHandler ( "onPlayerSpawn", root, onPlayerSpawn )     -- add an event handler for onPlayerSpawn

See Also