OnVehicleEnter: Difference between revisions
Jump to navigation
Jump to search
m (See Also for server events) |
Zangomangu (talk | contribs) m (Using "ped" instead of "player" when parameter refers to both) |
||
(9 intermediate revisions by 7 users not shown) | |||
Line 1: | Line 1: | ||
__NOTOC__ | __NOTOC__ | ||
{{Server event}} | {{Server event}} | ||
This event is triggered when a player enters a vehicle. | This event is triggered when a player or ped enters a vehicle. | ||
==Parameters== | ==Parameters== | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
ped thePed, int seat, player jacked | |||
</syntaxhighlight> | </syntaxhighlight> | ||
*''' | *'''thePed''': a [[player]] or [[ped]] element who is entering the [[vehicle]]. | ||
*'''seat''': | *'''seat''': an [[int]] representing the seat in which the ped is entering. Seat 0 is the driver's seat. | ||
*'''jacked''': | *'''jacked''': a [[player]] or [[ped]] element representing who has been jacked. | ||
==Source== | ==Source== | ||
Line 18: | Line 18: | ||
'''Example 1:''' 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"> | ||
policeVehicles { [598]=true,[596]=true,[597]=true,[599]=true } | policeVehicles = { [598]=true, [596]=true, [597]=true, [599]=true } | ||
policeSkins { [280]=true,[281]=true,[282]=true,[283]=true,[284]=true,[285]=true,[286]=true } | policeSkins = { [280]=true, [281]=true, [282]=true, [283]=true, [284]=true, [285]=true, [286]=true } | ||
function enterVehicle ( | function enterVehicle ( thePlayer, seat, jacked ) -- when a player enters a vehicle | ||
if ( policeVehicles[ | if ( policeVehicles[getElementModel ( source )] ) and ( not policeSkins[getElementModel ( thePlayer )] ) then -- if the vehicle is one of 4 police cars, and the skin is not a police skin | ||
removePedFromVehicle ( thePlayer ) -- force the player out of the vehicle | |||
outputChatBox ( "Only policeman can enter police cars!", | outputChatBox ( "Only policeman can enter police cars!", thePlayer ) -- and tell the player why | ||
end | end | ||
end | end | ||
addEventHandler ( "onVehicleEnter", getRootElement(), enterVehicle ) --add an event for | addEventHandler ( "onVehicleEnter", getRootElement(), enterVehicle ) -- add an event handler for onVehicleEnter | ||
</syntaxhighlight> | </syntaxhighlight> | ||
'''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. | '''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 (only works with players using CJ skin). | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
function addHelmetOnEnter ( | function addHelmetOnEnter ( thePlayer, seat, jacked ) | ||
if ( getElementModel ( source ) == 522 ) then -- if its a nrg | |||
addPedClothes ( thePlayer, "moto", "moto", 16 ) -- add the helmet | |||
end | |||
end | end | ||
addEventHandler ( "onVehicleEnter", getRootElement(), addHelmetOnEnter ) | addEventHandler ( "onVehicleEnter", getRootElement(), addHelmetOnEnter ) | ||
function removeHelmetOnExit ( | function removeHelmetOnExit ( thePlayer, seat, jacked ) | ||
if ( getElementModel ( source ) == 522 ) then -- if its a nrg | |||
removePedClothes ( thePlayer, 16 ) -- remove the helmet | |||
end | |||
end | end | ||
addEventHandler ( "onVehicleExit", getRootElement(), removeHelmetOnExit ) | addEventHandler ( "onVehicleExit", getRootElement(), removeHelmetOnExit ) |
Latest revision as of 18:49, 29 November 2020
This event is triggered when a player or ped enters a vehicle.
Parameters
ped thePed, int seat, player jacked
- thePed: a player or ped element who is entering the vehicle.
- seat: an int representing the seat in which the ped is entering. Seat 0 is the driver's seat.
- jacked: a player or ped element representing 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 ( thePlayer, seat, jacked ) -- when a player enters a vehicle if ( policeVehicles[getElementModel ( source )] ) and ( not policeSkins[getElementModel ( thePlayer )] ) then -- if the vehicle is one of 4 police cars, and the skin is not a police skin removePedFromVehicle ( thePlayer ) -- force the player out of the vehicle outputChatBox ( "Only policeman can enter police cars!", thePlayer ) -- and tell the player why end end addEventHandler ( "onVehicleEnter", getRootElement(), enterVehicle ) -- add an event handler for onVehicleEnter
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 (only works with players using CJ skin).
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 )
See Also
Vehicle events
- onTrailerAttach
- onTrailerDetach
- onVehicleDamage
- onVehicleEnter
- onVehicleExit
- onVehicleExplode
- onVehicleRespawn
- onVehicleStartEnter
- onVehicleStartExit
Event functions
- addEvent
- addEventHandler
- cancelEvent
- cancelLatentEvent
- getEventHandlers
- getLatentEventHandles
- getLatentEventStatus
- removeEventHandler
- triggerEvent
- wasEventCancelled