OnPlayerEnterVehicle

From GTA Network Wiki
Jump to: navigation, search

OnPlayerEnterVehicle
Shared Function

utilities-terminal.png Server-Side system-users.png Client-Side csharp.png C#

This type of event is used for handling code when the player enters any type of vehicle.



Server-side

Subscribing

Note: the Attribute should be declared above the method to be invoked, it's alternative to subscribing the method to a delegate, introduced for performance reasons.

[ServerEvent(Event.PlayerEnterVehicle)]

Method Syntax

void OnPlayerEnterVehicle(Client player, Vehicle vehicle, sbyte seatID)

Required Parameters

  • Client: the player.
  • Vehicle: the vehicle.
  • seatID: the seatID. -1 is driver.

Example

[ServerEvent(Event.PlayerEnterVehicle)]
public void OnPlayerEnterVehicle(Client player, Vehicle vehicle, sbyte seatID)
{
    // Some code..
}


Client-side

Subscribing

Note: the method should be subscribed to the respective event delegate in your Main constructor/Entry point for it to be invoked.

public Main() 
{
    Events.OnPlayerEnterVehicle += OnPlayerEnterVehicle;
}

Method Syntax

void OnPlayerEnterVehicle(RAGE.Elements.Vehicle vehicle, int seatId, RAGE.Events.CancelEventArgs cancel)

Required Parameters

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

Example

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

Note: ternary operator ?: was used, for more info visit the Microsoft C# Reference docs

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

References