getColorFromString | Multi Theft Auto: Wiki Skip to content

getColorFromString

Client-side
Server-side
Shared

This page is incomplete! Help wanted!

Please finish this page using the corresponding Old Wiki article.
Go to Contribution guidelines for more information.


This function will extract Red, Green, Blue and Alpha values from a hex string you provide it. These strings follow the same format as used in HTML, with addition of the Alpha values.

Syntax

getColorFromString ( )

Code Examples

server

This example will set the blip attached to a player to a color they specify by typingset_my_color [color]in the console.

function setPlayerBlipColor ( playerSource, commandName, colorString )
local red, green, blue, alpha = getColorFromString ( colorString ) -- convert the color string to numbers
local playerBlip = getBlipAttachedTo ( playerSource ) -- find the blip attached to the player
if ( playerBlip and red ) then -- check a blip is attached to the player and that a valid color was specified
setBlipColor ( playerBlip, red, green, blue, alpha ) -- set the player's blip color
end
end
addCommandHandler ( "set_my_color", setPlayerBlipColor )
-- specify the getBlipAttachedTo function
function getBlipAttachedTo( thePlayer )
local blips = getElementsByType( "blip" )
for k, theBlip in ipairs( blips ) do
if getElementAttachedTo( theBlip ) == thePlayer then
return theBlip
end
end
return false
end