<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.multitheftauto.com/wiki/GetPlayersInRange?action=history&amp;feed=atom</id>
	<title>GetPlayersInRange - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.multitheftauto.com/wiki/GetPlayersInRange?action=history&amp;feed=atom"/>
	<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=GetPlayersInRange&amp;action=history"/>
	<updated>2026-04-14T08:58:25Z</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=GetPlayersInRange&amp;diff=67446&amp;oldid=prev</id>
		<title>Logan: /* Syntax */</title>
		<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=GetPlayersInRange&amp;diff=67446&amp;oldid=prev"/>
		<updated>2020-10-03T12:35:02Z</updated>

		<summary type="html">&lt;p&gt;&lt;span dir=&quot;auto&quot;&gt;&lt;span class=&quot;autocomment&quot;&gt;Syntax&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{Note|You can use [[CountPlayersInRange|countPlayersInRange]] if you want count players in the range.}}&lt;br /&gt;
{{Useful Function}}&lt;br /&gt;
==Syntax==&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
table getPlayersInRange(element thePlayer, float range)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Required Arguments===&lt;br /&gt;
* '''thePlayer''' : The player you want to get the players in range.&lt;br /&gt;
* '''range''' : Range size.&lt;br /&gt;
===Returns===&lt;br /&gt;
Returns a table of players that are within a certain range if there is minimum 1 player else it returns false.&lt;br /&gt;
==Code==&lt;br /&gt;
&amp;lt;section name=&amp;quot;Function source&amp;quot; class=&amp;quot;both&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 getPlayersInRange (playerSource,range)&lt;br /&gt;
	local allPlayers = getElementsByType(&amp;quot;player&amp;quot;); &lt;br /&gt;
	local x,y,z = getElementPosition(playerSource);&lt;br /&gt;
	local count = 0;&lt;br /&gt;
	local players = {}&lt;br /&gt;
	for k, v in ipairs(allPlayers) do &lt;br /&gt;
		if(v and playerSource)then&lt;br /&gt;
			if not(v == playerSource)then&lt;br /&gt;
					local Sx,Sy,Sz = getElementPosition(v);&lt;br /&gt;
					local distance = getDistanceBetweenPoints3D(x,y,z,Sx,Sy,Sz);&lt;br /&gt;
					if(distance &amp;lt;= range)then&lt;br /&gt;
					count = count +1&lt;br /&gt;
					players[v] = v; &lt;br /&gt;
				end&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
	end &lt;br /&gt;
	if(count == 0)then&lt;br /&gt;
		return false;&lt;br /&gt;
	else&lt;br /&gt;
		return players;&lt;br /&gt;
	end&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;
* [ Created By ; IDARED ]&lt;br /&gt;
&lt;br /&gt;
==See Also==&lt;br /&gt;
{{Useful_Functions}}&lt;/div&gt;</summary>
		<author><name>Logan</name></author>
	</entry>
</feed>