OnVehicleStartEnter: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
m (Using "ped" instead of "player" when parameter refers to both)
 
(18 intermediate revisions by 11 users not shown)
Line 1: Line 1:
__NOTOC__  
__NOTOC__  
This event is triggered when a player starts to enter a vehicle. This event can be used to cancel entry, if necessary.
{{Server event}}
This event is triggered when a player or ped starts to enter a vehicle. This event can be used to cancel entry, if necessary.


==Syntax==  
==Parameters==
{{Deprecated feature|3|1.0|
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
void onVehicleStartEnter ( player player, int seat, player jacked )
ped enteringPed, int seat, ped jacked
</syntaxhighlight>  
</syntaxhighlight>  
}}
{{New feature/item|3|1.0||
<syntaxhighlight lang="lua">
ped enteringPed, int seat, ped jacked, int door
</syntaxhighlight>}}
*'''enteringPed''': a [[player]] or [[ped]] element who is starting to enter a vehicle.
*'''seat''': an [[int]] representing the seat in which the ped is entering.
*'''jacked''': a [[player]] or [[ped]] element representing who is going to be jacked.
*'''door''': an [[int]] of which door is being used (0-3). 0 is driver side door, 1 is front passenger, 2 is back left, 3 is back right.
==Source==
The [[event system#Event source|source]] of this event is the [[vehicle]] in which a ped began to enter.


==Variables==
===Canceling===
*'''player''': A player element representing the player who is starting to enter a vehicle
If this event is [[Event system #Canceling|canceled]], the ped will not enter the vehicle.
*'''seat''': An integer representing the seat in which the player is entering
*'''jacked''': A player element representing who is going to be jacked


==Example==  
==Example==  
This example locks a police car if a player trying to enter is not a policeman
This example blocks a player out of a police vehicle if he is not a policeman.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
--add an event for onVehicleStartEnter
policeVehicles = { [598]=true,[596]=true,[597]=true,[599]=true }
addEventHandler ( "onVehicleStartEnter", getRootElement(), "playerStartEnter" )
policeSkins = { [280]=true,[281]=true,[282]=true,[283]=true,[284]=true,[285]=true,[286]=true }
function playerStartEnter ( player, seat, jacked ) --when a player starts entering a vehicle
 
if ( getVehicleName ( source ) == "police" ) and ( getPlayerSkin ( source ) > 279 ) then --if the vehicle is a police car, and the player's skin is higher than 279 i.e. a cop skin
function enterVehicle ( player, seat, jacked ) --when a player enters a vehicle
    setVehicleLocked ( source, false ) --open the vehicle
    if ( policeVehicles[getElementModel(source)] ) and ( not policeSkins[getElementModel(player)] ) then --if the vehicle is one of 4 police cars, and the skin is not a police skin
else --if he's not a cop
        cancelEvent()
    setVehicleLocked ( source, true ) --lock the vehicle
        outputChatBox ( "Only policeman can enter police cars!", player ) --and tell the player why
    end
end
end
addEventHandler ( "onVehicleStartEnter", getRootElement(), enterVehicle ) --add an event handler for onVehicleStartEnter
</syntaxhighlight>
</syntaxhighlight>


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

Latest revision as of 18:53, 29 November 2020

This event is triggered when a player or ped starts to enter a vehicle. This event can be used to cancel entry, if necessary.

Parameters

ped enteringPed, int seat, ped jacked, int door
  • enteringPed: a player or ped element who is starting to enter a vehicle.
  • seat: an int representing the seat in which the ped is entering.
  • jacked: a player or ped element representing who is going to be jacked.
  • door: an int of which door is being used (0-3). 0 is driver side door, 1 is front passenger, 2 is back left, 3 is back right.

Source

The source of this event is the vehicle in which a ped began to enter.

Canceling

If this event is canceled, the ped will not enter the vehicle.

Example

This example blocks 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 ( player, seat, jacked ) --when a player enters a vehicle
    if ( policeVehicles[getElementModel(source)] ) and ( not policeSkins[getElementModel(player)] ) then --if the vehicle is one of 4 police cars, and the skin is not a police skin
        cancelEvent()
        outputChatBox ( "Only policeman can enter police cars!", player ) --and tell the player why
    end
end
addEventHandler ( "onVehicleStartEnter", getRootElement(), enterVehicle ) --add an event handler for onVehicleStartEnter

See Also

Vehicle events


Event functions