GetVehicleOccupants: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
m (Made example prettier) |
||
Line 22: | Line 22: | ||
==Example== | ==Example== | ||
This example prints all vehicle occupants into the F8 console if "/occupants" is typed: | This example prints all vehicle occupants into the F8 console if "/occupants" is typed: | ||
<syntaxhighlight lang="lua">function outputOccupants(player) | <syntaxhighlight lang="lua"> | ||
function outputOccupants(player) | |||
if isPedInVehicle(player) then -- If he is actually in a vehicle... | if isPedInVehicle(player) then -- If he is actually in a vehicle... | ||
outputConsole("------------------------------------", player) -- Print a seprerator for easier reading | |||
for seat, occupant in pairs(getVehicleOccupants(getPedOccupiedVehicle(player))) do -- Loop through the array | |||
if getElementType(occupant) == "player" then | |||
outputConsole("------------------------------------",player) -- Print a seprerator for easier reading | outputConsole("Seat " .. seat .. ": " .. getPlayerName(occupant), player) -- Print who's in the seat | ||
for seat, occupant in pairs( | |||
if getElementType(occupant)=="player" then | |||
end | end | ||
end | end | ||
outputConsole("------------------------------------",player) -- Print another seprerator | outputConsole("------------------------------------",player) -- Print another seprerator | ||
end | end |
Revision as of 20:23, 6 August 2013
This function gets all players sitting in the specified vehicle.
Syntax
table getVehicleOccupants ( vehicle theVehicle )
Required Arguments
- theVehicle: The vehicle of which you wish to retrieve the occupants.
Returns
Returns a table with contents...
table[seat] = occupant
... if successful. Returns false in the case of failure.
Note: 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.
Example
This example prints all vehicle occupants into the F8 console if "/occupants" is typed:
function outputOccupants(player) if isPedInVehicle(player) then -- If he is actually in a vehicle... outputConsole("------------------------------------", player) -- Print a seprerator for easier reading for seat, occupant in pairs(getVehicleOccupants(getPedOccupiedVehicle(player))) do -- Loop through the array if getElementType(occupant) == "player" then outputConsole("Seat " .. seat .. ": " .. getPlayerName(occupant), player) -- Print who's in the seat end end outputConsole("------------------------------------",player) -- Print another seprerator end end addCommandHandler("occupants",outputOccupants) -- 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