<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.multitheftauto.com/wiki/HexColorToRGB?action=history&amp;feed=atom</id>
	<title>HexColorToRGB - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.multitheftauto.com/wiki/HexColorToRGB?action=history&amp;feed=atom"/>
	<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=HexColorToRGB&amp;action=history"/>
	<updated>2026-05-15T07:36:44Z</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=HexColorToRGB&amp;diff=71984&amp;oldid=prev</id>
		<title>Tracer: This function covers all types of colors including original HEX ones, hex shortcuts and MTA tocolor values.</title>
		<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=HexColorToRGB&amp;diff=71984&amp;oldid=prev"/>
		<updated>2021-08-27T14:18:08Z</updated>

		<summary type="html">&lt;p&gt;This function covers all types of colors including original HEX ones, hex shortcuts and MTA tocolor values.&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 converts hex string to RGBA values.&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Syntax==&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
int, int, int, int hexColorToRGB(string/int hex_color)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Returns===&lt;br /&gt;
Returns R, G, B, A colors if successful, otherwise false.&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 hexColorToRGB(hex)&lt;br /&gt;
    hex = (type(hex) == 'number') and '0x'..('%x'):format(hex):gsub('%l', string.upper) or hex&lt;br /&gt;
    if hex:match('^0x%x%x%x%x%x%x%x%x$') then&lt;br /&gt;
        local a = tonumber('0x'..hex:sub(3,4))&lt;br /&gt;
        local r = tonumber('0x'..hex:sub(5,6))&lt;br /&gt;
        local g = tonumber('0x'..hex:sub(7,8))&lt;br /&gt;
        local b = tonumber('0x'..hex:sub(9,10))&lt;br /&gt;
        return r,g,b,a&lt;br /&gt;
    elseif hex:match('^#%x%x%x$') then&lt;br /&gt;
        local r = tonumber('0x'..hex:sub(2,2)..hex:sub(2,2))&lt;br /&gt;
        local g = tonumber('0x'..hex:sub(3,3)..hex:sub(3,3))&lt;br /&gt;
        local b = tonumber('0x'..hex:sub(4,4)..hex:sub(4,4))&lt;br /&gt;
        return r,g,b,255&lt;br /&gt;
    elseif hex:match('^#%x%x%x%x%x%x$') then&lt;br /&gt;
        local r = tonumber('0x'..hex:sub(2,3))&lt;br /&gt;
        local g = tonumber('0x'..hex:sub(4,5))&lt;br /&gt;
        local b = tonumber('0x'..hex:sub(6,7))&lt;br /&gt;
        return r,g,b,255&lt;br /&gt;
    else return false,false,false,false 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;
==Example==&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;
local color1 = 0xFFFF0000 -- the slowest&lt;br /&gt;
local color2 = '0xFFFF0000'&lt;br /&gt;
local color3 = '#FF0000'&lt;br /&gt;
local color4 = '#F00' -- the fastest&lt;br /&gt;
&lt;br /&gt;
iprint(hexColorToRGB(color1)) -- 255, 0, 0, 255&lt;br /&gt;
iprint(hexColorToRGB(color2)) -- 255, 0, 0, 255&lt;br /&gt;
iprint(hexColorToRGB(color3)) -- 255, 0, 0, 255&lt;br /&gt;
iprint(hexColorToRGB(color4)) -- 255, 0, 0, 255&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/section&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Author: Tracer&lt;br /&gt;
&lt;br /&gt;
==See Also==&lt;br /&gt;
{{Useful_Functions}}&lt;/div&gt;</summary>
		<author><name>Tracer</name></author>
	</entry>
</feed>