Code: Select all
function ColorizeText takes integer red, integer green, integer blue, string text returns string
local string d = ""
local integer i = 1
local integer x
if red>255 then
set red = 255
else
if red<0 then
set red = 0
endif
endif
if green>255 then
set green = 255
else
if green<0 then
set green = 0
endif
endif
if blue>255 then
set blue = 255
else
if blue<0 then
set blue = 0
endif
endif
loop
exitwhen i>2
set x = ModuloInteger(red, 16)
set red = (red-x)/16
if x<10 then
set d = I2S(x) + d
endif
if x == 10 then
set d = "A" + d
endif
if x == 11 then
set d = "B" + d
endif
if x == 12 then
set d = "C" + d
endif
if x == 13 then
set d = "D" + d
endif
if x == 14 then
set d = "E" + d
endif
if x == 15 then
set d = "F" + d
endif
set i = i + 1
endloop
loop
exitwhen i>4
set x = ModuloInteger(green, 16)
set green = (green-x)/16
if x<10 then
set d = I2S(x) + d
endif
if x == 10 then
set d = "A" + d
endif
if x == 11 then
set d = "B" + d
endif
if x == 12 then
set d = "C" + d
endif
if x == 13 then
set d = "D" + d
endif
if x == 14 then
set d = "E" + d
endif
if x == 15 then
set d = "F" + d
endif
set i = i + 1
endloop
loop
exitwhen i>6
set x = ModuloInteger(blue, 16)
set blue = (blue-x)/16
if x<10 then
set d = I2S(x) + d
endif
if x == 10 then
set d = "A" + d
endif
if x == 11 then
set d = "B" + d
endif
if x == 12 then
set d = "C" + d
endif
if x == 13 then
set d = "D" + d
endif
if x == 14 then
set d = "E" + d
endif
if x == 15 then
set d = "F" + d
endif
set i = i + 1
endloop
return "|c00" + d + text + "|r"
endfunction
UPDATE: It didn't need to have three local strings, so I redid it to work with one local string.