#include <amxmodx>

enum Icon {
	C4,
	Escape,
	Rescue,
	Defuser,
	Buyzone,
	VipSafety
}

new Cvars[Icon]
new CvarsDefaultValues[Icon][] = { "255 100 0", "255 215 0", "255 100 0 ", "0 100 255","0 160 0","0 160 0"}
new IconNames[Icon][] = {"c4","escape","rescue","defuser","buyzone","vipsafety"}

new Trie:TrieIconNames

public plugin_init() {
	register_plugin( "Icons Color Changer", "1.0", "xPaw" );
	
	TrieIconNames = TrieCreate();
	
	new cvarName[20]
	
	new append = formatex(cvarName, charsmax(cvarName), "icons_");
	
	for(new Icon:i = C4 ; i<Icon;i++) {
		formatex(cvarName[append], charsmax(cvarName) - append, IconNames[i]);
		Cvars[i] = register_cvar(cvarName,CvarsDefaultValues[i]);
		
		TrieSetCell(TrieIconNames,IconNames[i],i);
	}
	
	register_message( get_user_msgid("StatusIcon"), "msgStatusIcon" );
}

public msgStatusIcon( msgId, msgDest, id ) {
	if( get_msg_arg_int( 1 ) == 0 )
		return PLUGIN_CONTINUE;
	
	new szIcon[10]
	get_msg_arg_string( 2, szIcon, 9 );
	
	new Icon:icon
	
	if( TrieGetCell(TrieIconNames,szIcon,icon) ) {
		new szColor[ 12 ], rgb[ 3 ][ 4 ], iRed, iGreen, iBlue;
		
		get_pcvar_string( Cvars[icon] , szColor, charsmax( szColor ) );
		parse( szColor, rgb[ 0 ], 3 , rgb[ 1 ], 3 , rgb[ 2 ], 3 );

		iRed	= clamp( str_to_num( rgb[ 0 ] ), 0, 255 );
		iGreen	= clamp( str_to_num( rgb[ 1 ] ), 0, 255 );
		iBlue	= clamp( str_to_num( rgb[ 2 ] ), 0, 255 );
		
		set_msg_arg_int( 3, ARG_BYTE, iRed );
		set_msg_arg_int( 4, ARG_BYTE, iGreen );
		set_msg_arg_int( 5, ARG_BYTE, iBlue );
	}
	
	return PLUGIN_CONTINUE;
}