<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.multitheftauto.com/wiki/Table.element?action=history&amp;feed=atom</id>
	<title>Table.element - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.multitheftauto.com/wiki/Table.element?action=history&amp;feed=atom"/>
	<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=Table.element&amp;action=history"/>
	<updated>2026-05-10T13:11:32Z</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=Table.element&amp;diff=65233&amp;oldid=prev</id>
		<title>Enargy: Created page with &quot;{{Useful Function}} &lt;lowercasetitle&gt;&lt;/lowercasetitle&gt; __NOTOC__ This function allows you to search within a table of any size or dimensions, userdata values.  ==Syntax== &lt;synt...&quot;</title>
		<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=Table.element&amp;diff=65233&amp;oldid=prev"/>
		<updated>2020-02-22T23:30:20Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;{{Useful Function}} &amp;lt;lowercasetitle&amp;gt;&amp;lt;/lowercasetitle&amp;gt; __NOTOC__ This function allows you to search within a table of any size or dimensions, userdata values.  ==Syntax== &amp;lt;synt...&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;
&amp;lt;lowercasetitle&amp;gt;&amp;lt;/lowercasetitle&amp;gt;&lt;br /&gt;
__NOTOC__&lt;br /&gt;
This function allows you to search within a table of any size or dimensions, userdata values.&lt;br /&gt;
&lt;br /&gt;
==Syntax==&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;table table.element( table tbl[, string theType=nil ] )&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Required Arguments===&lt;br /&gt;
* '''tbl''': The table for search within.&lt;br /&gt;
&lt;br /&gt;
===Optional Arguments===&lt;br /&gt;
* '''theType''': The type of element you want a list of. For example:&lt;br /&gt;
** '''&amp;quot;player&amp;quot;'''&lt;br /&gt;
** '''&amp;quot;vehicle&amp;quot;'''&lt;br /&gt;
** '''&amp;quot;ped&amp;quot;'''&lt;br /&gt;
&lt;br /&gt;
===Returns===&lt;br /&gt;
Returns a new table with only userdata content.&lt;br /&gt;
&lt;br /&gt;
==Code==&lt;br /&gt;
&amp;lt;section name=&amp;quot;Server- and/or clientside Script&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 table.element(t, elemType, _aux)&lt;br /&gt;
	local elem = _aux or {}&lt;br /&gt;
	for k, v in pairs(t) do&lt;br /&gt;
		if (type(v) == &amp;quot;table&amp;quot;) then&lt;br /&gt;
			table.element(v, elemType, elem)&lt;br /&gt;
		else&lt;br /&gt;
			if (type(v) == &amp;quot;userdata&amp;quot;) then&lt;br /&gt;
				if elemType then&lt;br /&gt;
					if (getElementType(v) == elemType) then&lt;br /&gt;
						table.insert(elem, v)&lt;br /&gt;
					end&lt;br /&gt;
				else&lt;br /&gt;
					table.insert(elem, v)&lt;br /&gt;
				end&lt;br /&gt;
			end&lt;br /&gt;
		end	&lt;br /&gt;
	end&lt;br /&gt;
	return elem&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- and/or clientside Script&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;
local vehicle = createVehicle(411, 0, 0, 0)&lt;br /&gt;
local ped = createPed(200, 0, 0, 0)&lt;br /&gt;
&lt;br /&gt;
local myTable = {&lt;br /&gt;
	[&amp;quot;randomsh*t&amp;quot;] = {&lt;br /&gt;
		localPlayer,&lt;br /&gt;
		{localPlayer},&lt;br /&gt;
		{{localPlayer, ped, &amp;quot;I Luv U&amp;quot;, 20, false, true}},&lt;br /&gt;
		{[&amp;quot;player&amp;quot;] = localPlayer},&lt;br /&gt;
		[&amp;quot;vehicle&amp;quot;] = vehicle,&lt;br /&gt;
		45778972,&lt;br /&gt;
		&amp;quot;Hello World&amp;quot;,&lt;br /&gt;
		true,&lt;br /&gt;
		ped&lt;br /&gt;
	},&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
local info = table.element(myTable)&lt;br /&gt;
&lt;br /&gt;
for index, value in ipairs(info) do&lt;br /&gt;
	outputChatBox(&amp;quot;The type of element is: &amp;quot; .. getElementType(value))&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- output:&lt;br /&gt;
-- The type of element is: player&lt;br /&gt;
-- The type of element is: player&lt;br /&gt;
-- The type of element is: player&lt;br /&gt;
-- The type of element is: ped&lt;br /&gt;
-- The type of element is: player&lt;br /&gt;
-- The type of element is: ped&lt;br /&gt;
-- The type of element is: vehicle&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/section&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Author: Enargy&lt;br /&gt;
&lt;br /&gt;
==See Also==&lt;br /&gt;
{{Useful_Functions}}&lt;/div&gt;</summary>
		<author><name>Enargy</name></author>
	</entry>
</feed>