OnPlayerVehicleEnter: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(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''': ...)
 
 
(11 intermediate revisions by 6 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]] enters a vehicle.


==Parameters==  
==Parameters==  
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
vehicle theVehicle, int seat, player jacked
vehicle theVehicle, int seat, ped jacked
</syntaxhighlight>  
</syntaxhighlight>  


*'''theVehicle''': A vehicle element representing the vehicle that was entered
*'''theVehicle''': a [[vehicle]] element representing the vehicle that was entered.
*'''seat''': An integer representing the seat in which the player is entering
*'''seat''': an [[int]] representing the seat in which the player is entering.
*'''jacked''': A player element representing a player who has been 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 ( vehicle, seat, jacked ) --when a player enters a vehicle
function enterVehicle ( theVehicle, 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
     if ( policeVehicles[getElementModel ( theVehicle )] ) and ( not policeSkins[getElementModel ( 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
         removePedFromVehicle ( source ) -- force the player out of the vehicle
         outputChatBox ( "Only policeman can enter police cars!", source ) --and tell the player why
         outputChatBox ( "Only policeman can enter police cars!", source ) -- and tell the player why
     end
     end
end
end
addEventHandler ( "onPlayerEnterVehicle", getRootElement(), enterVehicle ) --add an event for onPlayerEnterVehicle
addEventHandler ( "onPlayerVehicleEnter", root, enterVehicle ) -- add an event handler for onPlayerVehicleEnter
</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.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
function addHelmetOnEnter ( vehicle, seat, jacked )
function addHelmetOnEnter ( theVehicle, seat, jacked )
  if ( getVehicleID ( vehicle ) == 522 ) then -- if its a nrg
    if ( getElementModel ( theVehicle ) == 522 ) then -- if its a nrg
    addPlayerClothes ( source, "moto", "moto", 16 ) -- add the helmet
        addPedClothes ( source, "moto", "moto", 16 ) -- add the helmet
  end
    end
end
end
addEventHandler ( "onPlayerEnterVehicle", getRootElement(), addHelmetOnEnter )
addEventHandler ( "onPlayerVehicleEnter", root, addHelmetOnEnter )


function removeHelmetOnExit ( vehicle, seat, jacked )
function removeHelmetOnExit ( theVehicle, seat, jacked )
  if ( getVehicleID ( vehicle ) == 522 ) then -- if its a nrg
    if ( getElementModel ( theVehicle ) == 522 ) then -- if its a nrg
    removePlayerClothes ( source, 16 ) -- remove the helmet
        removePedClothes ( source, 16 ) -- remove the helmet
  end
    end
end
end
addEventHandler ( "onPlayerExitVehicle", getRootElement(), removeHelmetOnExit )
addEventHandler ( "onPlayerVehicleExit", root, removeHelmetOnExit )
</syntaxhighlight>
</syntaxhighlight>


==See Also==
{{See also/Server event|Player events}}
{{Event_functions}}

Latest revision as of 13:45, 31 December 2022

This event is triggered when a player enters a vehicle.

Parameters

vehicle theVehicle, int seat, ped jacked
  • theVehicle: a vehicle element representing the vehicle that was entered.
  • seat: an int representing the seat in which the player is entering.
  • jacked: a player or ped element representing 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 ( theVehicle, seat, jacked ) --when a player enters a vehicle
    if ( policeVehicles[getElementModel ( theVehicle )] ) and ( not policeSkins[getElementModel ( source )] ) then -- if the vehicle is one of 4 police cars, and the skin is not a police skin
        removePedFromVehicle ( source ) -- force the player out of the vehicle
        outputChatBox ( "Only policeman can enter police cars!", source ) -- and tell the player why
    end
end
addEventHandler ( "onPlayerVehicleEnter", root, enterVehicle ) -- add an event handler for onPlayerVehicleEnter

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

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

See Also

Player events


Event functions