OnVehicleExit: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
m (correct event name)
m (formatting)
 
Line 18: Line 18:
The [[event system#Event source|source]] of this event is the [[vehicle]] that was exited.
The [[event system#Event source|source]] of this event is the [[vehicle]] that was exited.


==Example==  
==Examples==
 
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">
Line 37: Line 38:




==Example 2==
This example will turn off a vehicle's engine when the driver gets out of the car.
This example will turn off a vehicle's engine when the driver gets out of the car.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">

Latest revision as of 17:45, 1 June 2025

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.

Examples

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 )


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