OnVehicleEnter: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
Line 22: | Line 22: | ||
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 | ||
</syntaxhighlight> | |||
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"> | |||
addEventHandler ( "onVehicleEnter", getRootElement(), "onEnterVehicle" ) | |||
function onEnterVehicle ( player, seat, jacked ) | |||
if ( getVehicleID ( source ) == 522 ) then -- if its a nrg | |||
addPlayerClothes ( player, "moto", "moto", 16 ) -- add the helmet | |||
end | |||
end | |||
addEventHandler ( "onVehicleExit", getRootElement(), "onExitVehicle" ) | |||
function onExitVehicle ( player, seat, jacked ) | |||
if ( getVehicleID ( source ) == 522 ) then -- if its a nrg | |||
removePlayerClothes ( player, 16 ) -- remove the helmet | |||
end | |||
end | |||
</syntaxhighlight> | </syntaxhighlight> | ||
==See Also== | ==See Also== | ||
{{Event_functions}} | {{Event_functions}} |
Revision as of 15:24, 2 December 2006
This event is triggered when a player enters a vehicle.
Syntax
void onVehicleEnter ( player player, int seat, player jacked )
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
- seat: An integer representing the seat in which the player is entering
- jacked: A player element representing a player who has been jacked
Example
This example forces a player out of a police vehicle if he is not a policeman.
addEventHandler ( "onVehicleEnter", getRootElement(), "vehicleEnter" ) --add an event for onPlayerEnterVehicle function vehicleEnter ( player, seat, jacked ) --when a player enters a vehicle 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 removePlayerFromVehicle ( player )--force the player out of the vehicle outputChatBox ( "Only policeman can enter police cars!", player ) --and tell the player why end
This example adds a 'moto' helmet to a player when he gets on a nrg bike, and removes it when he gets off.
addEventHandler ( "onVehicleEnter", getRootElement(), "onEnterVehicle" ) function onEnterVehicle ( player, seat, jacked ) if ( getVehicleID ( source ) == 522 ) then -- if its a nrg addPlayerClothes ( player, "moto", "moto", 16 ) -- add the helmet end end addEventHandler ( "onVehicleExit", getRootElement(), "onExitVehicle" ) function onExitVehicle ( player, seat, jacked ) if ( getVehicleID ( source ) == 522 ) then -- if its a nrg removePlayerClothes ( player, 16 ) -- remove the helmet end end
See Also
- addEvent
- addEventHandler
- cancelEvent
- cancelLatentEvent
- getEventHandlers
- getLatentEventHandles
- getLatentEventStatus
- removeEventHandler
- triggerEvent
- wasEventCancelled