GetVehicleOccupants
Jump to navigation
Jump to search
This function gets all peds sitting in the specified vehicle.
Syntax
table getVehicleOccupants ( vehicle theVehicle )
OOP Syntax Help! I don't understand this!
- Method: vehicle:getOccupants(...)
- Variable: .occupants
Required Arguments
- theVehicle: the vehicle of which you wish to retrieve the occupants.
Returns
Returns a table with seat ID as an index and the occupant as an element like this: table[seat] = occupant
Returns false if an invalid vehicle was passed or if the vehicle has no seats (like a trailer)
COUNTING PLAYERS IN A VEHICLE
Don't use an ipairs loop with the table returned by this function. It will skip the driver, as ipairs starts at 1 and the driver seat is ID 0. And if there's an empty seat, ipairs will stop looping. You should use a pairs loop instead.
local counter = 0 for seat, player in pairs(getVehicleOccupants(pseudoVehicle)) do counter = counter + 1 end outputDebugString("Players in your vehicle: ".. counter)
Example
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
- addVehicleUpgrade
- attachTrailerToVehicle
- blowVehicle
- createVehicle
- detachTrailerFromVehicle
- fixVehicle
- getOriginalHandling
- getTrainDirection
- getTrainPosition
- getTrainSpeed
- getTrainTrack
- getVehicleColor
- getVehicleCompatibleUpgrades
- getVehicleController
- getVehicleDoorOpenRatio
- getVehicleDoorState
- getVehicleEngineState
- getVehicleHandling
- getVehicleHeadLightColor
- getVehicleLandingGearDown
- getVehicleLightState
- getVehicleMaxPassengers
- getVehicleModelFromName
- getVehicleName
- getVehicleNameFromModel
- getVehicleOccupant
- getVehicleOccupants
- getVehicleOverrideLights
- getVehiclePaintjob
- getVehiclePanelState
- getVehiclePlateText
- getVehicleSirenParams
- getVehicleSirens
- getVehicleSirensOn
- getVehicleTowedByVehicle
- getVehicleTowingVehicle
- getVehicleTurretPosition
- getVehicleType
- getVehicleUpgradeOnSlot
- getVehicleUpgradeSlotName
- getVehicleUpgrades
- getVehicleVariant
- getVehicleWheelStates
- isTrainDerailable
- isTrainDerailed
- isVehicleBlown
- isVehicleDamageProof
- isVehicleFuelTankExplodable
- isVehicleLocked
- isVehicleOnGround
- isVehicleTaxiLightOn
- removeVehicleUpgrade
- setTrainDerailable
- setTrainDerailed
- setTrainDirection
- setTrainPosition
- setTrainSpeed
- setTrainTrack
- setVehicleColor
- setVehicleDamageProof
- setVehicleDoorOpenRatio
- setVehicleDoorState
- setVehicleDoorsUndamageable
- setVehicleEngineState
- setVehicleFuelTankExplodable
- setVehicleHandling
- setVehicleHeadLightColor
- setVehicleLandingGearDown
- setVehicleLightState
- setVehicleLocked
- setVehicleOverrideLights
- setVehiclePaintjob
- setVehiclePanelState
- setVehiclePlateText
- setVehicleSirens
- setVehicleSirensOn
- setVehicleTaxiLightOn
- setVehicleTurretPosition
- setVehicleVariant
- setVehicleWheelStates