SetVehicleLocked: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
 
No edit summary
 
(9 intermediate revisions by 4 users not shown)
Line 1: Line 1:
[[Category:Incomplete]]
__NOTOC__
 
{{Server client function}}
__NOTOC__
This function can be used to set the vehicle's doors to be locked or unlocked.  Locking a vehicle restricts access to the vehicle.
This fake function is for use with blah & blah and does blahblahblabhalbhl
{{warning|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==  
==Syntax==  
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
bool setVehicleLocked ( element vehicle, bool locked )             
bool setVehicleLocked ( vehicle theVehicle, bool locked )             
</syntaxhighlight>  
</syntaxhighlight>
{{OOP||[[vehicle]]:setLocked|locked|isVehicleLocked}}


===Required Arguments===  
===Required Arguments===  
*'''argumentName:''' description
*'''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
===Optional Arguments===
{{OptionalArg}}
*'''argumentName2:''' descriptiona
*'''argumentName3:''' description


===Returns===
===Returns===
Returns ''true'' if blah, ''false'' otherwise.
Returns ''true'' if the operation was successful, ''false'' otherwise.


==Example==  
==Example==
This example does...
<section name="Server" class="server" show="true">
This example allows a player to lock his vehicle when he is inside it.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
--This line does...
function lockcar ( thePlayer )
blabhalbalhb --abababa
    playervehicle = getPlayerOccupiedVehicle ( thePlayer )  -- define 'playervehicle' as the vehicle the player is in
--This line does this...
    if ( playervehicle ) then                                -- if a player is in a vehicle
mooo
        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
</syntaxhighlight>
</syntaxhighlight>
</section>


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

Latest revision as of 08:31, 4 November 2020

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

[[|link=|]] Warning: 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

bool setVehicleLocked ( vehicle theVehicle, bool locked )            

OOP Syntax Help! I don't understand this!

Method: vehicle:setLocked(...)
Variable: .locked
Counterpart: isVehicleLocked


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

Click to collapse [-]
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