OnVehicleExit: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
m (correct event name)
 
(14 intermediate revisions by 11 users not shown)
Line 1: Line 1:
__NOTOC__  
__NOTOC__  
This event is triggered when a player leaves a vehicle.
{{Server event}}
This event is triggered when a player or ped leaves a vehicle.


==Syntax==  
==Parameters==  
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
void onVehicleExit ( player player, int seat, player jacker )
ped thePed, int seat, ped jacker, bool forcedByScript
</syntaxhighlight>  
</syntaxhighlight>  


==Variables==
*'''thePed''': a [[player]] or [[ped]] element who exited the [[vehicle]].
* The source of this event is the vehicle which was exited
*'''seat''': an [[int]] representing the seat in which the ped exited from.
*'''player''': A player element representing the player who exited the vehicle
*'''jacker''': a [[player]] or [[ped]] element who jacked the driver.
*'''seat''': An integer representing the seat in which the player exited from
{{New feature/item|3.0154|1.5.3|11247|
*'''jacker''': A player element representing the player who jacked the driver
*'''forcedByScript:''' a [[boolean]] representing whether the exit was forced using [[removePedFromVehicle]] or by the ped/player.
}}
 
==Source==
The [[event system#Event source|source]] of this event is the [[vehicle]] that was exited.


==Example==  
==Example==  
This example adds a 'moto' helmet to a player when he gets on a nrg bike, and removes it when he gets off.
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 ( thePlayer, seat, jacked )
function onEnterVehicle ( player, seat, jacked )
    if ( getElementModel ( source ) == 522 ) then -- if its a nrg
  if ( getVehicleID ( source ) == 522 ) then -- if its a nrg
        addPedClothes ( thePlayer, "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 ( thePlayer, seat, jacked )
function onExitVehicle ( player, seat, jacked )
    if ( getElementModel ( source ) == 522 ) then -- if its a nrg
  if ( getVehicleID ( source ) == 522 ) then -- if its a nrg
        removePedClothes ( thePlayer, 16 ) -- remove the helmet
    removePlayerClothes ( player, 16 ) -- remove the helmet
    end
  end
end
end
addEventHandler ( "onVehicleExit", getRootElement(), removeHelmetOnExit )
</syntaxhighlight>
==Example 2==
This example will turn off a vehicle's engine when the driver gets out of the car.
<syntaxhighlight lang="lua">
addEventHandler ( "onVehicleExit", getRootElement(), function(theVehicle, leftSeat, jackerPlayer)
    if leftSeat == 0 and not jackerPlayer then
      setVehicleEngineState( theVehicle, false)
    end
end)
</syntaxhighlight>
</syntaxhighlight>


==See Also==
==Changelog==
{{Event_functions}}
{{ChangelogHeader}}
{{ChangelogItem|1.5.3-9.11247|Added forcedByScript argument}}
 
{{See also/Server event|Vehicle events}}

Latest revision as of 14:50, 18 June 2024

This event is triggered when a player or ped leaves a vehicle.

Parameters

ped thePed, int seat, ped jacker, bool forcedByScript
  • thePed: a player or ped element who exited the vehicle.
  • seat: an int representing the seat in which the ped exited from.
  • jacker: a player or ped element who jacked the driver.

Source

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

Example

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 ( thePlayer, seat, jacked )
    if ( getElementModel ( source ) == 522 ) then -- if its a nrg
        addPedClothes ( thePlayer, "moto", "moto", 16 ) -- add the helmet
    end
end
addEventHandler ( "onVehicleEnter", getRootElement(), addHelmetOnEnter )

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


Example 2

This example will turn off a vehicle's engine when the driver gets out of the car.

addEventHandler ( "onVehicleExit", getRootElement(), function(theVehicle, leftSeat, jackerPlayer)
    if leftSeat == 0 and not jackerPlayer then
       setVehicleEngineState( theVehicle, false)
    end
end)

Changelog

Version Description
1.5.3-9.11247 Added forcedByScript argument

See Also

Vehicle events


Event functions