PlayerEnterVehicle: Difference between revisions

From RAGE Multiplayer Wiki
(var)
m (Removed workaround examples and text, added in 'known issue' which should be removed when fixed.)
Line 1: Line 1:
__NOTOC__
This event is triggered when a player is in the car.
This event is triggered when a player is in the car.
'''As of now PlayerEnterVehicle is actually PlayerStartEnterVehicle and is triggered twice when entering a vehicle!'''
 
*'''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, which sits down (serverside only).
* '''player'''
* '''vehicle''' - vehicle in which the player sits.
* '''vehicle''' - The current vehicle the player is sitting in.
* '''seat'''  - the place where he sits down. (Currently undefined clientside, use Player::getSeatIsTryingToEnter instead)
* '''seat'''  - The seat ID the player sits down on.


==Example==
==Example==
This example outputs chat message, when player is in the car.
This example outputs chat message, when player is in the car.
{{ServerSide}}
<div class="header" style="background-color: #408DAE; color: #FFFFFF; border: 2px solid #408DAE;">
<syntaxhighlight lang="javascript">
<div style="margin: 10px 10px 10px 10px;"><b>Server-Side</b></div>
<pre>
function playerEnterVehicleHandler(player, vehicle, seat) {
function playerEnterVehicleHandler(player, vehicle, seat) {
  const playerName = player.name;
player.outputChatBox(`${player.name} got into the car with ID: ${vehicle.id}. Seat: ${seat}`);
  const vehicleID = vehicle.id;
}
 
  mp.players.broadcast(`${playerName} got into the car with ID: ${vehicleID}. Seat: ${seat}`);
mp.events.add("playerEnterVehicle", playerEnterVehicleHandler);
}
</pre>
</div>


mp.events.add("playerEnterVehicle", playerEnterVehicleHandler);
</syntaxhighlight>


{{ClientSide}}
<div class="header" style="background-color: #AE4040; color: #FFFFFF; border: 2px solid #AE4040;">
<syntaxhighlight lang="javascript">
<div style="margin: 10px 10px 10px 10px;"><b>Client-Side</b></div>
// The player is not emmited client-side assuming it's you
<pre>
function playerEnterVehicleHandler(vehicle) {
function playerEnterVehicleHandler(vehicle, seat) {
  var seat = mp.players.local.getSeatIsTryingToEnter(); //Workaround since seat is currently undefined
   mp.gui.chat.push(`You got into the car with ID: ${vehicle.id}. Seat: ${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);
</syntaxhighlight>
</pre>
</div>


==See also==
==See also==
{{Player_events}}
{{Player_events}}

Revision as of 07:46, 21 October 2018


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

  • 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
  • vehicle - The current vehicle the player is sitting in.
  • seat - The seat ID the player sits down on.

Example

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

Server-Side
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
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