RemovePlayerFromVehicle: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
 
(5 intermediate revisions by 5 users not shown)
Line 1: Line 1:
__NOTOC__  
__NOTOC__
This function removes a player from a vehicle immediately. This works for drivers and passengers. Note that this removes the player from the vehicle and puts him in the exact position where the command was initiated.
{{Server function}}
{{Deprecated|removePedFromVehicle}}
 
This function removes a player from a vehicle immediately. This works for drivers and passengers. Note that this removes the player from the vehicle and puts him in the exact position where the command was initiated.


==Syntax==  
==Syntax==  
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
bool removePlayerFromVehicle ( element player )           
bool removePlayerFromVehicle ( player thePlayer )           
</syntaxhighlight>  
</syntaxhighlight>  


===Required Arguments===  
===Required Arguments===  
*'''player:''' The player you wish to remove from a vehicle
*'''thePlayer:''' The player you wish to remove from a vehicle


===Returns===
===Returns===
Line 16: Line 19:
This example forces a player out of a police vehicle if he is not a policeman.
This example forces a player out of a police vehicle if he is not a policeman.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
addEventHandler ( "onPlayerEnterVehicle", getRootElement(), "enterVehicle" ) --add an event for onPlayerEnterVehicle
local policevehicles = { [596]=true, [597]=true, [598]=true, [599]=true }  -- make a table of police vehicle IDs
function enterVehicle ( vehicle, seat, jacked ) --when a player enters a vehicle
local policeskins = { [283]=true, [284]=true, [285]=true, [286]=true }    -- make a table of police skin IDs
     if ( vehicle == 598 or 596 or 597 or 599 ) and ( getPlayerSkin ( source ) ~= 280 or 281 or 282 or 283 or 284 or 285 or 286 ) then --if the vehicle is one of 4 police cars, and the skin is not a police skin
function enterVehicle ( theVehicle, seat, jacked )                         -- when a player enters a vehicle
         removePlayerFromVehicle ( source )--force the player out of the vehicle
     local skinID = getPlayerSkin ( source )                               -- get his skin ID
         outputChatBox ( "Only policeman can enter police cars!", source ) --and tell the player why
    local vehID = getVehicleID ( theVehicle )
    if policevehicles[vehID] and not policeskins[skinID] then             -- if the vehicle is one of 4 police cars, and the skin is not a police skin
         removePlayerFromVehicle ( source )                                 -- force the player out of the vehicle
         outputChatBox ( "Only policemen can enter police cars!", source ) -- and tell the player why
     end
     end
end
end
addEventHandler ( "onPlayerEnterVehicle", root, enterVehicle ) -- add an event for onPlayerEnterVehicle
</syntaxhighlight>
</syntaxhighlight>


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

Latest revision as of 08:13, 4 November 2020

Emblem-important.png This function is deprecated. This means that its use is discouraged and that it might not exist in future versions.

Please use removePedFromVehicle instead.


This function removes a player from a vehicle immediately. This works for drivers and passengers. Note that this removes the player from the vehicle and puts him in the exact position where the command was initiated.

Syntax

bool removePlayerFromVehicle ( player thePlayer )           

Required Arguments

  • thePlayer: The player you wish to remove from a vehicle

Returns

Returns true if the operation was successful, false otherwise.

Example

This example forces a player out of a police vehicle if he is not a policeman.

local policevehicles = { [596]=true, [597]=true, [598]=true, [599]=true }  -- make a table of police vehicle IDs
local policeskins = { [283]=true, [284]=true, [285]=true, [286]=true }     -- make a table of police skin IDs
function enterVehicle ( theVehicle, seat, jacked )                         -- when a player enters a vehicle
    local skinID = getPlayerSkin ( source )                                -- get his skin ID
    local vehID = getVehicleID ( theVehicle )
    if policevehicles[vehID] and not policeskins[skinID] then              -- if the vehicle is one of 4 police cars, and the skin is not a police skin
        removePlayerFromVehicle ( source )                                 -- force the player out of the vehicle
        outputChatBox ( "Only policemen can enter police cars!", source )  -- and tell the player why
    end
end
addEventHandler ( "onPlayerEnterVehicle", root, enterVehicle ) -- add an event for onPlayerEnterVehicle

See Also