/* A plugin for the silly */
 
/* $Id: plugin_fun.sma,v 1.1.2.2 2002/01/13 02:20:40 sbrownlow Exp $ */
/*      Heavily edited 01:04 23/02/2002 by Caveman                   *
 *              to plugin_cavey_advfun,sma v 0.2                     *
 *            - http://gosh.ex.ac.uk/~py99jan/                       */
 
#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 GlowTimer[MAX_PLAYERS];
new StrobeState[MAX_PLAYERS];
 
new iLastAYB = 0;
 
//***********************************************************************************************************************
 
AllYourBaseAreBelongToUs(User[]) {
  new i;
  new iMaxPlayers = maxplayercount();
  new Name[MAX_NAME_LENGTH];
 
  if (systemtime() < iLastAYB) {
    messageex(User, "I think we should wait a little bit longer, don't you?", print_chat);
  } else {
    for (i = 1; i <= iMaxPlayers; i++) {
      if (playerinfo(i,Name,MAX_NAME_LENGTH) == 1) {
        execclient(Name, "speak ^"(p96) all(t20) your(t20) base(t10) are(t20) be(t40) lock(e50) handling(s70) to us^"");
      }
    }
 
    set_timer("ayb1",5,1);
    set_timer("ayb2",25,1); 
    set_timer("ayb3",40,1); 
    iLastAYB = systemtime();
    iLastAYB += 600;
  }
}
 
public ayb1(Timer,Repeat,HLName,HLParam) { 
  centersay("In A.D. 2101^nWar was beginning.^nCaptain: What happen?^nMechanic: Somebody set up us the bomb.^nOperator: We get signal.^nCaptain: What!",15,255,255,255); 
} 
 
public ayb2(Timer,Repeat,HLName,HLParam) { 
  centersay("Operator: Main screen turn on.^nCaptain: It's You!!^nCats: How are you gentlemen !!^nCats: All your base are belong to us.^nCats: You are on the way to destruction.^nCaptain: What you say !!",15,255,255,255); 
} 
 
public ayb3(Timer,Repeat,HLName,HLParam) { 
  centersay("Cats: You have no chance to survive make your time.^nCats: HA HA HA HA ....^nCaptain: Take off every 'zig'!!^nCaptain: You know what you doing.^nCaptain: Move 'zig'.^nCaptain: For great justice.",15,255,255,255); 
} 
 
//***********************************************************************************************************************
 
GlowHelper(User[], Color[]) {
	new i;
	new iGoodColor = 1;
 
	get_userindex(User,i);
	if(GlowTimer[i] != 0){
		kill_timer(GlowTimer[i]);
		GlowTimer[i] = 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) {
		GlowTimer[i] = set_timer("glowFire",1,99999,User);
	} else if ( streq(Color, "strobe")==1) {
		GlowTimer[i] = set_timer("glowStrobe",1,99999,User);
	} else if ( streq(Color, "rainbow")==1) {
		GlowTimer[i] = set_timer("glowRotate",2,99999,User);
	} else if ( streq(Color, "christmas")==1) {
		GlowTimer[i] = set_timer("glowXmas",1,99999,User);
	} else if ( streq(Color, "police")==1) {
		GlowTimer[i] = set_timer("glowPolice",1,99999,User);
	} else if ( streq(Color, "off")==1) {
		glow(User,0,0,0);
	} else {
		iGoodColor = 0;
	}
	if ( streq(Color, "help")==1) {
		messageex(User,"Glow Colours:\nred | blue | fuchsia | skyblue\nlime | aqua | olive | green\nwhite | yellow | purple | darkblue\nteal | pink | orange | gold\noff\nsay glow colour",print_tty);
	}
	return iGoodColor;
}
 
public glowFire(Timer,Repeat,HLName,HLParam){
	new i = 0;
	new User[MAX_NAME_LENGTH];
 
	convert_string(HLParam,User,MAX_NAME_LENGTH);
	get_userindex(User,i);
	if(StrobeState[i] == 0){
		StrobeState[i] = 1;
		glow(User,255,148,9);
	} else {
		StrobeState[i] = 0;
		glow(User,250,10,10);
	}
}
 
public glowPolice(Timer,Repeat,HLName,HLParam){
	new i = 0;
	new User[MAX_NAME_LENGTH];
 
	convert_string(HLParam,User,MAX_NAME_LENGTH);
	get_userindex(User,i);
	if(StrobeState[i] == 0){
		StrobeState[i] = 1;
		glow(User,10,10,250);
	} else {
		StrobeState[i] = 0;
		glow(User,250,10,10);
	}
}
 
public glowRotate(Timer,Repeat,HLName,HLParam){
	new Red;
	new Green;
	new Blue;
	new User[MAX_NAME_LENGTH];
	new i;
	convert_string(HLParam,User,MAX_NAME_LENGTH);
	get_userindex(User,i);
	if(check_user(User)!=0){
		Red = random(256);
		Green = random(256);
		Blue = random(256);
		glow(User,Red,Green,Blue);
	}
}
 
public glowStrobe(Timer,Repeat,HLName,HLParam){
	new Red;
	new Green;
	new Blue;
	new i = 0;
	new User[MAX_NAME_LENGTH];
 
	convert_string(HLParam,User,MAX_NAME_LENGTH);
 
	if(check_user(User)!=0){
		get_userindex(User,i);
		if(StrobeState[i] == 0){
			StrobeState[i] = 1;
			Red = random(256);
			Green = random(256);
			Blue = random(256);
		} else {
			StrobeState[i] = 0;
			Red = 0;
			Green = 0;
			Blue = 0;
		}
		glow(User,Red,Green,Blue);
	}
}
 
public glowXmas(Timer,Repeat,HLName,HLParam){
	new i = 0;
	new User[MAX_NAME_LENGTH];
 
	convert_string(HLParam,User,MAX_NAME_LENGTH);
	get_userindex(User,i);
	if(StrobeState[i] == 0){
		StrobeState[i] = 1;
		glow(User,10,250,10);
	} else {
		StrobeState[i] = 0;
		glow(User,250,10,10);
	}
}
 
KillGlow() {
       new i;
       new iMaxPlayers = maxplayercount();
       new Name[MAX_NAME_LENGTH];
 
       for (i = 1; i <= iMaxPlayers; i++) {
               if(playerinfo(i,Name,MAX_NAME_LENGTH)==1) {
                   glow(Name,0,0,0);
               }
       }
}
 
KillDisco() {
	new i;
	new iMaxPlayers = maxplayercount();
	new Name[MAX_NAME_LENGTH];
 
	for (i = 1; i <= iMaxPlayers; i++) {
		if(playerinfo(i,Name,MAX_NAME_LENGTH)==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;
 
	if(getvar("admin_fun_mode")==0) {
		KillDisco();
	} else {
		for (i = 1; i <= iMaxPlayers; i++) {
			if(playerinfo(i,Name,MAX_NAME_LENGTH)==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");
		KillGlow();
	}
	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];
	new Target[MAX_DATA_LENGTH];
	new strColor[MAX_DATA_LENGTH];
 
	convert_string(HLCommand,Command,MAX_NAME_LENGTH);
	convert_string(HLData,Data,MAX_NAME_LENGTH);
	convert_string(HLUserName,User,MAX_NAME_LENGTH);
 
	strbreak(Data,Target,strColor, MAX_DATA_LENGTH);
 
	/*Checks to see if the input is correct AND that the user has access*/
	if ( ( check_user(Target) == 1 ) && ( access(ACCESS_FUN, User) ) ){
		if (GlowHelper(Target,strColor)==1) {
			selfmessage("Success.");
		} else {
			selfmessage("Unrecognized colour.");
		}
	} else if ( ( getvar("admin_fun_mode")==1 ) || ( access(ACCESS_FUN, User) ) ) {
		if (GlowHelper(User,Data)==1) {
			selfmessage("Success.");
		} else {
			selfmessage("Unrecognized colour.");
		}
	}
	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);
	strstripquotes(Data);
	if (strmatch(Data, "glow ", strlen("glow "))==1) {
		if (getvar("admin_fun_mode") == 0) {
			messageex(User, "Glowing is only allowed during fun mode.", print_chat);
		} 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 {
			  		snprintf(Text, MAX_TEXT_LENGTH, "%s begins glowing %s.", User, strGlow);
			 	}
			  	say(Text);
			} else {
				snprintf(Text, MAX_TEXT_LENGTH, "Sorry, %s, but I don't recognize that 'glow' colour.", User);
				messageex(User, Text, print_chat);
			}
 
		}
	} else if (streq(Data, "movezig") == 1 && getvar("admin_fun_mode")==1) {
		AllYourBaseAreBelongToUs(User);
	}
	return PLUGIN_CONTINUE;
}
 
public admin_fun_say(HLCommand,HLData,HLUserName,UserIndex) {
	new SayFun[MAX_NUMBER_LENGTH];
	get_vaultdata("SAY_FUN", SayFun, MAX_NUMBER_LENGTH);
 
	if ( strtonum(SayFun) == 1 ){
		snprintf(SayFun,MAX_NUMBER_LENGTH,"2");
		set_vaultdata("SAY_FUN",SayFun);
		selfmessage("^"say glow colour^" will be disabled on map change or server restart");
	} else 	if ( strtonum(SayFun) == 2 ){
		snprintf(SayFun,MAX_NUMBER_LENGTH,"1");
		set_vaultdata("SAY_FUN",SayFun);
		plugin_registercmd("say","HandleSay",ACCESS_ALL, "say glow <colour | ^"off^">: Causes you to glow that colour.  Fun mode only.");
	}
 
	return PLUGIN_HANDLED;
}
 
public plugin_init() {
	new SayFun[MAX_NUMBER_LENGTH];
	strinit(SayFun);
 
	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_ALL,"admin_glow [User] <colour | ^"off^">: Causes you to glow that colour.");
	plugin_registercmd("admin_fun_say","admin_fun_say",ACCESS_FUN,"admin_fun_say : Toggles whether ^"say glow colour^" works or not");	
	get_vaultdata("SAY_FUN", SayFun, MAX_NUMBER_LENGTH);
	if ( strtonum(SayFun) == 1 ){
		plugin_registercmd("say","HandleSay",ACCESS_ALL, "say glow <colour | ^"off^">: Causes you to glow that colour.  Fun mode only.");
	} else if ( strtonum(SayFun) == 0 ){
		snprintf(SayFun,MAX_NUMBER_LENGTH,"1");
		set_vaultdata("SAY_FUN",SayFun);
		plugin_registercmd("say","HandleSay",ACCESS_ALL, "say glow <colour | ^"off^">: Causes you to glow that colour.  Fun mode only.");
	}
 
	return PLUGIN_CONTINUE;
}