<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.multitheftauto.com/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Timur2915</id>
	<title>Multi Theft Auto: Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.multitheftauto.com/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Timur2915"/>
	<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/wiki/Special:Contributions/Timur2915"/>
	<updated>2026-04-29T16:07:51Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.39.3</generator>
	<entry>
		<id>https://wiki.multitheftauto.com/index.php?title=GetVehicleOccupants&amp;diff=64555</id>
		<title>GetVehicleOccupants</title>
		<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=GetVehicleOccupants&amp;diff=64555"/>
		<updated>2019-10-22T08:24:00Z</updated>

		<summary type="html">&lt;p&gt;Timur2915: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__NOTOC__&lt;br /&gt;
{{Server client function}}&lt;br /&gt;
This function gets all peds sitting in the specified vehicle.&lt;br /&gt;
&lt;br /&gt;
==Syntax== &lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
table getVehicleOccupants ( vehicle theVehicle )            &lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
{{OOP||[[vehicle]]:getOccupants|occupants}}&lt;br /&gt;
===Required Arguments=== &lt;br /&gt;
*'''theVehicle:''' the [[vehicle]] of which you wish to retrieve the occupants.&lt;br /&gt;
&lt;br /&gt;
===Returns===&lt;br /&gt;
Returns a [[table]] with seat ID as an index and the occupant as an element like this: table[seat] = occupant&lt;br /&gt;
&lt;br /&gt;
Returns ''false'' if an invalid vehicle was passed or if the vehicle has no seats (like a trailer)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style='font-weight: bold;background:blue;color:white;padding:2px; padding-left:8px;'&amp;gt;COUNTING PLAYERS IN A VEHICLE&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;div style='border: 2px solid blue;padding: 5px;'&amp;gt;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.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
local counter = 0&lt;br /&gt;
&lt;br /&gt;
for seat, player in pairs(getVehicleOccupants(pseudoVehicle)) do&lt;br /&gt;
    counter = counter + 1&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
outputDebugString(&amp;quot;Players in your vehicle: &amp;quot;.. counter)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Example== &lt;br /&gt;
This example prints all vehicle occupants into the F8 console if &amp;quot;/occupants&amp;quot; is typed:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function outputOccupants()&lt;br /&gt;
    -- Make sure they're in a vehicle&lt;br /&gt;
    if (not isPedInVehicle(localPlayer)) then&lt;br /&gt;
        outputConsole(&amp;quot;You're not in a vehicle.&amp;quot;)&lt;br /&gt;
        return false&lt;br /&gt;
    end&lt;br /&gt;
    outputConsole(&amp;quot;------------------------------------&amp;quot;) -- Print a separator for easier reading&lt;br /&gt;
    for seat, occupant in pairs(getVehicleOccupants(getPedOccupiedVehicle(localPlayer))) do -- Loop through the array&lt;br /&gt;
        outputConsole(&amp;quot;Seat &amp;quot; .. seat .. &amp;quot;: &amp;quot; .. getPlayerName(occupant)) -- Print who's in the seat &lt;br /&gt;
    end&lt;br /&gt;
    outputConsole(&amp;quot;------------------------------------&amp;quot;) -- Print another separator&lt;br /&gt;
end&lt;br /&gt;
addCommandHandler(&amp;quot;occupants&amp;quot;, outputOccupants, false, false) -- Add a command &amp;quot;/occupants&amp;quot; which triggers outputOccupants&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==See Also==&lt;br /&gt;
{{Vehicle_functions}}&lt;/div&gt;</summary>
		<author><name>Timur2915</name></author>
	</entry>
</feed>