getVehicleOccupants | Multi Theft Auto: Wiki Skip to content

getVehicleOccupants

Client-side
Server-side
Shared

Manual Review Required

Please finish this page using the corresponding Old Wiki article. Go to Contribution guidelines for more information.


This function gets all peds sitting in the specified vehicle.

OOP Syntax Help! I don't understand this!

  • Method:vehicle:getOccupants(...)
  • Variable: .occupants

Syntax

table getVehicleOccupants ( vehicle theVehicle )
Required Arguments
  • theVehicle: the vehicle of which you wish to retrieve the occupants.

Returns

  • table: value

Returns a table with seat ID as an index and the occupant as an element like this: table[seat] = occupant

Code Examples

shared

This example prints all vehicle occupants into the F8 console if "/occupants" is typed:

function outputOccupants()
-- Make sure they're in a vehicle
if (not isPedInVehicle(localPlayer)) then
outputConsole("You're not in a vehicle.")
return false
end
outputConsole("------------------------------------") -- Print a separator for easier reading
for seat, occupant in pairs(getVehicleOccupants(getPedOccupiedVehicle(localPlayer))) do -- Loop through the array
outputConsole("Seat " .. seat .. ": " .. getPlayerName(occupant)) -- Print who's in the seat
end
outputConsole("------------------------------------") -- Print another separator
end
addCommandHandler("occupants", outputOccupants, false, false) -- Add a command "/occupants" which triggers outputOccupants

See Also

Vehicle Functions