<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.gtaconnected.com/wiki/index.php?action=history&amp;feed=atom&amp;title=Template%3AScriptingExamples%2FUtilityCode%2FLua%2FgetClientFromText</id>
	<title>Template:ScriptingExamples/UtilityCode/Lua/getClientFromText - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.gtaconnected.com/wiki/index.php?action=history&amp;feed=atom&amp;title=Template%3AScriptingExamples%2FUtilityCode%2FLua%2FgetClientFromText"/>
	<link rel="alternate" type="text/html" href="https://wiki.gtaconnected.com/wiki/index.php?title=Template:ScriptingExamples/UtilityCode/Lua/getClientFromText&amp;action=history"/>
	<updated>2026-04-13T00:48:30Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.39.15</generator>
	<entry>
		<id>https://wiki.gtaconnected.com/wiki/index.php?title=Template:ScriptingExamples/UtilityCode/Lua/getClientFromText&amp;diff=3811&amp;oldid=prev</id>
		<title>Mex: Mex moved page Template:ScriptingExamples/UtilityCode/getClientFromText to Template:ScriptingExamples/UtilityCode/Lua/getClientFromText</title>
		<link rel="alternate" type="text/html" href="https://wiki.gtaconnected.com/wiki/index.php?title=Template:ScriptingExamples/UtilityCode/Lua/getClientFromText&amp;diff=3811&amp;oldid=prev"/>
		<updated>2018-08-14T08:08:55Z</updated>

		<summary type="html">&lt;p&gt;Mex moved page &lt;a href=&quot;/Template:ScriptingExamples/UtilityCode/getClientFromText&quot; class=&quot;mw-redirect&quot; title=&quot;Template:ScriptingExamples/UtilityCode/getClientFromText&quot;&gt;Template:ScriptingExamples/UtilityCode/getClientFromText&lt;/a&gt; to &lt;a href=&quot;/Template:ScriptingExamples/UtilityCode/Lua/getClientFromText&quot; title=&quot;Template:ScriptingExamples/UtilityCode/Lua/getClientFromText&quot;&gt;Template:ScriptingExamples/UtilityCode/Lua/getClientFromText&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;function getClientFromText(text)&lt;br /&gt;
    local clients = getClients()&lt;br /&gt;
    local textLower = text:lower()&lt;br /&gt;
    local textLength = text:len()&lt;br /&gt;
&lt;br /&gt;
    -- player id&lt;br /&gt;
    local textNumber = tonumber(text, 10)&lt;br /&gt;
    if textNumber then&lt;br /&gt;
        for i,client in ipairs(clients) do&lt;br /&gt;
            if client.player.id == textNumber then&lt;br /&gt;
                return client&lt;br /&gt;
            end&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    -- player full name (case-insensitive)&lt;br /&gt;
    for i,client in ipairs(clients) do&lt;br /&gt;
        if client.player.name:lower() == textLower then&lt;br /&gt;
            return client&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    -- player partial name (case-insensitive)&lt;br /&gt;
    for i,client in ipairs(clients) do&lt;br /&gt;
        if client.player.name:lower():find(textLower, 1, true) then&lt;br /&gt;
            return client&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    -- nearest player name match (case-insensitive)&lt;br /&gt;
    local charMatchCounts = {}&lt;br /&gt;
    for i,client in ipairs(clients) do&lt;br /&gt;
        local playerNameChars = {}&lt;br /&gt;
        local playerNameLower = client.player.name:lower()&lt;br /&gt;
        local playerNameLength = client.player.name:len()&lt;br /&gt;
        for i2=1, playerNameLength do&lt;br /&gt;
            table.insert(playerNameChars, playerNameLower:sub(i2, i2))&lt;br /&gt;
        end&lt;br /&gt;
        local charMatchCount = 0&lt;br /&gt;
        local playerNameCharIndex&lt;br /&gt;
        for i2=1, textLength do&lt;br /&gt;
            playerNameCharIndex = false&lt;br /&gt;
            local textChar = textLower:sub(i2, i2)&lt;br /&gt;
            for i3,playerNameChar in ipairs(playerNameChars) do&lt;br /&gt;
                if textChar == playerNameChar then&lt;br /&gt;
                    charMatchCount = charMatchCount + 1&lt;br /&gt;
                    playerNameCharIndex = i3&lt;br /&gt;
                    break&lt;br /&gt;
                end&lt;br /&gt;
            end&lt;br /&gt;
            if playerNameCharIndex then&lt;br /&gt;
                table.remove(playerNameChars, playerNameCharIndex)&lt;br /&gt;
            end&lt;br /&gt;
        end&lt;br /&gt;
        charMatchCounts[i] = { client, charMatchCount / playerNameLength }&lt;br /&gt;
    end&lt;br /&gt;
    local highestCharMatchCount = 0&lt;br /&gt;
    local highestCharMatchCountClient&lt;br /&gt;
    for i,data in ipairs(charMatchCounts) do&lt;br /&gt;
        if data[2] &amp;gt; highestCharMatchCount then&lt;br /&gt;
            highestCharMatchCount = data[2]&lt;br /&gt;
            highestCharMatchCountClient = data[1]&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
    if highestCharMatchCountClient then&lt;br /&gt;
        return highestCharMatchCountClient&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    -- no match&lt;br /&gt;
    return false&lt;br /&gt;
end&lt;/div&gt;</summary>
		<author><name>Mex</name></author>
	</entry>
</feed>