ServersYour serverFor creatorsForumFAQDocumentationSecurity
Download the launcher
  1. Documentation
  2. Shared functions
  3. getVehicleOccupants

Function

getVehicleOccupants

Server and clientVehiclesIdentical to MTA:SA

Returns everyone (players and peds) sitting in the vehicle as a table of seat number → occupant. Empty seats are not in the table, so loop over it with pairs, not ipairs (seat 0 is not an array index).

Syntax

table getVehicleOccupants(vehicle vehicle)

Arguments

vehiclevehicle
The vehicle.

Returns

A table { [seat] = player/ped }.

Example

local function vehicleMessage(vehicle, text)
    for seat, occupant in pairs(getVehicleOccupants(vehicle)) do
        if getElementType(occupant) == "player" then outputChatBox(text, occupant) end
    end
end

See also