OnVehicleEnter: 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 event}}
This event is triggered when a player enters a vehicle.
This event is triggered when a player enters a vehicle.


==Syntax==  
==Parameters==  
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
void onVehicleEnter ( player player, int seat, player jacked )
player player, int seat, player jacked
</syntaxhighlight>  
</syntaxhighlight>  


==Variables==
* The source of this event is the [[vehicle]] that is being entered by a ''player''.
*'''player''': A player element representing the player who is entering the vehicle
*'''player''': A player element representing the player who is entering the vehicle
*'''seat''': An integer representing the seat in which the player is entering
*'''seat''': An integer representing the seat in which the player is entering
*'''jacked''': A player element representing a player who has been jacked
*'''jacked''': A player element representing a player who has been jacked
==Source==
The [[event system#Event source|source]] of this event is the [[vehicle]] that was entered.


==Example==  
==Example==  
This example forces a player out of a police vehicle if he is not a policeman.
'''Example 1:''' This example forces a player out of a police vehicle if he is not a policeman.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
addEventHandler ( "onVehicleEnter", getRootElement(), "vehicleEnter" ) --add an event for onPlayerEnterVehicle
policeVehicles { [598]=true,[596]=true,[597]=true,[599]=true }
function vehicleEnter ( player, seat, jacked ) --when a player enters a vehicle
policeSkins { [280]=true,[281]=true,[282]=true,[283]=true,[284]=true,[285]=true,[286]=true }
     if ( source == 598 or 596 or 597 or 599 ) and ( getPlayerSkin ( player ) ~= 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 ( player, seat, jacked ) --when a player enters a vehicle
     if ( policeVehicles[getVehicleID(source)] ) and ( not policeSkins[getPlayerSkin(player)] ) then --if the vehicle is one of 4 police cars, and the skin is not a police skin
         removePlayerFromVehicle ( player )--force the player out of the vehicle
         removePlayerFromVehicle ( player )--force the player out of the vehicle
         outputChatBox ( "Only policeman can enter police cars!", player ) --and tell the player why
         outputChatBox ( "Only policeman can enter police cars!", player ) --and tell the player why
     end
     end
end
addEventHandler ( "onVehicleEnter", getRootElement(), enterVehicle ) --add an event for onPlayerEnterVehicle
</syntaxhighlight>
</syntaxhighlight>


This example adds a 'moto' helmet to a player when he gets on a nrg bike, and removes it when he gets off.
'''Example 2:''' This example adds a 'moto' helmet to a player when he gets on a nrg bike, and removes it when he gets off.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
addEventHandler ( "onVehicleEnter", getRootElement(), "onEnterVehicle" )
function addHelmetOnEnter ( player, seat, jacked )
function onEnterVehicle ( player, seat, jacked )
   if ( getVehicleID ( source ) == 522 ) then -- if its a nrg
   if ( getVehicleID ( source ) == 522 ) then -- if its a nrg
     addPlayerClothes ( player, "moto", "moto", 16 ) -- add the helmet
     addPlayerClothes ( player, "moto", "moto", 16 ) -- add the helmet
   end
   end
end
end
addEventHandler ( "onVehicleEnter", getRootElement(), addHelmetOnEnter )


addEventHandler ( "onVehicleExit", getRootElement(), "onExitVehicle" )
function removeHelmetOnExit ( player, seat, jacked )
function onExitVehicle ( player, seat, jacked )
   if ( getVehicleID ( source ) == 522 ) then -- if its a nrg
   if ( getVehicleID ( source ) == 522 ) then -- if its a nrg
     removePlayerClothes ( player, 16 ) -- remove the helmet
     removePlayerClothes ( player, 16 ) -- remove the helmet
   end
   end
end
end
addEventHandler ( "onVehicleExit", getRootElement(), removeHelmetOnExit )
</syntaxhighlight>
</syntaxhighlight>


==See Also==
==See Also==
{{Event_functions}}
{{Event_functions}}

Revision as of 14:09, 22 October 2007

This event is triggered when a player enters a vehicle.

Parameters

player player, int seat, player jacked
  • player: A player element representing the player who is entering the vehicle
  • seat: An integer representing the seat in which the player is entering
  • jacked: A player element representing a player who has been jacked

Source

The source of this event is the vehicle that was entered.

Example

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

policeVehicles { [598]=true,[596]=true,[597]=true,[599]=true }
policeSkins { [280]=true,[281]=true,[282]=true,[283]=true,[284]=true,[285]=true,[286]=true }

function enterVehicle ( player, seat, jacked ) --when a player enters a vehicle
    if ( policeVehicles[getVehicleID(source)] ) and ( not policeSkins[getPlayerSkin(player)] ) then --if the vehicle is one of 4 police cars, and the skin is not a police skin
        removePlayerFromVehicle ( player )--force the player out of the vehicle
        outputChatBox ( "Only policeman can enter police cars!", player ) --and tell the player why
    end
end
addEventHandler ( "onVehicleEnter", getRootElement(), enterVehicle ) --add an event for onPlayerEnterVehicle

Example 2: This example adds a 'moto' helmet to a player when he gets on a nrg bike, and removes it when he gets off.

function addHelmetOnEnter ( player, seat, jacked )
  if ( getVehicleID ( source ) == 522 ) then -- if its a nrg
    addPlayerClothes ( player, "moto", "moto", 16 ) -- add the helmet
  end
end
addEventHandler ( "onVehicleEnter", getRootElement(), addHelmetOnEnter )

function removeHelmetOnExit ( player, seat, jacked )
  if ( getVehicleID ( source ) == 522 ) then -- if its a nrg
    removePlayerClothes ( player, 16 ) -- remove the helmet
  end
end
addEventHandler ( "onVehicleExit", getRootElement(), removeHelmetOnExit )

See Also