getVehicleOccupants | Multi Theft Auto: Wiki Skip to content

getVehicleOccupants

Client-side
Server-side
Shared

This page is incomplete! Help wanted!

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.

Syntax

getVehicleOccupants ( )

Code Examples

server

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