GetVehicleOccupants

From GT-MP
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.


If there are no players in the vehicle, the function will return an empty Client[] array.

Syntax

API.getVehicleOccupants(NetHandle vehicle);

Required Arguments

  • vehicle: parameter input should be in NetHandle type.

NOTE: This function returns data in Client[] type.

Usage example

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

[Command("cmdtest", GreedyArg = true)]
public void CMD_cmdtest(Client sender)
{
        var usersInCar = API.getVehicleOccupants(API.getPlayerVehicle(sender)); // we get the players of the vehicle. We assume that sender is inside a vehicle, and by using getPlayerVehicle we get the NetHandle
        API.sendChatMessageToPlayer(sender, "List of players in your vehicle:");
        foreach (var player in usersInCar) {
            API.sendChatMessageToPlayer(sender, player.name); //We'll send a message containing one of the occupant's name
        }
}

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

Changelog

Version Description
1.0 Release.

References