IsVehicleLocked: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 13: Line 13:


==Example==
==Example==
This example creates a vehicle, then displays if it is locked or not in the chatbox (vehicles are created unlocked).
<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">
newcar = createVehicle ( 520, 1024, 1024, 1024 )
function lockcar ( thePlayer )
if isVehicleLocked ( newcar ) then
    playervehicle = getPlayerOccupiedVehicle ( thePlayer )   -- define 'playervehicle' as the vehicle the player is in
    outputChatBox ( "Vehicle is locked." )
    if ( playervehicle ) then                               -- if a player is in a vehicle
else
        if isVehicleLocked ( playervehicle ) then            -- and if the vehicle is already locked
    outputChatBox ( "Vehicle is unlocked." )
            setVehicleLocked ( playervehicle, false )       -- unlock it
        else                                                 -- otherwise (if it isn't locked)
            setVehicleLocked ( playervehicle, true )         -- lock it
        end
    end
end
end
function bindLockOnSpawn ( theSpawnpoint )                    -- when a player spawns
    bindKey ( source, "l", "down", "Lock car", lockcar )    -- bind the 'l' key to the 'lockcar' function
end
addEventHandler ( "onPlayerSpawn", getRootElement(), bindLockOnSpawn )    -- add an event handler for onPlayerSpawn
</syntaxhighlight>
</syntaxhighlight>
</section>


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

Revision as of 16:51, 29 August 2007

This will tell you if a vehicle is locked.

Syntax

bool isVehicleLocked ( vehicle theVehicle )

Required Arguments

  • theVehicle: The vehicle that you want to obtain the locked status of.

Returns

Returns true if the vehicle specified is locked, false if is unlocked or the vehicle specified is invalid.

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", "Lock car", lockcar )     -- bind the 'l' key to the 'lockcar' function
end
addEventHandler ( "onPlayerSpawn", getRootElement(), bindLockOnSpawn )     -- add an event handler for onPlayerSpawn

See Also