PlayerEnterVehicle: Difference between revisions

From RAGE Multiplayer Wiki
(var)
Line 1: Line 1:
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!'''


==Parameters==
==Parameters==
* '''player'''  - player, which sits down (serverside only)
* '''player'''  - player, which sits down (serverside only).
* '''vehicle''' - vehicle in which the player sits.
* '''vehicle''' - vehicle in which the player sits.
* '''seat'''  - the place where he sits down.
* '''seat'''  - the place where he sits down. (Currently undefined clientside, use Player::getSeatIsTryingToEnter instead)


==Example==
==Example==
Line 23: Line 24:
<syntaxhighlight lang="javascript">
<syntaxhighlight lang="javascript">
// The player is not emmited client-side assuming it's you
// The player is not emmited client-side assuming it's you
function playerEnterVehicleHandler(vehicle, seat) {
function playerEnterVehicleHandler(vehicle) {
   const vehicleID = vehicle.id;
   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.players.broadcast(`You got into the car with ID: ${vehicleID}. Seat: ${seat}`);
}
}



Revision as of 22:20, 18 October 2018

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!

Parameters

  • player - player, which sits down (serverside only).
  • vehicle - vehicle in which the player sits.
  • seat - the place where he sits down. (Currently undefined clientside, use Player::getSeatIsTryingToEnter instead)

Example

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

Server-Side

function playerEnterVehicleHandler(player, vehicle, seat) {
   const playerName = player.name;
   const vehicleID = vehicle.id;

   mp.players.broadcast(`${playerName} got into the car with ID: ${vehicleID}. Seat: ${seat}`);
}

mp.events.add("playerEnterVehicle", playerEnterVehicleHandler);
Client-Side
// The player is not emmited client-side assuming it's you
function playerEnterVehicleHandler(vehicle) {
   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.events.add("playerEnterVehicle", playerEnterVehicleHandler);

See also

Checkpoint

Colshape

Entity

Player

Streaming

Vehicle

Waypoint