PlayerEnterVehicle: Difference between revisions
No edit summary |
No edit summary |
||
| (16 intermediate revisions by 8 users not shown) | |||
| Line 1: | Line 1: | ||
This event is triggered when a player | This event is triggered when a player entered vehicle. | ||
{{ServersideCsJsEvent}} | |||
= | {{CSharpContainer|1= | ||
See [[OnPlayerEnterVehicle]]. | |||
}} | |||
{{JSContainer| | |||
{{Parameters}} | |||
* '''player''': {{RageType|Player}} - The [[:Category:Player API|player]] which entered vehicle. | |||
* '''vehicle''': {{RageType|Vehicle}} - The current [[:Category:Vehicle API|vehicle]] the player is sitting in. | |||
* '''seat''': {{RageType|Number}} - The seat ID the player sits down on. | |||
{{Example}} | |||
This example outputs chat message, when player is in the car. | This example outputs chat message, when player is in the car. | ||
< | <pre> | ||
function playerEnterVehicleHandler(player, vehicle, seat) { | function playerEnterVehicleHandler(player, vehicle, seat) { | ||
player.outputChatBox(`${player.name} got into the car with ID: ${vehicle.id}. Seat: ${seat}`); | |||
} | |||
mp.events.add("playerEnterVehicle", playerEnterVehicleHandler); | |||
</pre> | |||
}} | |||
{{ClientsideCsJsEvent}} | |||
{{CSharpContainer| | |||
<syntaxhighlight lang="csharp"> | |||
public delegate void OnPlayerEnterVehicleDelegate(Vehicle vehicle, int seatId); | |||
</syntaxhighlight> | |||
{{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. | |||
<syntaxhighlight lang="csharp"> | |||
Events.OnPlayerEnterVehicle += OnPlayerEnterVehicle; | |||
</syntaxhighlight> | |||
<syntaxhighlight lang="csharp"> | |||
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"); | |||
} | |||
} | } | ||
</syntaxhighlight> | |||
}} | |||
{{JSContainer| | |||
{{Parameters}} | |||
* '''vehicle''': {{RageType|Vehicle}} - The current [[:Category:Vehicle API|vehicle]] the player entered. | |||
* '''seat''': {{RageType|Number}} - The seat ID the player sits down on. | |||
{{ | {{Example}} | ||
< | <pre> | ||
function playerEnterVehicleHandler(vehicle, seat) { | function playerEnterVehicleHandler(vehicle, seat) { | ||
mp.gui.chat.push(`You got into the car with ID: ${vehicle.id}. Seat: ${seat}`); | |||
} | } | ||
mp.events.add("playerEnterVehicle", playerEnterVehicleHandler); | mp.events.add("playerEnterVehicle", playerEnterVehicleHandler); | ||
</ | </pre> | ||
}} | |||
==See also== | ==See also== | ||
{{Player_events}} | {{Player_events}} | ||
[[Category:Player]] | |||
[[Category:Vehicle]] | |||
[[Category:Server-side Event]] | |||
[[Category:Client-side Event]] | |||
Latest revision as of 19:01, 15 May 2024
This event is triggered when a player entered vehicle.
Server-Side Event
C# Syntax
See OnPlayerEnterVehicle.
JavaScript Syntax
Parameters
- player: Player - The player which entered vehicle.
- 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# 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
- playerChat
- playerCommand
- playerDamage
- playerDeath
- playerJoin
- playerQuit
- playerReady
- playerSpawn
- playerWeaponChange
Streaming
Vehicle
- playerStartEnterVehicle
- playerEnterVehicle
- playerStartExitVehicle
- playerExitVehicle
- trailerAttached
- vehicleDamage
- vehicleDeath
- vehicleHornToggle
- vehicleSirenToggle