/* A plugin for the silly */
 
/* $Id $ */
 
/* 
Last Changed: 6/4/01
 
Changes:
1) More colors (static colors thanks to Nikeeee[AMH1987@aol.com])
2) Glow rainbow, strobe and police ([OSU] Guardian Bob[atkinssc@mailbox.orst.edu])
3) Better management of users for glow, (doesn't rely on player index)
4) glow help list the colors
5) movezig removes the words (which blocks users screens)
6) admin_glow2 to make other users glow, without telling them.
*/
 
#include <core>
#include <console>
#include <string>
#include <admin>
#include <adminlib>
 
#define ACCESS_FUN 8192
 
new STRING_VERSION[MAX_DATA_LENGTH] = "2.50.0";
 
new iDiscoCount = 0;
new iDiscoTimer = 0;
 
new iLastAYB = 0;
 
AllYourBaseAreBelongToUs() {
  new i;
  new iMaxPlayers = maxplayercount();
  new Name[MAX_NAME_LENGTH];
 
  if (systemtime() < iLastAYB) {
    say("I think we should wait a little bit longer, don't you?");
  } else {
    for (i = 1; i <= iMaxPlayers; i++) {
      if (playerinfo(i,Name,MAX_NAME_LENGTH) == 1) {
        execclient(Name, "speak ^"all your base are be lock to us^"");
      }
    }
    iLastAYB = systemtime();
    iLastAYB += 120;
  }
}
 
 
new iGlowTimer1[64] = 0;
new iGlowTimer2[64] = 0;
new iGlowStrobe[64] = 0;
new UserLookup[64][MAX_NAME_LENGTH]={ 
"^a", "^a", "^a", "^a", "^a", "^a", "^a", "^a",
"^a", "^a", "^a", "^a", "^a", "^a", "^a", "^a",
"^a", "^a", "^a", "^a", "^a", "^a", "^a", "^a",
"^a", "^a", "^a", "^a", "^a", "^a", "^a", "^a",
"^a", "^a", "^a", "^a", "^a", "^a", "^a", "^a",
"^a", "^a", "^a", "^a", "^a", "^a", "^a", "^a",
"^a", "^a", "^a", "^a", "^a", "^a", "^a", "^a",
"^a", "^a", "^a", "^a", "^a", "^a", "^a", "^a"};
 
LookUP(User[]){
	new pos = -1;
	new returnVal = -1;
	new i;
	for (i = 0; i < 64; i++) {
		if(strcasestr(UserLookup[i], "^a")==1){
			if(check_user(UserLookup[i]) == 0){
				if(iGlowTimer1[i] != 0){
					kill_timer(iGlowTimer1[i]);
					iGlowTimer1[i] = 0;
				}
				if(iGlowTimer2[i] != 0){
					kill_timer(iGlowTimer2[i]);
					iGlowTimer2[i] = 0;
				}
				if(iGlowStrobe[i] != 0){
					iGlowStrobe[i] = 0;
				}
				UserLookup[i][0]='^a';
			}
		}
		if(pos == -1 && UserLookup[i][0]=='^a')
			pos = i;
		if (strmatch(User, UserLookup[i], strlen(User))==1)
			 returnVal = i;
	}
	if(returnVal == -1 && check_user(User) != 0){
		returnVal = pos;
		for(i=0;i<MAX_NAME_LENGTH;i++)
			UserLookup[pos][i]=User[i];
	}
	return returnVal;
}
 
 
 
GlowHelper(User[], Color[]) {
	new iGoodColor = 1;
	new Look;
	Look = LookUP(User);
	if(iGlowTimer1[Look] != 0){
		kill_timer(iGlowTimer1[Look]);
		iGlowTimer1[Look] = 0;
	}
	if(iGlowTimer2[Look] != 0){
		kill_timer(iGlowTimer2[Look]);
		iGlowTimer2[Look] = 0;
	}
	if(iGlowStrobe[Look] != 0){
		iGlowStrobe[Look] = 0;
	}
 
	if ( streq(Color,"red")==1) {
		glow(User,250,10,10);
	} else if ( streq(Color, "blue")==1) {
		glow(User,10,10,250);
	} else if ( streq(Color, "fuchsia")==1) {
		glow(User,255,0,255);
	} else if ( streq(Color, "skyblue")==1) {
		glow(User,0,0,255);
	} else if ( streq(Color, "lime")==1) {
		glow(User,10,10,250);
	} else if ( streq(Color, "brown")==1) {
		glow(User,139,59,19);
	} else if ( streq(Color, "aqua")==1) {
		glow(User,0,255,255);
	} else if ( streq(Color, "olive")==1) {
		glow(User,128,128,0);
	} else if ( streq(Color, "green")==1) {
		glow(User,10,250,10);
	} else if ( streq(Color, "white")==1) {
		glow(User,250,250,250);
	} else if ( streq(Color, "yellow")==1) {
		glow(User,250,250,10);
	} else if ( streq(Color, "purple")==1) {
		glow(User,250,191,36);
	} else if ( streq(Color, "darkblue")==1) {
		glow(User,24,0,76);
	} else if ( streq(Color, "teal")==1) {
		glow(User,0,255,255);
	} else if ( streq(Color, "pink")==1) {
		glow(User,255,1,115);
	} else if ( streq(Color, "orange")==1) {
		glow(User,255,148,9);
	} else if ( streq(Color, "gold")==1) {
		glow(User,248,10,250);
	} else if ( streq(Color, "fire")==1) {
		iGlowTimer2[Look] = set_timer("glowFire",1,99999,User);
	} else if ( streq(Color, "christmas")==1) {
		iGlowTimer2[Look] = set_timer("glowXmas",1,99999,User);
	} else if ( streq(Color, "police")==1) {
		iGlowTimer2[Look] = set_timer("glowPolice",1,99999,User);
	} else if ( streq(Color, "strobe")==1) {
		iGlowTimer2[Look] = set_timer("glowStrobe",1,99999,User);
	} else if ( streq(Color, "rainbow")==1) {
		iGlowTimer1[Look] = set_timer("glowRotate",2,99999,User);
	} else if ( streq(Color, "off")==1) {
		glow(User,0,0,0);
	} else {
		iGoodColor = 0;
	}
	if ( streq(Color, "help")==1) {
                messageex(User,"Glow Colors:\nred | blue | fuchsia | skyblue\nlime | aqua | olive | green\nwhite | yellow | purple | darkblue\nteal | pink | orange | gold\nrainbow | strobe | police | christmas | fire | off\nsay glow color",print_tty);
	}
	return iGoodColor;
}
 
public glowRotate(Timer,Repeat,HLName,HLParam){
	new Red;
	new Green;
	new Blue;
	new User[MAX_NAME_LENGTH];
 
	convert_string(HLParam,User,MAX_NAME_LENGTH);
        LookUP(User);
	if(check_user(User)!=0){
 
		Red = random(256);
		Green = random(256);
		Blue = random(256);
		glow(User,Red,Green,Blue);
	}
}
 
public glowFire(Timer,Repeat,HLName,HLParam){
	new Index = 0;
	new User[MAX_NAME_LENGTH];
 
	convert_string(HLParam,User,MAX_NAME_LENGTH);
	Index = LookUP(User);
	if(iGlowStrobe[Index] == 0){
		iGlowStrobe[Index] = 1;
		glow(User,255,148,9);
	} else {
		iGlowStrobe[Index] = 0;
		glow(User,250,10,10);
	}
}
 
public glowXmas(Timer,Repeat,HLName,HLParam){
	new Index = 0;
	new User[MAX_NAME_LENGTH];
 
	convert_string(HLParam,User,MAX_NAME_LENGTH);
	Index = LookUP(User);
	if(iGlowStrobe[Index] == 0){
		iGlowStrobe[Index] = 1;
		glow(User,10,250,10);
	} else {
		iGlowStrobe[Index] = 0;
		glow(User,250,10,10);
	}
}
 
public glowPolice(Timer,Repeat,HLName,HLParam){
	new Index = 0;
	new User[MAX_NAME_LENGTH];
 
	convert_string(HLParam,User,MAX_NAME_LENGTH);
	Index = LookUP(User);
	if(iGlowStrobe[Index] == 0){
		iGlowStrobe[Index] = 1;
		glow(User,10,10,250);
	} else {
		iGlowStrobe[Index] = 0;
		glow(User,250,10,10);
	}
}
 
public glowStrobe(Timer,Repeat,HLName,HLParam){
	new Red;
	new Green;
	new Blue;
	new Index = 0;
	new User[MAX_NAME_LENGTH];
 
	convert_string(HLParam,User,MAX_NAME_LENGTH);
 
	if(check_user(User)!=0){
		Index = LookUP(User);
		if(iGlowStrobe[Index] == 0){
			iGlowStrobe[Index] = 1;
			Red = random(256);
			Green = random(256);
			Blue = random(256);
		} else {
			iGlowStrobe[Index] = 0;
			Red = 0;
			Green = 0;
			Blue = 0;
		}
		glow(User,Red,Green,Blue);
	}
}
 
 
KillDisco() {
	new i;
	new iMaxPlayers = maxplayercount();
	new Name[MAX_NAME_LENGTH];
	new SessionID;
	new Team;
	new WONID;
 
	for (i = 1; i <= iMaxPlayers; i++) {
		if(playerinfo(i,Name,MAX_NAME_LENGTH,SessionID,WONID,Team)==1) {
			glow(Name,0,0,0);
		}
	}
	centersay("Disco . . . Is Dead.",10,0,255,0);
	kill_timer(iDiscoTimer);
	iDiscoCount = 0;
	iDiscoTimer = 0;
}
 
public DiscoInferno(Timer,Repeat,HLName,HLParam) {
	new i;
	new iDiscoMsg;
	new iMaxPlayers = maxplayercount();
	new Blue;
	new Green;
	new Name[MAX_NAME_LENGTH];
	new Red;
	new SessionID;
	new Team;
	new WONID;
 
	if(getvar("admin_fun_mode")==0) {
		KillDisco();
	} else {
		for (i = 1; i <= iMaxPlayers; i++) {
			if(playerinfo(i,Name,MAX_NAME_LENGTH,SessionID,WONID,Team)==1) {
				Red = random(256);
				Green = random(256);
				Blue = random(256);
				glow(Name,Red,Green,Blue);
			}
		}
		if (iDiscoCount == 0) {
			iDiscoMsg = random(5);
			if (iDiscoMsg == 0) {
				centersay("Uh Uh Uh Uh . . . Staying Alive!",10,Red,Green,Blue);
			} else if (iDiscoMsg == 1) {
				centersay("Disco Inferno, Baby!",10,Red,Green,Blue);
			} else if (iDiscoMsg == 2) {
				centersay("Just Talkin' 'Bout Shaft!",10,Red,Green,Blue);
			} else if (iDiscoMsg == 3) {
				centersay("So . . . What's Your Sign?",10,Red,Green,Blue);
			} else {
				centersay("Ooga Shaka!",10,Red,Green,Blue);
			}
		}
		iDiscoCount++;
		if (iDiscoCount > 20)
			iDiscoCount = 0;
	}
}
 
public admin_disco(HLCommand,HLData,HLUserName,UserIndex) {
	new Command[MAX_COMMAND_LENGTH];
	new Data[MAX_DATA_LENGTH];
	new User[MAX_NAME_LENGTH];
 
	convert_string(HLCommand,Command,MAX_NAME_LENGTH);
	convert_string(HLData,Data,MAX_NAME_LENGTH);
	convert_string(HLUserName,User,MAX_NAME_LENGTH);
	if (getvar("admin_fun_mode")==0) {
		selfmessage("The discotheque can only be turned on if admin_fun_mode is 1.");
	} else if (iDiscoTimer == 0) {
		iDiscoTimer = set_timer("DiscoInferno",5,99999);
		selfmessage("Let the disco begin!");
	} else {
		KillDisco();
	}
	say_command(User,Command,Data);
	return PLUGIN_HANDLED;
}
 
public admin_fun(HLCommand,HLData,HLUserName,UserIndex) {
	new Command[MAX_COMMAND_LENGTH];
	new Data[MAX_DATA_LENGTH];
	new User[MAX_NAME_LENGTH];
 
	convert_string(HLCommand,Command,MAX_NAME_LENGTH);
	convert_string(HLData,Data,MAX_NAME_LENGTH);
	convert_string(HLUserName,User,MAX_NAME_LENGTH);
	if(check_param(Data)==1) {
		execute_command(User,Command,"admin_fun_mode","1");
	} else {
		execute_command(User,Command,"admin_fun_mode","0");
	}
	return PLUGIN_HANDLED;
}
 
public admin_glow(HLCommand,HLData,HLUserName,UserIndex) {
	new Command[MAX_COMMAND_LENGTH];
	new Data[MAX_DATA_LENGTH];
	new User[MAX_NAME_LENGTH];
 
	convert_string(HLCommand,Command,MAX_NAME_LENGTH);
	convert_string(HLData,Data,MAX_NAME_LENGTH);
	convert_string(HLUserName,User,MAX_NAME_LENGTH);
	if (GlowHelper(User,Data)==1) {
		selfmessage("Success.");
	} else {
		selfmessage("Unrecognized color.");
	}
	return PLUGIN_HANDLED;
}
 
public admin_glow2(HLCommand,HLData,HLUserName,UserIndex) {
	new Command[MAX_COMMAND_LENGTH];
	new Data[MAX_DATA_LENGTH];
	new User[MAX_DATA_LENGTH];
	new strColor[MAX_DATA_LENGTH];
	new GlowUser[MAX_DATA_LENGTH];
 
	convert_string(HLCommand,Command,MAX_COMMAND_LENGTH);
	convert_string(HLData,Data,MAX_DATA_LENGTH);
	convert_string(HLUserName,User,MAX_DATA_LENGTH);
	strbreak(Data,GlowUser,strColor, MAX_DATA_LENGTH);
 
	if (check_user(GlowUser)==1) {
		if (GlowHelper(GlowUser,strColor)==1) {
			selfmessage("Success.");
		} else {
			selfmessage("Unrecognized color.");
		}
	} else {
		selfmessage("Unrecognized player: ");
	}
	return PLUGIN_HANDLED;
}
 
public HandleSay(HLCommand,HLData,HLUserName,UserIndex) {
  new i;
  new Command[MAX_COMMAND_LENGTH];
  new Data[MAX_DATA_LENGTH];
  new Length;
  new strGlow[MAX_DATA_LENGTH];
  new Text[MAX_TEXT_LENGTH];
  new User[MAX_NAME_LENGTH];
 
  /* Ignore the console */
  if (UserIndex < 1) 
    return PLUGIN_CONTINUE;
 
  convert_string(HLCommand,Command,MAX_COMMAND_LENGTH);
  convert_string(HLData,Data,MAX_DATA_LENGTH);
  convert_string(HLUserName,User,MAX_NAME_LENGTH);
  if (strmatch(Data, "glow ", strlen("glow "))==1) {
    if (getvar("admin_fun_mode") == 0) {
      say("Glowing is only allowed during fun mode.");
    } else {
			/* we need to strip out 'glow ' (5 characters */
			Length = strlen(Data);
			for(i=5;i<Length+1;i++)
				strGlow[i-5] = Data[i];
			strGlow[i-5] = NULL_CHAR;
 
			if (GlowHelper(User, strGlow) == 1) {
				if (streq(strGlow,"off")==1) {
			    snprintf(Text, MAX_TEXT_LENGTH, "%s is no longer glowing.", User);
				} else if (streq(strGlow,"strobe")==1) {
			    snprintf(Text, MAX_TEXT_LENGTH, "%s begins strobing.", User);
				} else if (streq(strGlow,"rainbow")==1) {
			    snprintf(Text, MAX_TEXT_LENGTH, "%s begins changing colors.", User);
				} else if (streq(strGlow,"police")==1) {
			    snprintf(Text, MAX_TEXT_LENGTH, "%s begins glowing red and blue.", User);
				} else if (streq(strGlow,"christmas")==1) {
			    snprintf(Text, MAX_TEXT_LENGTH, "%s is a christmas tree.", User);
				} else if (streq(strGlow,"fire")==1) {
			    snprintf(Text, MAX_TEXT_LENGTH, "%s is on fire.", User);
				} else {
			  	snprintf(Text, MAX_TEXT_LENGTH, "%s begins glowing %s.", User, strGlow);
			  }
			} else if (streq(strGlow,"help")!=1){
			  snprintf(Text, MAX_TEXT_LENGTH, "Sorry, %s, but I don't recognize that 'glow' color.", User);
			}
			say(Text);
  	}
  } else if (streq(Data, "movezig") == 1) {
    AllYourBaseAreBelongToUs();
  }
  return PLUGIN_CONTINUE;
}
 
public plugin_init() {
	plugin_registerinfo("Fun Plugin","Does silly stuff.",STRING_VERSION);
 
	plugin_registercmd("admin_disco","admin_disco",ACCESS_FUN,"admin_disco: Starts disco fever. Fun mode only.");	
	plugin_registercmd("admin_fun","admin_fun",ACCESS_FUN,"admin_fun <^"on^" | ^"off^">: Turns fun mode on or off.");	
	plugin_registercmd("admin_glow","admin_glow",ACCESS_FUN,"admin_glow <color | ^"off^">: Causes you to glow that color.");
	plugin_registercmd("admin_glow2","admin_glow2",ACCESS_FUN,"admin_glow2 <player> <color | ^"off^">: Causes player to glow that color.");
	plugin_registercmd("say","HandleSay",ACCESS_ALL, "say glow <color | ^"off^">: Causes you to glow that color.  Fun mode only.");
 
	return PLUGIN_CONTINUE;
}