OnPlayerVehicleEnter

From Multi Theft Auto: Wiki
Revision as of 05:26, 30 December 2007 by ChrML (talk | contribs) (New page: __NOTOC__ {{Server event}} This event is triggered when a player enters a vehicle. ==Parameters== <syntaxhighlight lang="lua"> vehicle theVehicle, int seat, player jacked </syntaxhighlight> *'''theVehicle''': ...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

This event is triggered when a player enters a vehicle.

Parameters

vehicle theVehicle, int seat, player jacked
  • theVehicle: A vehicle element representing the vehicle that was entered
  • 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 player that entered the vehicle.

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 ( vehicle, seat, jacked ) --when a player enters a vehicle
    if ( policeVehicles[getVehicleID(vehicle)] ) and ( not policeSkins[getPlayerSkin(source)] ) 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 policeman can enter police cars!", source ) --and tell the player why
    end
end
addEventHandler ( "onPlayerEnterVehicle", 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 ( vehicle, seat, jacked )
  if ( getVehicleID ( vehicle ) == 522 ) then -- if its a nrg
    addPlayerClothes ( source, "moto", "moto", 16 ) -- add the helmet
  end
end
addEventHandler ( "onPlayerEnterVehicle", getRootElement(), addHelmetOnEnter )

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

See Also