<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.multitheftauto.com/wiki/GetElementResourceName?action=history&amp;feed=atom</id>
	<title>GetElementResourceName - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.multitheftauto.com/wiki/GetElementResourceName?action=history&amp;feed=atom"/>
	<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=GetElementResourceName&amp;action=history"/>
	<updated>2026-05-02T16:45:28Z</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=GetElementResourceName&amp;diff=82249&amp;oldid=prev</id>
		<title>Arran Fortuna: Created page with &quot;__NOTOC__ {{Useful Function}} This function returns the name of the resource that created an element.  ==Syntax== &lt;syntaxhighlight lang=&quot;lua&quot;&gt; string getElementResourceName ( element theElement ) &lt;/syntaxhighlight&gt;  ===Required arguments=== * '''theElement''': the element you want to get the resource name of.  ==Returns== This function always returns a ''string'' containing the element's creator or a string containing information on how it failed to do so.  ==Cod...&quot;</title>
		<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=GetElementResourceName&amp;diff=82249&amp;oldid=prev"/>
		<updated>2025-07-21T09:27:58Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;__NOTOC__ {{Useful Function}} This function returns the name of the resource that created an element.  ==Syntax== &amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt; string getElementResourceName ( element theElement ) &amp;lt;/syntaxhighlight&amp;gt;  ===Required arguments=== * &amp;#039;&amp;#039;&amp;#039;theElement&amp;#039;&amp;#039;&amp;#039;: the &lt;a href=&quot;/wiki/Element&quot; title=&quot;Element&quot;&gt;element&lt;/a&gt; you want to get the resource name of.  ==Returns== This function always returns a &amp;#039;&amp;#039;string&amp;#039;&amp;#039; containing the &lt;a href=&quot;/wiki/Element&quot; title=&quot;Element&quot;&gt;element&lt;/a&gt;&amp;#039;s creator or a string containing information on how it failed to do so.  ==Cod...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;__NOTOC__&lt;br /&gt;
{{Useful Function}}&lt;br /&gt;
This function returns the name of the resource that created an element.&lt;br /&gt;
&lt;br /&gt;
==Syntax==&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
string getElementResourceName ( element theElement )&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Required arguments===&lt;br /&gt;
* '''theElement''': the [[element]] you want to get the resource name of.&lt;br /&gt;
&lt;br /&gt;
==Returns==&lt;br /&gt;
This function always returns a ''string'' containing the [[element]]'s creator or a string containing information on how it failed to do so.&lt;br /&gt;
&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 getElementResourceName(element)&lt;br /&gt;
    if not isElement(element) then&lt;br /&gt;
        return &amp;quot;Invalid element&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    local maxHops = 50&lt;br /&gt;
    local path = getElementType(element)&lt;br /&gt;
    local chain = { element }&lt;br /&gt;
&lt;br /&gt;
    -- Build parent chain&lt;br /&gt;
    local current = element&lt;br /&gt;
    while current and maxHops &amp;gt; 0 do&lt;br /&gt;
        current = getElementParent(current)&lt;br /&gt;
        if current then&lt;br /&gt;
            table.insert(chain, current)&lt;br /&gt;
            path = path .. &amp;quot; -&amp;gt; &amp;quot; .. getElementType(current)&lt;br /&gt;
        end&lt;br /&gt;
        maxHops = maxHops - 1&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    -- Try to match one of the parents to a resource root&lt;br /&gt;
    for _, res in ipairs(getResources()) do&lt;br /&gt;
        local resRoot = getResourceRootElement(res)&lt;br /&gt;
        for _, ancestor in ipairs(chain) do&lt;br /&gt;
            if ancestor == resRoot then&lt;br /&gt;
                return getResourceName(res)&lt;br /&gt;
            end&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    return &amp;quot;No matching resource found (path: &amp;quot; .. path .. &amp;quot;)&amp;quot;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/section&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
{{Useful_Functions}}&lt;/div&gt;</summary>
		<author><name>Arran Fortuna</name></author>
	</entry>
</feed>