/*
 * Plugin 1st Made By: Alfred Reynolds.
 * Plugin Modified By: Sharpsniper (Added Many more csay and tsay colors)
 * Plugin Re-edited By: Caveman (took out all the duplicate/broken functions to just leave the edited bits)
 * Plugin re-redited By: Caveman, Added r(ainbow)say, f(licker)say, p(rivate)c(entre)say, p(rivate)t(ype)say and csg(uard)say.
 * Have Fun
*/
 
/* plugin_cavey_display.sma version 0.1a 10:06 28/04/2002 */
 
#include <core>
#include <console>
#include <string>
#include <admin>
#include <adminlib>
 
new STRING_VERSION[MAX_DATA_LENGTH] = "2.50.2";
 
public admin_csay(HLCommand,HLData,HLUserName,UserIndex) {
	new Color[MAX_DATA_LENGTH];
	new Command[MAX_COMMAND_LENGTH];
	new Data[MAX_DATA_LENGTH];
	new Message[MAX_DATA_LENGTH];
	new User[MAX_NAME_LENGTH];
 
	convert_string(HLCommand,Command,MAX_COMMAND_LENGTH);
	convert_string(HLData,Data,MAX_DATA_LENGTH);
	convert_string(HLUserName,User,MAX_NAME_LENGTH);
 
	strbreak(Data,Color,Message,MAX_DATA_LENGTH);
	if (streq(Color,"red")==1) {
		centersay(Message,10,250,10,10);
	} else if ( streq(Color, "blue")==1) {
		centersay(Message,10,10,10,250);
	} else if ( streq(Color, "green")==1) {
		centersay(Message,10,10,250,10);
	} else if ( streq(Color, "white")==1) {
		centersay(Message,10,250,250,250);
	} else if ( streq(Color, "yellow")==1) {
		centersay(Message,10,250,250,10);
	} else if ( streq(Color, "purple")==1) {
		centersay(Message,10,250,10,250);
	} else if ( streq(Color, "terq")==1) {
		centersay(Message,10,63,187,239);
	} else if ( streq(Color, "skyblue")==1) {
		centersay(Message,10,0,0,255);
	} else if ( streq(Color, "brown")==1) {
		centersay(Message,10,139,59,19);
	} else if ( streq(Color, "lime")==1) {
		centersay(Message,10,10,10,250);
	} else if ( streq(Color, "orange")==1) {
		centersay(Message,10,255,148,9);
	} else if ( streq(Color, "teal")==1) {
		centersay(Message,10,0,255,255);
	} else if ( streq(Color, "pink")==1) {
		centersay(Message,10,255,1,115);
	} else if ( streq(Color, "aqua")==1) {
		centersay(Message,10,0,255,255);
	} else if ( streq(Color, "navy")==1) {
		centersay(Message,10,24,0,76);
	} else if ( streq(Color, "olive")==1) {
		centersay(Message,10,128,128,0);
	} else {
		centersay(Data,10,15,250,10);
	}
	log_command(User,Command,Data);
	return PLUGIN_HANDLED;
}
 
new Fsay[3];	/*0 is the timer, 1 is the flag, 2 is the type*/
public admin_fsay(HLCommand,HLData,HLUserName,UserIndex){
	new Command[MAX_COMMAND_LENGTH];
	new Data[MAX_DATA_LENGTH];
	new User[MAX_NAME_LENGTH];
 
	new Timer;	
	new Repeat;
 
	convert_string(HLCommand,Command,MAX_COMMAND_LENGTH);
	convert_string(HLData,Data,MAX_DATA_LENGTH);
	convert_string(HLUserName,User,MAX_NAME_LENGTH);
	log_command(User,Command,Data);
 
	if (UserIndex == 0){
		return PLUGIN_HANDLED;
	}
	if ( Fsay[0] != 0 ) {
		kill_timer(Fsay[0]);
	}
	if (strcasestr(Command, "admin_rsay") != -1){
		Timer = 1;
		Repeat = 1;
		Fsay[2] = 1;
	} else if (strcasestr(Command, "admin_fsay") != -1){
		Timer = 1;
		Repeat = 10;
		Fsay[2] = 2;
	} else if (strcasestr(Command, "admin_csgsay") != -1){
		Timer = 1;
		Repeat = 10;
		Fsay[2] = 3;
	}
	Fsay[0] = set_timer("flickersay", Timer, Repeat, Data);
 
	return PLUGIN_HANDLED;
}
 
public flickersay(Timer,Repeat,HLUser,HLParam){ 
	new Data[MAX_DATA_LENGTH];
 
	new Colours[MAX_DATA_LENGTH];
	new Colour[2][MAX_DATA_LENGTH];
	new Message[MAX_DATA_LENGTH];
 
	new i;
 
	new iRed[2] = 0;
	new iGreen[2] = 0;
	new iBlue[2] = 0;
 
	convert_string(HLParam,Data,MAX_DATA_LENGTH);
 
	strbreak(Data,Colour[0],Colours,MAX_DATA_LENGTH);
	strbreak(Colours,Colour[1],Message,MAX_DATA_LENGTH);
	strinit(Data);
 
	for (i=0;i<2;i++){
		if (strcasestr(Colour[i], "red") != -1){ 
			iRed[i] = 255;
			iGreen[i] = 10;
			iBlue[i] = 10;
		} else if (strcasestr(Colour[i], "green") != -1) {	
			iRed[i] = 10;
			iGreen[i] = 255;
			iBlue[i] = 10;
		} else if (strcasestr(Colour[i], "blue") != -1) {	
			iRed[i] = 10;
			iGreen[i] = 10;
			iBlue[i] = 255;
		} else if ( (strcasestr(Colour[i], "cyan") != -1) || (strcasestr(Colour[i], "teal") != -1) ) {	
			iRed[i] = 10;
			iGreen[i] = 255;
			iBlue[i] = 255;
		} else if ( (strcasestr(Colour[i], "lime") != -1) ) {	
			iRed[i] = 10;
			iGreen[i] = 10;
			iBlue[i] = 250;
		} else if (strcasestr(Colour[i], "skyblue") != -1) {
			iRed[i] = 0;
			iGreen[i] = 0;
			iBlue[i] = 255;
		} else if (strcasestr(Colour[i], "magenta") != -1) {
			iRed[i] = 255;
			iGreen[i] = 10;
			iBlue[i] = 255;
		} else if (strcasestr(Colour[i], "yellow") != -1) {
			iRed[i] = 255;
			iGreen[i] = 255;
			iBlue[i] = 10;
		} else if (strcasestr(Colour[i], "pink") != -1) {	
			iRed[i] = 252;
			iGreen[i] = 60;
			iBlue[i] = 200;
		} else if (strcasestr(Colour[i], "orange") != -1) {
			iRed[i] = 255;
			iGreen[i] = 100;
			iBlue[i] = 10;
		} else if (strcasestr(Colour[i], "purple") != -1) {
			iRed[i] = 250;
			iGreen[i] = 10;
			iBlue[i] = 250;
		} else if (strcasestr(Colour[i], "turq") != -1) {
			iRed[i] = 63;
			iGreen[i] = 187;
			iBlue[i] = 239;
		} else if (strcasestr(Colour[i], "brown") != -1) {
			iRed[i] = 139;
			iGreen[i] = 59;
			iBlue[i] = 19;
		} else if (strcasestr(Colour[i], "navy") != -1) {
			iRed[i] = 24;
			iGreen[i] = 0;
			iBlue[i] = 76;
		} else if (strcasestr(Colour[i], "white") != -1) {	
			iRed[i] = 255;
			iGreen[i] = 255;
			iBlue[i] = 255;
		} else if (strcasestr(Colour[i], "none") != -1) {	
			iRed[i] = 0;
			iGreen[i] = 0;
			iBlue[i] = 0;
		} else {		/* Default is white fading out */
			strcat(Data, Colour[i],  MAX_DATA_LENGTH);
			strcat(Data, " ",  MAX_DATA_LENGTH);
			iRed[i] = ( 255 - (255*i) );
			iGreen[i] = ( 255 - (255*i) );
			iBlue[i] = ( 255 - (255*i) );
		}
	}
 
	strcat(Data, Message,  MAX_DATA_LENGTH);
 
	if (Fsay[2] == 1){
		rainbow( Data, 10, iRed[0], iGreen[0], iBlue[0], iRed[1], iGreen[1], iBlue[1]);
	} else if (Fsay[2] == 2 && Fsay[1] == 1 ){
		rainbow( Data, Timer, iRed[0], iGreen[0], iBlue[0], iRed[1], iGreen[1], iBlue[1]);
		Fsay[1] = 2;
	} else if (Fsay[2] == 2 && Fsay[1] != 1 ){
		rainbow( Data, Timer, iRed[1], iGreen[1], iBlue[1], iRed[0], iGreen[0], iBlue[0]);
		Fsay[1] = 1;
	} else if (Fsay[2] == 3 && Fsay[1] == 1 ){
		rainbow( Data, Timer, 255, 100, 10, 0, 0, 0);
		Fsay[1] = 2;
	} else if (Fsay[2] == 3 && Fsay[1] != 1 ){
		rainbow( Data, Timer, 0, 0, 0, 255, 100, 10);
		Fsay[1] = 1;
	} 
 
	return PLUGIN_HANDLED;
}
 
public admin_pcsay(HLCommand,HLData,HLUserName,UserIndex) {
	new Command[MAX_COMMAND_LENGTH];
	new Data[MAX_DATA_LENGTH];
	new Msg[MAX_TEXT_LENGTH];
	new Target[MAX_TEXT_LENGTH];
	new TargetName[MAX_NAME_LENGTH];
	new Text[MAX_TEXT_LENGTH];
	new User[MAX_NAME_LENGTH];
 
	convert_string(HLCommand,Command,MAX_COMMAND_LENGTH);
	convert_string(HLData,Data,MAX_DATA_LENGTH);
	convert_string(HLUserName,User,MAX_NAME_LENGTH);
	strbreak(Data, Target, Msg, MAX_TEXT_LENGTH);
 
	if (strlen(Msg) == 0) {
		selfmessage( "Unparsable format: no message found.");
		return PLUGIN_HANDLED;
	} else if (check_user(Target) == 0) {
		selfmessage("Unrecognized player: ");
		selfmessage(Target);
		return PLUGIN_HANDLED;
	}
 
	get_username(Target,TargetName,MAX_NAME_LENGTH);
 
	snprintf(Text, MAX_TEXT_LENGTH, "(Private Msg to %s): %s", TargetName, Msg);
	messageex(User, Text, print_chat);
	if (streq(Command, "admin_pcsay")==1) {
		messageex(TargetName, Msg, print_pretty);
	} else if (streq(Command, "admin_ptsay")==1) {
		messageex(TargetName, Msg, print_tty);
	}
 
	log_command(User,Command,Data);
	return PLUGIN_HANDLED;
}
 
public admin_tsay(HLCommand,HLData,HLUserName,UserIndex) {
	new Command[MAX_COMMAND_LENGTH];
	new Data[MAX_DATA_LENGTH];
	new User[MAX_NAME_LENGTH];
	new Color[MAX_NAME_LENGTH];
	new Message[MAX_DATA_LENGTH];
 
	convert_string(HLCommand,Command,MAX_COMMAND_LENGTH);
	convert_string(HLData,Data,MAX_DATA_LENGTH);
	convert_string(HLUserName,User,MAX_NAME_LENGTH);
 
	strbreak(Data,Color,Message,MAX_DATA_LENGTH);
 
	if (streq(Color,"red")==1) {
		typesay(Message,10,250,10,10);
	} else if ( streq(Color, "blue")==1) {
		typesay(Message,10,10,10,250);
	} else if ( streq(Color, "green")==1) {
		typesay(Message,10,10,250,10);
	} else if ( streq(Color, "white")==1) {
		typesay(Message,10,250,250,250);
	} else if ( streq(Color, "yellow")==1) {
		typesay(Message,10,250,250,10);
	} else if ( streq(Color, "purple")==1) {
		typesay(Message,10,250,10,250);
	} else if ( streq(Color, "terq")==1) {
		typesay(Message,10,63,187,239);
	} else if ( streq(Color, "skyblue")==1) {
		typesay(Message,10,0,0,255);
	} else if ( streq(Color, "brown")==1) {
		typesay(Message,10,139,59,19);
	} else if ( streq(Color, "lime")==1) {
		typesay(Message,10,10,10,250);
	} else if ( streq(Color, "orange")==1) {
		typesay(Message,10,255,148,9);
	} else if ( streq(Color, "teal")==1) {
		typesay(Message,10,0,255,255);
	} else if ( streq(Color, "pink")==1) {
		typesay(Message,10,255,1,115);
	} else if ( streq(Color, "aqua")==1) {
		typesay(Message,10,0,255,255);
	} else if ( streq(Color, "navy")==1) {
		typesay(Message,10,24,0,76);
	} else if ( streq(Color, "olive")==1) {
		typesay(Message,10,128,128,0);
	} else {
		typesay(Data,10,220,220,220);
	}
	log_command(User,Command,Data);
	return PLUGIN_HANDLED;
}
 
public plugin_init() {
	plugin_registerinfo("Caveys Super-Say Plugin","Getting the message accross in style.",STRING_VERSION);
 
	plugin_registercmd("admin_csay","admin_csay",ACCESS_SAY,"admin_csay [color] <msg>: Shows message in center of screen. (Center-say)");
	plugin_registercmd("admin_tsay","admin_tsay",ACCESS_SAY,"admin_tsay [color] <msg>: Prints msg on lower left of screen. (Type-say)");
	plugin_registercmd("admin_rsay","admin_fsay",ACCESS_SAY,"admin_rsay [color] [color] <msg>: Prints msg in center of screen in fading text. (Raindow-say)");
	plugin_registercmd("admin_fsay","admin_fsay",ACCESS_SAY,"admin_fsay [color] [color] <msg>: Prints msg in center of screen in flickering text. (Flicker-say)");
	plugin_registercmd("admin_csgsay","admin_fsay",ACCESS_SAY,"admin_csgsaysay <msg>: Prints msg in center of screen in flickering CSGuard style text. (CSG-Say)");
	plugin_registercmd("admin_ptsay","admin_pcsay",ACCESS_SAY,"admin_ptsay <User> <Message>: Private typesay to a user");
	plugin_registercmd("admin_pcsay","admin_pcsay",ACCESS_SAY,"admin_pcsay <User> <Message>: Private centersay to a user");
 
	return PLUGIN_CONTINUE;
}