<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.multitheftauto.com/wiki/IsPlayerActuallyInVehicle?action=history&amp;feed=atom</id>
	<title>IsPlayerActuallyInVehicle - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.multitheftauto.com/wiki/IsPlayerActuallyInVehicle?action=history&amp;feed=atom"/>
	<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=IsPlayerActuallyInVehicle&amp;action=history"/>
	<updated>2026-05-12T15:02:01Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.39.3</generator>
	<entry>
		<id>https://wiki.multitheftauto.com/index.php?title=IsPlayerActuallyInVehicle&amp;diff=76056&amp;oldid=prev</id>
		<title>Dragon: Created page with &quot;{{Useful Function}} __NOTOC__ This function provides a hacky way to recreate the client-side behavior of isPedInVehicle server-sided for player elements ONLY. It checks if a specified player is actually in a vehicle and not just in the process of entering.  ==Syntax== &lt;syntaxhighlight lang=&quot;lua&quot;&gt;bool isPlayerActuallyInVehicle ( player thePlayer )&lt;/syntaxhighlight&gt;  ===Required Arguments=== * '''thePlayer''': a player to check if they are inside a ve...&quot;</title>
		<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=IsPlayerActuallyInVehicle&amp;diff=76056&amp;oldid=prev"/>
		<updated>2023-01-27T17:37:37Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;{{Useful Function}} __NOTOC__ This function provides a hacky way to recreate the client-side behavior of &lt;a href=&quot;/wiki/IsPedInVehicle&quot; title=&quot;IsPedInVehicle&quot;&gt;isPedInVehicle&lt;/a&gt; server-sided for &lt;a href=&quot;/wiki/Player&quot; class=&quot;mw-redirect&quot; title=&quot;Player&quot;&gt;player&lt;/a&gt; elements ONLY. It checks if a specified &lt;a href=&quot;/wiki/Player&quot; class=&quot;mw-redirect&quot; title=&quot;Player&quot;&gt;player&lt;/a&gt; is actually in a &lt;a href=&quot;/wiki/Vehicle&quot; class=&quot;mw-redirect&quot; title=&quot;Vehicle&quot;&gt;vehicle&lt;/a&gt; and not just in the process of entering.  ==Syntax== &amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;bool isPlayerActuallyInVehicle ( player thePlayer )&amp;lt;/syntaxhighlight&amp;gt;  ===Required Arguments=== * &amp;#039;&amp;#039;&amp;#039;thePlayer&amp;#039;&amp;#039;&amp;#039;: a &lt;a href=&quot;/wiki/Player&quot; class=&quot;mw-redirect&quot; title=&quot;Player&quot;&gt;player&lt;/a&gt; to check if they are inside a ve...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{Useful Function}}&lt;br /&gt;
__NOTOC__&lt;br /&gt;
This function provides a hacky way to recreate the client-side behavior of [[isPedInVehicle]] server-sided for [[player]] elements ONLY. It checks if a specified [[player]] is actually in a [[vehicle]] and not just in the process of entering.&lt;br /&gt;
&lt;br /&gt;
==Syntax==&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;bool isPlayerActuallyInVehicle ( player thePlayer )&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Required Arguments===&lt;br /&gt;
* '''thePlayer''': a [[player]] to check if they are inside a [[vehicle]] or not.&lt;br /&gt;
&lt;br /&gt;
===Returns===&lt;br /&gt;
Returns ''true'' if the specified [[player]] has fully completed entering a [[vehicle]] and hasn't fully completed exiting it yet, ''false'' otherwise.&lt;br /&gt;
&lt;br /&gt;
==Code==&lt;br /&gt;
&amp;lt;section name=&amp;quot;Function source&amp;quot; class=&amp;quot;server&amp;quot; show=&amp;quot;true&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function isPlayerActuallyInVehicle(player)&lt;br /&gt;
	assert(isElement(player) and (getElementType(player) == &amp;quot;player&amp;quot;), &amp;quot;Bad argument @ isPlayerActuallyInVehicle [player expected, got &amp;quot; .. type(player) .. &amp;quot; '&amp;quot; .. tostring(player) .. &amp;quot;']&amp;quot;)&lt;br /&gt;
	local vehicle = getPedOccupiedVehicle(player)&lt;br /&gt;
	if vehicle then&lt;br /&gt;
		local x,y = getElementPosition(player)&lt;br /&gt;
		local vx,vy = getElementPosition(vehicle)&lt;br /&gt;
		if x == vx and y == vy then&lt;br /&gt;
			return true&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	return false&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/section&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Example==&lt;br /&gt;
&amp;lt;section name=&amp;quot;Server&amp;quot; class=&amp;quot;server&amp;quot; show=&amp;quot;true&amp;quot;&amp;gt;&lt;br /&gt;
This example will output a chat message anywhere within 50ms of a player changing their in-vehicle-state according to [[isPlayerActuallyInVehicle]].&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
local allPlayers = {}&lt;br /&gt;
function resStart()&lt;br /&gt;
	for i,v in ipairs(getElementsByType(&amp;quot;player&amp;quot;)) do&lt;br /&gt;
		allPlayers[v] = isPlayerActuallyInVehicle(v)&lt;br /&gt;
	end&lt;br /&gt;
	setTimer(checkInterval,50,0)&lt;br /&gt;
end&lt;br /&gt;
addEventHandler(&amp;quot;onResourceStart&amp;quot;,getResourceRootElement(getThisResource()),resStart)&lt;br /&gt;
&lt;br /&gt;
function addPlayer()&lt;br /&gt;
	allPlayers[source] = isPlayerActuallyInVehicle(source)&lt;br /&gt;
end&lt;br /&gt;
addEventHandler(&amp;quot;onPlayerJoin&amp;quot;,getRootElement(),addPlayer)&lt;br /&gt;
&lt;br /&gt;
function checkInterval()&lt;br /&gt;
	for k,v in pairs(allPlayers) do&lt;br /&gt;
		local result = isPlayerActuallyInVehicle(k)&lt;br /&gt;
		if not v == result then&lt;br /&gt;
			outputChatBox(getPlayerName(k)..&amp;quot; changed their in vehicle state to &amp;quot;..tostring(result))&lt;br /&gt;
			allPlayers[k] = result&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;/section&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Author: [[User:Dragon]]&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
{{Useful_Functions}}&lt;/div&gt;</summary>
		<author><name>Dragon</name></author>
	</entry>
</feed>