GetVehicleOccupants

From GTA Network Wiki
Jump to: navigation, search

GetVehicleOccupants
Server-Side Function

utilities-terminal.png Server-Side csharp.png C#

A function that returns the players who are inside a vehicle.

Syntax

List<Client> NAPI.Vehicle.GetVehicleOccupants(NetHandle vehicle, int maxOccupants = 4);

Required Arguments

  • vehicle: parameter input should be in NetHandle type.

Usage example

In this example, we're going to retrieve the players inside a vehicle, and we'll send a chat message.

[Command("carmates")]
public void CarMates(Client sender)
{
    // we get the players of the vehicle. We assume that sender is inside a vehicle, and by using getPlayerVehicle we get the NetHandle
    var playersInCar = NAPI.Vehicle.GetVehicleOccupants(sender.Vehicle); 
    sender.SendChatMessage("List of players in your vehicle:");
    foreach (var player in playersInCar) 
    {
        // We'll send a message containing one of the occupant's name
        sender.SendChatMessage(player.Name); 
    }
}

Remember that if you're not in any vehicle, the vehicle doesn't exist or is empty, this function will return an empty list.

Changelog

Version Description
1.0 Release.

References