PlayerEnterVehicle: Difference between revisions

From RAGE Multiplayer Wiki
m (category)
No edit summary
Line 2: Line 2:


{{ServersideCsJsEvent}}
{{ServersideCsJsEvent}}
{{CSharpContainer|1=
See [https://wiki.gtanet.work/index.php?title=OnPlayerEnterVehicle on GTA Network Wiki].
}}
{{JSContainer|
{{JSContainer|
*'''Known issue''': Client side this event is triggered when the player starts to enter the vehicle and not once they've completely sat down. This also causes the seat parameter to return 'undefined'.
*'''Known issue''': Client side this event is triggered when the player starts to enter the vehicle and not once they've completely sat down. This also causes the seat parameter to return 'undefined'.


{{Parameters}}
{{Parameters}}
* '''player'''
* '''player''': {{RageType|Player}}
* '''vehicle''' - The current vehicle the player is sitting in.
* '''vehicle''': {{RageType|Vehicle}} - The current vehicle the player is sitting in.
* '''seat''' - The seat ID the player sits down on.
* '''seat''': {{RageType|Number}} - The seat ID the player sits down on.


{{Example}}
{{Example}}
Line 22: Line 27:


{{ClientsideCsJsEvent}}
{{ClientsideCsJsEvent}}
{{CSharpContainer|
{{CSharpContainer|
<syntaxhighlight lang="c#">
<syntaxhighlight lang="csharp">
public delegate void OnPlayerEnterVehicleDelegate(Vehicle vehicle, int seatId);
public delegate void OnPlayerEnterVehicleDelegate(Vehicle vehicle, int seatId);
</syntaxhighlight>
</syntaxhighlight>
Line 33: Line 39:
The example below sends a chat message to play when they enter a vehicle, showing whether they are driver or passenger.
The example below sends a chat message to play when they enter a vehicle, showing whether they are driver or passenger.


<syntaxhighlight lang="c#">
<syntaxhighlight lang="csharp">
Events.OnPlayerEnterVehicle += OnPlayerEnterVehicle;
Events.OnPlayerEnterVehicle += OnPlayerEnterVehicle;
</syntaxhighlight>
</syntaxhighlight>
<syntaxhighlight lang="c#">
<syntaxhighlight lang="csharp">
public void OnPlayerEnterVehicle(RAGE.Elements.Vehicle vehicle, int seatId, RAGE.Events.CancelEventArgs cancel)
public void OnPlayerEnterVehicle(RAGE.Elements.Vehicle vehicle, int seatId, RAGE.Events.CancelEventArgs cancel)
{
{
Line 52: Line 58:


{{JSContainer|
{{JSContainer|
{{Parameters}}
* '''vehicle''': {{RageType|Vehicle}} - The current vehicle the player entered.
* '''seat''': {{RageType|Number}} - The seat ID the player sits down on.
{{Example}}
<pre>
<pre>
function playerEnterVehicleHandler(vehicle, seat) {
function playerEnterVehicleHandler(vehicle, seat) {
Line 64: Line 75:
{{Player_events}}
{{Player_events}}


[[Category:Player]]
[[Category:Vehicle]]
[[Category:Server-side Event]]
[[Category:Server-side Event]]
[[Category:Client-side Event]]
[[Category:Client-side Event]]

Revision as of 13:38, 23 May 2019

This event is triggered when a player is in the car.

Server-Side
Event

 C#  JavaScript




C# Syntax


JavaScript Syntax

  • Known issue: Client side this event is triggered when the player starts to enter the vehicle and not once they've completely sat down. This also causes the seat parameter to return 'undefined'.

Parameters

  • player: Player
  • vehicle: Vehicle - The current vehicle the player is sitting in.
  • seat: Number - The seat ID the player sits down on.

Example

This example outputs chat message, when player is in the car.

function playerEnterVehicleHandler(player, vehicle, seat) {
	player.outputChatBox(`${player.name} got into the car with ID: ${vehicle.id}. Seat: ${seat}`);
}
 
mp.events.add("playerEnterVehicle", playerEnterVehicleHandler);


Client-Side Event

 C#  JavaScript



C# Syntax

public delegate void OnPlayerEnterVehicleDelegate(Vehicle vehicle, int seatId);

Parameters

  • vehicle - vehicle RAGE.Elements.Vehicle
  • seatId - the id of the seat, expectsSystem.Int32

Example

The example below sends a chat message to play when they enter a vehicle, showing whether they are driver or passenger.

Events.OnPlayerEnterVehicle += OnPlayerEnterVehicle;
public void OnPlayerEnterVehicle(RAGE.Elements.Vehicle vehicle, int seatId, RAGE.Events.CancelEventArgs cancel)
{
    if (seatId == -1)
    {
        RAGE.Chat.Output("You got in the driver's seat");
    }
    else
    {
        RAGE.Chat.Output("You got in a passenger seat");
    }
}


JavaScript Syntax

Parameters

  • vehicle: Vehicle - The current vehicle the player entered.
  • seat: Number - The seat ID the player sits down on.

Example

function playerEnterVehicleHandler(vehicle, seat) {
   mp.gui.chat.push(`You got into the car with ID: ${vehicle.id}. Seat: ${seat}`);
}

mp.events.add("playerEnterVehicle", playerEnterVehicleHandler);


See also

Checkpoint

Colshape

Entity

Player

Streaming

Vehicle

Waypoint