Results 1 to 10 of 16

Thread: How to change colors ingame?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Private
    Join Date
    Oct 2012
    Posts
    10
    Thanks
    2
    Thanked 22 Times in 8 Posts
    HTML and Decimal support:
    Code:
    setHtmlColor(code)
    {
    	if(!isDefined(code) || isDefined(code) && (code[0]=="#" && code.size!=7 || code[0]!="#" && code.size!=6))
    		return (1,1,1);
    	
    	if(code[0]=="#")
    		code=getSubStr(code,1,code.size);
    	hex=[];
    	for(i=0;i<code.size;i++)
    		hex[hex.size]=""+code[i];
    	for(i=0;i<hex.size;i++)
    	{
    		switch(toLower(hex[i]))
    		{
    			case "a":
    				hex[i]=10;
    				break;
    			case "b":
    				hex[i]=11;
    				break;
    			case "c":
    				hex[i]=12;
    				break;
    			case "d":
    				hex[i]=13;
    				break;
    			case "e":
    				hex[i]=14;
    				break;
    			case "f":
    				hex[i]=15;
    				break;
    			default:
    				hex[i]=int(hex[i]);
    				break;
    		}
    	}
    	r=(hex[0]*16)+hex[1];
    	g=(hex[2]*16)+hex[3];
    	b=(hex[4]*16)+hex[5];
    	
    	return setDecimalColor((r,g,b));
    }
    
    setDecimalColor(rgb)
    {
    	if(!isDefined(rgb))
    		return (1,1,1);
    	
    	if(rgb[0]<0 || rgb[0]>255)
    		rgb[0]=255;
    	if(rgb[1]<0 || rgb[1]>255)
    		rgb[1]=255;
    	if(rgb[2]<0 || rgb[2]>255)
    		rgb[2]=255;
    	
    	return (1/(255/rgb[0]),1/(255/rgb[1]),1/(255/rgb[2]));
    }
    Examples:
    Code:
    rgb=setHtmlColor("#1A1B1C");
    setCvar("g_TeamColor_Allies", rgb[0]+" "+rgb[1]+" "+rgb[2]);
    Code:
    rgb=setHtmlColor("#1A1B1C");
    
    new_hud=newHudElem();
    new_hud.horzAlign="center_safearea";
    new_hud.vertAlign="center_safearea";
    new_hud.alignX="center";
    new_hud.alignY="center";
    new_hud.x=0;
    new_hud.y=0;
    new_hud.color=rgb;
    new_hud.alpha=1;
    new_hud setText(&"HUD Example");
    Have fun!^^
    Last edited by DisSle; 5th April 2014 at 16:16.

  2. The Following 6 Users Say Thank You to DisSle For This Useful Post:

    Jeplaa (5th April 2014),kung foo man (5th April 2014),Mitch (5th April 2014),Ni3ls (5th April 2014),RobsoN (5th April 2014),Rocky (5th April 2014)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •