PHP Code:
//#CLIENTSIDE
function onActionGrab() {
temp.hexcolor = genHex();
this.chat = temp.hexcolor;
convertHexToRGB(temp.hexcolor);
this.chat = "Hex " @ temp.hexcolor @ " = RGB(" @ this.rgb @ ")";
this.r = this.rgb[0]/255;
this.g = this.rgb[1]/255;
this.b = this.rgb[2]/255;
setcoloreffect(this.r,this.g,this.b,1);
}
// Generate Hex Color Code
function genHex() {
temp.hexlist = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, "A", "B", "C", "D", "E", "F"};
temp.hex = {0, 0, 0, 0, 0, 0};
for (i=0; i<5; i++){
temp.hex[i] = temp.hexlist[int(random(0,16))];
}
temp.hexcolor = "#" @ temp.hex[0] @ temp.hex[1] @ temp.hex[2] @ temp.hex[3] @ temp.hex[4] @ temp.hex[5];
return temp.hexcolor;
}
// Convert Hex to RGB
function convertHexToRGB(hexcolor) {
temp.hexlist = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, "A", "B", "C", "D", "E", "F"};
temp.hexr1 = temp.hexlist.index(temp.hexcolor.substring(1,1));
temp.hexr0 = temp.hexlist.index(temp.hexcolor.substring(2,1));
temp.hexg1 = temp.hexlist.index(temp.hexcolor.substring(3,1));
temp.hexg0 = temp.hexlist.index(temp.hexcolor.substring(4,1));
temp.hexb1 = temp.hexlist.index(temp.hexcolor.substring(5,1));
temp.hexb0 = temp.hexlist.index(temp.hexcolor.substring(6,1));
temp.r = int(temp.hexr1 * 16^1) + int(temp.hexr0 * 16^0);
temp.g = int(temp.hexg1 * 16^1) + int(temp.hexg0 * 16^0);
temp.b = int(temp.hexb1 * 16^1) + int(temp.hexb0 * 16^0);
this.rgb = {temp.r, temp.g, temp.b};
this.chat = "R:" @ temp.r @ " G:" @ temp.g @ " B:" @ temp.b;
return this.rgb;
}
/*
Quick Conversion Methodology - Hex to Decimal for "A8"
1) Convert Hex Digit to Dec Value
A = 10, 8 = 8
2) Multiply x16^1 for the 1st Dec and x16^0 for the 2nd Dec
10 x 16^1 = 160, 8 x16^0 = 8
3) Add both of them to form the converted value
160 + 8 = 168
*/