//@unloadnpc Event Manager
//@loadnpc npc/thor/EventManager.txt

payon,190,134,4	script	Event Manager	4_F_OPERATION,{
function SetDefault; function ShowStatus; function Event; function Etc;

OnRunEvent:
while(1) {
	mes "[Event Manager]";
	getmapxy(.@map$, @x, @y, 0);
	if (getmapflag(strcharinfo(3), mf_pvp)) {
		mes "Sorry, you can't join event from this map";
		close;
	}
	if (getmapflag(strcharinfo(3), mf_nowarp)) {
		mes "Sorry, you can't join event from this map";
		close;
	}
	if (spectator && strcharinfo(PC_MAP) == "guild_vs2" ) {
		mes "Sorry, you are currently on spectator mode at PVP Match.  Use @match and leave.";
		close;
	}	
	if (spectator && strcharinfo(PC_MAP) == "guild_vs5" ) {
		mes "Sorry, you are currently on spectator mode at BTA.  Use @bta and leave.";
		close;
	}
	if (.deadlock && !Hp) {
		mes "You may not use event when you are dead.";
		close;
	}
	if (ShowStatus(.Active,1)) switch(.Active) {
		//case 6: break;	// No warps necessary for Disguise event.
		case 4: case 7: case 8: if (!.Waiting) break;	// Warp only before the event begins.
		default: set .@warp,1;
	} else mes "There is no ongoing event.";
	next;
	switch(select(
	  ((getgmlevel() < .GMBasic)?":":" > ^FF0000GM Menu^000000:")+
	  ((.@warp && !etatus && .Waiting)?" > ^0055FFWarp to Event^000000:":":")+
	  ((etatus)?" > ^0055FFLeave Event^000000:":":")+
	  " > Event Information:"+
	  (($0_auto)?" > Event Schedule:":":")+
	  " > ^777777Close^000000"
	)) {
		case 1: break;
		case 2: 
			if (.Active == 7) {
				if (Class != .7_job || BaseLevel > .7_max_level) {
					mes "[Event Manager]";
					mes "Sorry, only ^FF0000"+jobname(.7_job)+"^000000";
					mes "between level ^FF0000"+.7_min_level+"^000000 ~ ^FF0000"+.7_max_level+"^000000 can join on this event.";
					switch(select(
	 				 	((.@warp && !etatus && .Waiting)?" > ^0055FFWatch LMS Event^000000:":":")+
			 			 " > ^777777Close^000000"
					)) {
					case 1:
						getmapxy(.@map$, @x, @y, 0);
						set mlastmap$,.@map$;
						set mlastx,@x;
						set mlasty,@y;
						set mstatus,1;
						set mthp,Hp;
						set msp,Sp;
						setoption Option_Invisible, 1;
						sc_start SC_XMAS, 1600000, 0;
						warp getd("."+.Active+"_Map$"),getd("."+.Active+"_MapX"),getd("."+.Active+"_MapY"); 
						close;
					case 2:
						close;
					}
				}	
			}			
			getmapxy(.@map$, @x, @y, 0);
			set elastmap$,.@map$;
			set elastx,@x;
			set elasty,@y;
			set etatus,1;
			set ehp,Hp;
			set esp,Sp;
			percentheal 100, 100;
			queueadd .qid, getcharid(3);
			//debugmes(getcharid(3)+" has been added to event que");
			warp getd("."+.Active+"_Map$"),getd("."+.Active+"_MapX"),getd("."+.Active+"_MapY"); close;
		case 3:
			if (.qid) queueremove .qid, getcharid(3);
			set etatus,0;
			set Hp,ehp;
			set Sp,esp;
			warp elastmap$,elastx,elasty;
			close;
		case 4:
			if (.Active) set .@i, .Active;	// Only show information for active event if one is ongoing.
			else set .@i, select(.menu$);
			mes "[Event Manager]";
			mes "^0055FF ~ "+.Events$[.@i]+" ~^000000";
			switch(.@i) {

				case 1:
					mes "A group of monsters will randomly";
					mes "spawn on a map. Some are normal";
					mes "monsters, and some are not. ";
					mes "Kill the special ones for "+.1_points+" Online Points each.";
					break;
				case 2:
					mes "You will be rewarded when you help end the MvP invasion";
					mes "Anubis will appear when Osiris, Pharao and the Mummys dies";
					mes "AmonRa said that Anubis cloned himself, there are many os falses Anubis.";
					mes "However, just one is the true.";
					break;
				case 3:
					mes "A few monsters will spawn";
					mes "randomly on a map. Find";
					mes "and kill them for rewards!";
					break;
				case 4:
					mes "When the event starts, "+(.4_mobNum +.4_mobFake);
					mes "Porings will spawn. Only "+.4_mobNum;
					mes "is a real Poring with "+.4_points+" Online Points each kill,";
					mes "and "+.4_mobFake+" are fakes. The event ends";
					mes "when all real Poring is killed or.";
					mes "when no one left in the event areas.";
					break;

				case 5:
					mes "You just need to stay AWAY from ";
					mes "anything that you think its DANGEROUS!!";
					mes "Stay alive no matter what!";
					mes "The LAST SURVIVOR will be the WINNER";

					break;
				case 6:
					mes "I will disguise as a random";
					mes "monster. The first player to";
					mes "guess my name correctly";
					mes "will receive "+.6_points+" Online Points.";
					break;
				case 7:
					mes "When the event starts,";
					mes "free-for-all PVP will be";
					mes "turned on. The last player";
					mes "alive is the winner.";
					break;
				case 8:
					mes "When the event starts,";
					mes "Each player picks a box 1, 2, 3 or 4";
					mes "There will be a count down from 10 to 0";
					mes "at 0 a four sided die will be rolled";
					mes "Anyone in the box of the number rolled will be warped to town";
					mes "as well as anyone on the stairs or outside the box";
					mes "the number of players remaining will be announced";
					mes "this prosses will repeat till only one player remains.";
					mes "There will be only 1 winner of "+.8_points+" Online Points";
					break;

			}
			close;
		case 5:
			mes "[Event Manager]";
			set .@k, getarraysize(.Events$);
			freeloop(1);	// Just in case. :D
			for(set .@i,0; .@i<24; set .@i,.@i+1) if ($0_auto&(1<<.@i))
				for(set .@j,1; .@j<.@k; set .@j,.@j+1) if (getd("$"+.@j+"_auto")&(1<<.@i)) {
					mes ((.@i < 10)?"0":"")+.@i+".00: ^0055FF"+.Events$[.@j]+"^000000";
					break;
				}
			freeloop(0);
			close;
		case 6: close;
	}
	while(1) {
		mes "[Event Manager]";
		mes "Select an event to manage.";
		next;
		set .@i, select(.menu$+" ~ Automated events: ~ Set values to default: ~ ^777777Back to main menu...^000000");
		if (.@i == 10) break;
		if (.@i < 8) {
			mes "["+.Events$[.@i]+"]";
			if (!ShowStatus(.@i)) mes "Status: ^777777Inactive^000000";
			next;
		}
		switch(.@i) {
			case 1:
				while(1) {
					set .@j, select(
					  "Wait time ["+.1_wait+" minute"+((.1_wait == 1)?"":"s")+"]:"+	
					  "Monster ["+getmonsterinfo(.1_mobID,0)+"]:"+
					  "Normal Monsters ["+.1_mobNum+"]:"+
					  "Special Monsters ["+.1_mobNumS+"]:"+
					  "Points per kill ["+.1_points+"]:"+
					  "Map ["+.1_Map$+"]:"+
					  ((!.Active)?"^0055FFStart Event^000000:":":")+
					  ((.Active == 1)?"^FF0000End Event^000000:":":")+
					  "^777777Back to event menu...^000000"
					);
					if (.@j == 9) break;
					else if (.@j > 6) Event(1,8-.@j,1);
					if (Etc(1,1)) switch(.@j) {
						case 1:
							message strcharinfo(0),"Players must register during this time.";
							input .1_wait,1,60;
							break;

						case 2:
							input .@s;
							if (Etc(255,.@s)) set .1_mobID, .@s;
							break;
						case 3: input .1_mobNum; break;
						case 4: if (Etc()) input .1_mobNumS,1; break;
						case 5: if (Etc()) input .1_points; break;
						case 6: Etc(1); break;
					}
				}
				break;
			case 2:

				while(1) {
					set .@j, select(
					  "Wait time ["+.2_wait+" minute"+((.2_wait == 1)?"":"s")+"]:"+	
					  "Fake Anubis ["+.2_Fanubis+"]:"+
					  "Mummies ["+.2_MumAmEvent+"]:"+	
					  "Reward for Pharao ["+getitemname(.2_item3)+"]:"+
					  "Reward for Osiris ["+getitemname(.2_item4)+"]:"+
					  "Reward for Anubis ["+getitemname(.2_item2)+"]:"+
					  "Points per Anubis ["+.2_points+"]:"+
					  "Map ["+.2_Map$+"]:"+
					  ((!.Active)?"^0055FFStart Event^000000:":":")+
					  ((.Active == 2)?"^FF0000End Event^000000:":":")+
					  "^777777Back to event menu...^000000"
					);
					if (.@j == 11) break;
					else if (.@j > 8) Event(2,10-.@j,1);
					if (Etc(1,2)) switch(.@j) {
						case 1:
							message strcharinfo(0),"Players must register during this time.";
							input .2_wait,1,60;
							break;
						case 2: input .2_Fanubis,1; break;
						case 3: input .2_MumAmEvent,1; break;
						case 4: input .2_item3,1; break;
						case 5: input .2_item4,1; break;
						case 6: input .2_item2,1; break;
						case 7: if (Etc()) input .2_points; break;
						case 8: Etc(2); break;
					}
				}
				break;
			case 3:
				while(1) {
					set .@j, select(
					  "Monster ["+getmonsterinfo(.3_mobID,0)+"]:"+
					  "Number of Monsters ["+.3_mobNum+"]:"+
					  "Points per kill ["+.3_points+"]:"+
					  "Map ["+.3_Map$+"]:"+
					  ((!.Active)?"^0055FFStart Event^000000:":":")+
					  ((.Active == 3)?"^FF0000End Event^000000:":":")+
					  "^777777Back to event menu...^000000"
					);
					if (.@j == 7) break;
					else if (.@j > 4) Event(3,6-.@j,1);
					if (Etc(1,3)) switch(.@j) {
						case 1:
							set .@list$,"";
							for(set .@k,0; .@k<getarraysize(.3_pre); set .@k,.@k+1)
								set .@list$, .@list$+getmonsterinfo(.3_pre[.@k],0)+":";
							set .@k, select(.@list$+"^0055FFInput monster...:^777777Cancel^000000");
							if (.@k == getarraysize(.3_pre)+1) {
								input .@s;
								if (Etc(255,.@s)) set .3_mobID, .@s;
							} else if (.@k <= getarraysize(.3_pre))
								set .3_mobID, .3_pre[.@k-1];
							break;
						case 2: if (Etc()) input .3_mobNum,1; break;
						case 3: if (Etc()) input .3_points; break;
						case 4: Etc(3); break;
					}
				}
				break;
			case 4:
				while(1) {
					set .@j, select(
					  "Wait time ["+.4_wait+" minute"+((.4_wait == 1)?"":"s")+"]:"+
					  "Points for Winning ["+.4_points+"]:"+
					  "Special Poring["+.4_mobNum+"]:"+
					  "Wrong Poring["+.4_mobFake+"]:"+
					  "Map ["+.4_Map$+"]:"+
					  ((!.Active)?"^0055FFStart Event^000000:":":")+
					  ((.Active == 4)?"^FF0000End Event^000000:":":")+
					  "^777777Back to event menu...^000000"
					);
					if (.@j == 8) break;
					else if (.@j > 5) Event(4,7-.@j,1);
					if (Etc(1,4)) switch(.@j) {
						case 1: input .4_wait,0,60; break;
						case 2: if (Etc()) input .4_points; break;
						case 3: input .4_mobNum,1,500; break;
						case 4: input .4_mobFake,1,500; break;
						case 5: Etc(4); break;
					}
				}
				break;
			case 5:
				while(1) {
					set .@j, select(
					  "Wait time ["+.5_wait+" minute"+((.5_wait == 1)?"":"s")+"]:"+	
					  "Points per kill ["+.5_points+"]:"+
					  "Map ["+.5_Map$+"]:"+
					  ((!.Active)?"^0055FFStart Event^000000:":":")+
					  ((.Active == 5)?"^FF0000End Event^000000:":":")+
					  "^777777Back to event menu...^000000"
					);
					if (.@j == 6) break;
					else if (.@j > 3) Event(5,5-.@j,1);
					if (Etc(1,5)) switch(.@j) {
						case 1: input .5_wait,0,60; break;
						case 2: if (Etc()) input .5_points; break;
						case 3: Etc(5); break;
					}
				}
				break;
			case 6:
				while(1) {
					set .@j, select(
					  "Wait time ["+.6_wait+" minute"+((.6_wait == 1)?"":"s")+"]:"+
					  "Seconds per round ["+.6_time+"]:"+
					  "Number of Rounds ["+.6_rounds+"]:"+
					  "Points per answer ["+.6_points+"]:"+
					  ((!.Active)?"^0055FFStart Event^000000:":":")+
					  ((.Active == 6)?"^FF0000End Event^000000:":":")+
					  "^777777Back to event menu...^000000"
					);
					if (.@j == 7) break;
					else if (.@j > 4) Event(6,6-.@j,1);
					if (Etc(1,6)) switch(.@j) {
						case 1: input .6_wait,0,60; break;
						case 2: input .6_time,1,60; break;
						case 3: input .6_rounds,1; break;
						case 4: if (Etc()) input .6_points,0; break;
					}
				}
				break;
			case 7:
				while(1) {
					set .@j, select(
					  "Wait time ["+.7_wait+" minute"+((.7_wait == 1)?"":"s")+"]:"+
					  "Minimum Players ["+.7_min+"]:"+
					  "Points for Winning ["+.7_points+"]:"+
					  "Job ["+jobname(.7_job)+"]:"+
					  "Minimum Level ["+.7_min_level+"]:"+
					  "Maximum Level ["+.7_max_level+"]:"+
					  ((!.Active)?"^0055FFStart Event^000000:":":")+
					  ((.Active == 7)?"^FF0000End Event^000000:":":")+
					  "^777777Back to event menu...^000000"
					);
					if (.@j == 9) break;
					else if (.@j > 6) Event(7,6-.@j,1);
					if (Etc(1,7)) switch(.@j) {
						case 1:
							message strcharinfo(0),"Players must register during this time.";
							input .7_wait,1,60;
							break;
						case 2:
							message strcharinfo(0),"Event requires at least 2 players to start.";
							input .7_min,2;
							break;
						case 3: if (Etc()) input .7_points; break;
						case 4: message strcharinfo(0),"Select Job";
							input .7_job; break;
						case 5: message strcharinfo(0),"Job Minimum Level";
							input .7_min_level,1; break;
						case 6: message strcharinfo(0),"Job Maximum Level";
							input .7_max_level,1; break;
						case 7: Etc(7); break;
					}
				}
				break;
			case 8:
				while(1) {
					set .@j, select(
					  "Wait time ["+.8_wait+" minute"+((.8_wait == 1)?"":"s")+"]:"+
					  "Minimum Players ["+.8_min+"]:"+
					  "Points for Winning ["+.8_points+"]:"+
					  "Map ["+.8_Map$+"]:"+
					  ((!.Active)?"^0055FFStart Event^000000:":":")+
					  ((.Active == 8)?"^FF0000End Event^000000:":":")+
					  "^777777Back to event menu...^000000"
					);
					if (.@j == 8) break;
					else if (.@j > 4) Event(8,6-.@j,1);
					if (Etc(1,8)) switch(.@j) {
						case 1:
							message strcharinfo(0),"Players must register during this time.";
							input .8_wait,1,60;
							break;
						case 2:
							message strcharinfo(0),"Event requires at least 2 players to start.";
							input .8_min,2;
							break;
						case 3: if (Etc()) input .8_points; break;
						case 4: Etc(8); break;
					}
				}
				break;


			case 9:
				while(1) {
					mes "[Automated Events]";
					if (getgmlevel() < .GMFull) {
						mes "You aren't authorized";
						mes "to change this!";
						next;
						break;
					}
					if (!$0_auto) mes "No events are automated.";
					else for(set .@i,1; .@i<getarraysize(.Events$); set .@i,.@i+1)
						if (getd("$"+.@i+"_auto")) mes .Events$[.@i]+": ^0055FFautomated^000000";
					next;
					set .@i, select("Edit times...:Turn off all automated events:^777777Back to event menu...^000000");
					if (.@i == 1) {
						set .@i, select(.menu$+" > ^777777Cancel^000000");
						if (.@i < getarraysize(.Events$)) while(1) {
							set .@var$, "$"+.@i+"_auto";
							set .@menu$," ~ ^FF0000Finished...^000000:";
							for(set .@j,0; .@j<24; set .@j,.@j+1)
								set .@menu$, .@menu$+" ~ "+((getd(.@var$)&(1<<.@j))?"^0055FF":"^777777")+((.@j < 10)?"0":"")+.@j+".00^000000:";
							set .@j, select(.@menu$)-1;
							if (.@j) {
								set .@k,(1<<(.@j-1));
								if (getd(.@var$)&.@k) set $0_auto, $0_auto^.@k;
								else {
									if ($0_auto&.@k) {
										message strcharinfo(0),"Another event is already scheduled for hour "+(.@j-1)+".";
										set .@k,255;
									} else set $0_auto, $0_auto|.@k;
								}
								if (.@k != 255) setd .@var$, getd(.@var$)^.@k;
							}
							else break;
						}
					} else if (.@i == 2) {
						mes "[Automated Events]";
						mes "Do you really want to turn off";
						mes "all automated event settings?";
						mes "This action cannot be reversed.";
						next;
						if (select(" > ^0055FFYes^000000: > ^777777No^000000") == 1) {
							for(set .@i,1; .@i<getarraysize(.Events$); set.@i,.@i+1)
								setd "$"+.@i+"_auto",0;
							set $0_auto,0;
						}
					} else break;
				}
				break;
			case 10:
				mes "[Event Manager]";
				if (.Active) {
					mes "You can't change settings";
					mes "while an event is active.";
				} else {
					SetDefault(.@EventOption);
					mes "Defaults set.";
				}
				next;
				break;
		}
	}
}
close;

        function xy_wall;
        end;

OnMinute00:	// Automated events at the hour.
	if (.Active) end;	// Stop if an event is already active.
	set .@i, (1<<gettime(3));
	if ($0_auto&.@i) for(set .@j,1; .@j<getarraysize(.Events$); set .@j,.@j+1)
		if (getd("$"+.@j+"_auto")&.@i) {
			SetDefault(1<<(.@j-1));	// Use default values for automated events.
			Event(.@j,1,0);
			set .Active[1], .@j;
			break;
		}
	end;
OnMinute59:	// Automated events can only last 59 minutes before they are forced to end.
	if (.Active[1]) Event(.Active[1],0,0);
	end;

 
On0W:	// Show "!" emotion while warping players to the event map.
	while(.Waiting == 1) {
		emotion e_gasp;
		sleep 2500;
	}
	end;


On1A:
	if (.1_wait) {
		set .Waiting,1;
		donpcevent strnpcinfo(0)+"::On0W";
		announce "The Monster Summon event is now active.  Use @event to join this event.",16;
		for(set .@i,.1_wait; .@i > 0; set .@i,.@i-1){
			announce "The "+.Events$[.Active]+" Event Will begin at [ "+.1_Map$+" ] in "+.@i+" min!. Type @event to join.  Don't worry, you can warp back to your current location using @event > Leave Event anytime.", bc_all, C_AQUA, FW_BOLD, 16;
			sleep 60000;
		}
		if (!.Waiting) end;
		//set .Waiting,0;
	}
	freeloop(true);
	for(set .@i,0; .@i<.1_mobNum; set .@i,++.@i)
		switch(rand(1,3)) {
		case 1:
			monster .1_Map$,0,0,getmonsterinfo(.1_mobID,0),.1_mobID,1,strnpcinfo(0)+"::On1N";
			break;				
		case 2:
			monster .1_Map$,0,0,getmonsterinfo(.1_mobID,0),.1_mobID,1,strnpcinfo(0)+"::On1N";
			break;
		case 3:
			monster .1_Map$,0,0,getmonsterinfo(.1_mobID,0),.1_mobID,1,strnpcinfo(0)+"::On1N";
			break;
		}
	for(set .@i,0; .@i<.1_mobNumS; set .@i,++.@)
		switch(rand(1,3)) {
		case 1:
			monster .1_Map$,0,0,getmonsterinfo(.1_mobID,0),.1_mobID,1,strnpcinfo(0)+"::On1S";
			break;				
		case 2:
			monster .1_Map$,0,0,getmonsterinfo(.1_mobID,0),.1_mobID,1,strnpcinfo(0)+"::On1S";
			break;	
		case 3:
			monster .1_Map$,0,0,getmonsterinfo(.1_mobID,0),.1_mobID,1,strnpcinfo(0)+"::On1S";
			break;
		}
	freeloop(false);
	set .1_mobNum[1], .1_mobNum[0];
	set .1_mobNumS[1], .1_mobNumS[0];
	announce "The Monster Summon event has begun in "+.1_Map$+"! ~ "+.1_mobNumS[1]+" special monsters with "+.1_points+" points ~ Type @event to participate on this event.", bc_all, C_AQUA, FW_BOLD, 16;
	set .Waiting,1;
	end;

On1N:
	set .1_mobNum[1], .1_mobNum[1]-1;
	end;
On1S:
	set .1_mobNumS[1], .1_mobNumS[1]-1;
	Etc(127,.1_points);
	if (.1_mobNumS[1]) {
		announce "There are still "+.1_mobNumS[1]+" special monsters with "+.1_points+" points. You can still join the event using @event.", bc_all, C_AQUA, FW_BOLD, 16;
	} else {
		 Event(1,0,0);
	}
	end;
On2K:
	Etc(127,.2_points);
	mapannounce .2_Map$,strcharinfo(0)+" has slain the "+getmonsterinfo(.2_mobID,0)+"!",bc_map,0xe57c00;
	sleep 4000;
	if (.2_rounds[1] < .2_rounds[0]) {
		set .2_rounds[1], .2_rounds[1]+1;
		set .2_mobID, .2_mvp[rand(getarraysize(.2_mvp))];
		monster .2_Map$,0,0,getmonsterinfo(.2_mobID,0),.2_mobID,1,strnpcinfo(0)+"::On2K";
		mapannounce .2_Map$,"Round "+.2_rounds[1]+": "+getmonsterinfo(.2_mobID,0)+" has spawned!",bc_map,0xe57c00;
	}
	else Event(2,0,0);
	end;


On2A:
	if (.2_wait) {
		set .Waiting,1;
		donpcevent strnpcinfo(0)+"::On0W";
		for(set .@i,.2_wait; .@i > 0; set .@i,.@i-1){
			channelmes("#event","The MvP Invasion Will begin in "+.@i+" min!. Type @event to join.  Don't worry, we will warp you back to your current location after the event ends.");
			sleep 60 * .onesec;
		}
		if (!.Waiting) end;
		set .Waiting,0;
	}
	set .Waiting,0;
	set .2_FaMum,.2_MumAmEvent;
	set .2_FaraoKilled,1;
	set .2_OsirisKilled,1;
	channelmes("#event","The powerfull darkness king Anubis was awaken");
	sleep 5 * .onesec;
	monster .2_Map$,0,0,"Pharao",1157,1,strnpcinfo(0)+"::OnFaraoKilled";
	monster .2_Map$,0,0,"Osiris",1038,1,strnpcinfo(0)+"::OnOsirisKilled";
	monster .2_Map$,0,0,"Mummy",1041,.2_MumAmEvent,strnpcinfo(0)+"::OnMumiaKilled";
	channelmes("#event","Something unbelievable happened: Anubis hypnotized Pharao and Osiris, They are killing everyone in "+.2_Map$);
	sleep 5 * .onesec;
	channelmes("#event","AmonRa will reward everyone who helps to end the invasion");
	sleep 5 * .onesec;
	channelmes("#event","Anubis will appear when Osiris, Pharao and the Mummys dies");
	end;

On2B:
	sleep 10 * .onesec;
	channelmes("#event","AmonRa said that Anubis cloned himself, there are many falses Anubis in "+.2_Map$+", However, just one is the true ");
	monster .2_Map$,0,0,"Anubis",1098,.2_Fanubis,strnpcinfo(0)+"::OnFalseAnubisKilled";
	monster .2_Map$,0,0,"Anubis",1098,1,strnpcinfo(0)+"::OnTrueAnubisKilled";
	end;

	OnFaraoKilled:
		set .2_FaraoKilled,.2_FaraoKilled - 1;
		channelmes("#event","Thanks "+strcharinfo(0)+" for killing the Pharaoh, you will receive a "+getitemname(.2_item3)+", as reward");
		getitem .2_item3,1;
		if (!.2_FaraoKilled && !.2_OsirisKilled && !.2_FaMum) {
			donpcevent strnpcinfo(0)+"::On2B";
		}
		end;

	OnOsirisKilled:
		set .2_OsirisKilled,.2_OsirisKilled - 1;
		channelmes("#event","Thanks "+strcharinfo(0)+" for killing the Osiris, you'll receive a "+getitemname(.2_item4)+", as reward");
		getitem .2_item4,1;
		if (!.2_FaraoKilled && !.2_OsirisKilled && !.2_FaMum) {
			donpcevent strnpcinfo(0)+"::On2B";
		}
		end;

	OnMumiaKilled:
		set .2_FaMum,.2_FaMum - 1;
		//dispbottom "You killed a Mummy "+.2_FaMum;		
		//@Etc(127,.2_points);
		end;

	OnFalseAnubisKilled:
		Etc(127,.2_points);
		dispbottom "You killed a false Anubis";
		end;

	OnTrueAnubisKilled:
		channelmes("#event","Congratulations "+strcharinfo(0)+" you saved the world you will receive a "+getitemname(.2_item2)+", as reward! Thanks !!!");
		getitem .2_item2,1;
		killmonsterall .2_Map$;
		Event(2,0,0);
		end;



On3K:
	set .3_mobNum[1], .3_mobNum[1]-1;
	Etc(127,.3_points);
	set .@str$, ((.3_mobNum[1])?" "+.3_mobNum[1]+" "+getmonsterinfo(.3_mobID,0)+" remain.":"");
	mapannounce .3_Map$,strcharinfo(0)+" got a kill!"+.@str$,bc_map,0xe57c00;
	if (!.3_mobNum[1]) Event(3,0,0);
	end;
On4A:
	if (.4_wait) {
		announce "The Poring Catcher Event is now active. Earn "+.4_points+" points in killing the correct Poring.  Type @event to join.", bc_all, C_AQUA, FW_BOLD, 16;
		set .Waiting,1;
		donpcevent strnpcinfo(0)+"::On0W";
		for(set .@i,.4_wait; .@i > 0; set .@i,.@i-1){
			announce "The Poring Catcher Event Will begin in "+.@i+" min!. Type @event to join.  Don't worry, we will warp you back to your current location after the event ends.", bc_all, C_AQUA, FW_BOLD, 16;
			sleep 60 * .onesec;
		}
		if (!.Waiting) end;
		set .Waiting,0;
	}

	if (queuesize(.qid) < .4_min ) { // cannot start event if nobody joins(0) or just having (1) player
		announce "The "+.Events$[.Active]+" Event is canceled not enough players to continue!", bc_all, C_AQUA, FW_BOLD, 16;
		sleep 1000;
		Event(4,0,0);
		end;
	}

	set .Waiting,0;
	announce "The "+.Events$[.Active]+" event has begun! Registration is now close.", bc_all, C_AQUA, FW_BOLD, 16;
	sleep 3 * .onesec;
	mapannounce .4_Map$, "Welcome to "+.Events$[.Active]+" Event!",bc_map,0xffff90;
	sleep 3 * .onesec;
	mapannounce .4_Map$, "To the players don't know this event, It its very simple!",bc_map,0xffff90;
	sleep 3 * .onesec;
	mapannounce .4_Map$, "We will summon "+.4_mobNum+" correct Poring and "+.4_mobFake+" FAKE Poring with dfferent name.",bc_map,0xffff90;
	sleep 3 * .onesec;
	mapannounce .4_Map$, "You just need to kill the right or correct Poring to get extra Online Points!!",bc_map,0xffff90;
	sleep 3 * .onesec;
	mapannounce .4_Map$, "Don't use ELEMENTAL ARROW/WEAPON or MAGIC here.  You will MISS if you do.",bc_map,0xffff90;
	sleep 6 * .onesec;
	mapannounce .4_Map$, "Here we go..",bc_map, C_AQUA, FW_BOLD, 16;;
	sleep 3 * .onesec;
	mapannounce .4_Map$, "Event will start in 3....",bc_map,0xffff90;
	sleep 1 * .onesec;
	mapannounce .4_Map$, "2...",bc_map,0xffff90;
	sleep 1 * .onesec;
	mapannounce .4_Map$, "1..",bc_map,0xffff90;
	sleep 1 * .onesec;
	mapannounce .4_Map$, "Start looking for that correct Poring now for "+.4_points+" Online Points!",bc_map,0xffff90;
	setarray .@n$[0],"Proing","Pouring","Poiring","Poing","Poriing","Porong","Por1ng","P0ring","PoriNg";
	setarray .@id[0],3384;
	for(set .@i,0; .@i<.4_mobFake; set .@i,.@i+1)
		switch(rand(1,3)) {
		case 1:
			areamonster .4_Map$,75,91,118,120,.@n$[rand(1,9)],3384,1,strnpcinfo(0)+"::On4F";				
		case 2:
			areamonster .4_Map$,75,91,118,120,.@n$[rand(1,9)],3391,1,strnpcinfo(0)+"::On4F";
		case 3:
			areamonster .4_Map$,75,91,118,120,.@n$[rand(1,9)],3399,1,strnpcinfo(0)+"::On4F";
		}	

	for(set .@i,0; .@i<.4_mobNum; set .@i,.@i+1)
		switch(rand(1,3)) {
		case 1:
			areamonster .4_Map$,75,91,118,120,"Poring",3384,1,strnpcinfo(0)+"::On4R";				
		case 2:
			areamonster .4_Map$,75,91,118,120,"Poring",3391,1,strnpcinfo(0)+"::On4R";
		case 3:
			areamonster .4_Map$,75,91,118,120,"Poring",3399,1,strnpcinfo(0)+"::On4R";
		}
	end;

On4F:
	dispbottom "Sorry, It wasn't the correct Poring!";
	if (.qid) queueremove .qid, getcharid(3);
	set etatus,0;
	set Hp,ehp;
	set Sp,esp;
	warp elastmap$,elastx,elasty;
	if (.4_mobNum == 0 || !queuesize(.qid) ) {
		sleep 1000;
		Event(4,0,0);
	}
	end;
On4R:
	set .4_mobNum, .4_mobNum-1;
	Etc(127,.4_points);
	if (.qid) queueremove .qid, getcharid(3);
	set etatus,0;
	set Hp,ehp;
	set Sp,esp;
	warp elastmap$,elastx,elasty;
	channelmes("#event",strcharinfo(0)+" killed the real Poring and gained "+.4_points+" Online Points!");
	
	if (.4_mobNum == 0 || !queuesize(.qid) ) {
		sleep 1000;
		Event(4,0,0);
	}
	end;




On6A:
	if (.6_wait) {
		announce "The Disguise Event is active.  Use @event to join this event. Earn "+.6_points+" points on each correct guess.", bc_all, C_AQUA, FW_BOLD, 16;
		set .Waiting,1;
		donpcevent strnpcinfo(0)+"::On0W";
		sleep(60000*.6_wait);
		announce "The Disguise event will begin in "+.6_wait+" minute"+((.6_wait == 1)?"":"s")+"!  Type @event to participate.", bc_all, C_AQUA, FW_BOLD, 16;	
		if (!.Waiting) end;
		set .Waiting,0;
	}
 	areawarp .6_Map$,.xy_area[0],.xy_area[1],.xy_area[2],.xy_area[3],.Map$,89,145;
                     killmonster .Map$,strnpcinfo(0)+"::OnDied";
                        killmonster .Map$,strnpcinfo(0)+"::OnWallDied";
			setcell .Map$,.xy_area[0],.xy_area[1],.xy_area[2],.xy_area[3],cell_basilica,1;
			setcell .Map$,.xy_area[0],.xy_area[1],.xy_area[2],.xy_area[3],cell_walkable,0;

                       for( .@i = .xy_area[0]; .@i <= .xy_area[2]; .@i++ ){
                                xy_wall( .@i,.xy_area[1] );
                                xy_wall( .@i,.xy_area[3] );
                        }
                        for( .@i = .xy_area[1]; .@i <= .xy_area[3]; .@i++ ){
                                xy_wall( .xy_area[0],.@i,0 );
                                xy_wall( .xy_area[2],.@i );
                        }

	announce "The Disguise event has begun in "+strnpcinfo(4)+"! You can still participate by typing @event. Earn "+.6_points+" points on each correct guess.", bc_all, C_AQUA, FW_BOLD, 16;
	set .6_rounds[1],1;
 

On6B:
	announce "The Disguise event is ongoing at "+strnpcinfo(4)+"! You can still participate by typing @event for "+.6_points+" points on each correct guess.", bc_all, C_AQUA, FW_BOLD, 16;
	npctalk "Round "+.6_rounds[1]+"...";
	set .Waiting,2;
	sleep rand(2000,2500);
	if (!.Waiting) end;
	set .@valid,0;
	while(!.@valid) {
		set .6_mobID, rand(1001,1323);
		if (!compare(.Blacklist$,""+.6_mobID)) set .@valid,1;
		if (.@valid && .6_mobID[1]) if (getmonsterinfo(.6_mobID[0],0) == getmonsterinfo(.6_mobID[1],0)) set .@valid,0;
	}
	setnpcdisplay(strnpcinfo(0),.6_mobID);
	defpattern 1,"([^:]+):.\\s*"+getmonsterinfo(.6_mobID,0)+".*", "On6C";
	activatepset 1;
	set .Waiting,2;
	sleep(1000*.6_time);
	if (!.Waiting) end;
	set .Waiting,0;
	npctalk "Time's up. The answer was '"+getmonsterinfo(.6_mobID,0)+"'.";
	donpcevent strnpcinfo(0)+"::On6D";
	end;
On6C:
	Etc(127,.6_points);
	npctalk strcharinfo(0)+" is correct! The answer was '"+getmonsterinfo(.6_mobID,0)+"'.";
	set .Waiting,0;
	awake strnpcinfo(0);
On6D:
	set .6_rounds[1], .6_rounds[1]+1;
	deletepset 1;
	setnpcdisplay(strnpcinfo(0),4_F_OPERATION);
	set .6_mobID[1], .6_mobID;
	sleep 5000;
	if (.6_rounds[1] > .6_rounds[0]) {
		npctalk "That was the last round. Thanks for playing!";
                killmonster .Map$,strnpcinfo(0)+"::OnDied";
                killmonster .Map$,strnpcinfo(0)+"::OnWallDied";
		setcell .Map$,.xy_area[0],.xy_area[1],.xy_area[2],.xy_area[3],cell_basilica,0;
        	setcell .Map$,.xy_area[0],.xy_area[1],.xy_area[2],.xy_area[3],cell_walkable,1;
		set .Waiting,3;
		sleep 1000;
		Event(6,0,0);
	} else donpcevent strnpcinfo(0)+"::On6B";
	end;
On7A:
	announce "The Last Man Standing Event for [ "+jobname(.7_job)+" Level "+.7_min_level+" ~ "+.7_max_level+" ] is active.  Use @event to join this event.",16;
	set .Waiting,1;
		donpcevent strnpcinfo(0)+"::On0W";
		for(set .@i,.7_wait; .@i > 0; set .@i,.@i-1){
			channelmes("#event","The LastMan Standing Event [ "+jobname(.7_job)+" LVL "+.7_min_level+" ~ "+.7_max_level+" ] will begin in "+.@i+" min!. Please type @event to join.  Don't worry, we will warp you back to your current location after the event ends.");
			sleep 60 * .onesec;
		}
	if (!.Waiting) end;
	if (queuesize(.qid) < .7_min) {
		mapannounce .7_Map$,"The Last Man Standing event has been cancelled because not enough players registered.",0;
		sleep 1000;
		Event(7,0,0);
		end;
	}
	set .Waiting,2;
	mapannounce .7_Map$,"The event will start in 10 seconds...",bc_all,0xffff90;
	sleep 5000;
	if (.Waiting != 2) end;
	for(set .@i,5; .@i>0; set .@i,.@i-1) {
		mapannounce .7_Map$,.@i+"...",16;
		sleep 1000;
		if (.Waiting != 2) end;
	}
	set .Waiting,0;
	channelmes("#event","The "+.Events$[.Active]+" event has begun!");
	pvpon .7_Map$;
	donpcevent strnpcinfo(0)+"::On7B";
	end;

On7B:
	while(.Active == 7 && !.Waiting) {
		set .@i, queuesize(.qid);
		if (.@i == 1) {
			set .Waiting,3;
			// Terminate QUEUE
			.@it = queueiterator(.qid);
			for ( .@aid = qiget(.@it); qicheck(.@it); .@aid = qiget(.@it) )
			.aid[.@c++] = .@aid;
			if(.@it) qiclear .@it;
			if(.qid) queuedel .qid;
			sleep 5000;
			for ( .@i = 0; .@i < .@c; ++.@i ) {
				attachrid .aid[.@i];
				announce "Congratulation to [ "+strcharinfo(PC_NAME)+" ] the LAST MAN STANDING on this event!! ^^ !!",0;
				Etc(127,.7_points);
				set etatus,0;
				set Hp,ehp;
				set Sp,esp;
				warp elastmap$,elastx,elasty;
			}
			Event(7,0,0);
		} else if (.@i == 0) Event(7,0,0);
		else sleep 3000;
	}
	end;


On8A:
	set .Waiting,1;
	announce "The DICE Event is now active.  Earn "+.8_points+" points at this event. Use @event to join now.", bc_all, C_AQUA, FW_BOLD, 16;
	donpcevent strnpcinfo(0)+"::On0W";
	for(set .@i,.8_wait; .@i > 0; set .@i,.@i-1){
		announce "The DICE Event Will begin in "+.@i+" min!. Type @event to join.  Don't worry, we will warp you back to your current location after the event ends.", bc_all, C_AQUA, FW_BOLD, 16;
		sleep 60 * .onesec;
	}
	if (queuesize(.qid)  < .8_min ) { // cannot start event if nobody joins(0) or just having (1) player
		announce "The "+.Events$[.Active]+" Event is canceled not enough players to continue!", bc_all, C_AQUA, FW_BOLD, 16;;
		sleep 1000;
		Event(8,0,0);
		end;
	}
	set .Waiting,0;
	announce "The "+.Events$[.Active]+" event has begun! Registration is now close. There are "+queuesize(.qid)+" players joined this event.", bc_all, C_AQUA, FW_BOLD, 16;
	sleep 5000;
	mapannounce .8_Map$,"Go ahead and chose which is your lucky box.",bc_all,0xffff90;
	sleep 20000;
	for(set .@1234,0; .@1234 < 100; set .@1234,.@1234+1){
		for(set .@i,10; .@i > 0; set .@i,.@i-1){
			mapannounce .8_Map$,""+.@i+"...",bc_all,0xffff90;
			sleep 1 * .onesec;
		}
		set .@i,rand(1,4);

		switch(.@i){
			case 1:	areawarp .8_Map$,183,81,191,59,.8_Map2$,142,93;   break;
			case 2:	areawarp .8_Map$,195,81,203,59,.8_Map2$,142,93;	break;
			case 3:	areawarp .8_Map$,207,81,215,59,.8_Map2$,142,93;	break;
			case 4:	areawarp .8_Map$,219,81,227,59,.8_Map2$,142,93;	break;
		}
		// Stairs Area
		areawarp .8_Map$,182,94,228,88,.8_Map2$,142,93;	 //Upper Area
		areawarp .8_Map$,185,87,188,82,.8_Map2$,142,93;	 //Stairs 1
		areawarp .8_Map$,197,87,200,82,.8_Map2$,142,93;	 //Stairs 2
		areawarp .8_Map$,209,87,212,82,.8_Map2$,142,93;	 //Stairs 3
		areawarp .8_Map$,221,87,224,82,.8_Map2$,142,93;	 //Stairs 4
		if(queuesize(.qid)<=1){
			set .@1234,100+1;
		} else {
			sleep2 1;
			channelmes("#event","Dice Event ... Box "+.@i+" has been ejected. There are still "+queuesize(.qid)+" remaining");
			mapannounce .8_Map$,"There are "+queuesize(.qid)+" Players Remaining. Take a few moments if you want to change boxes.",bc_all,0xffff90;
			sleep 20000;
		}
	}
	
	donpcevent strnpcinfo(0)+"::On8B";
	end;
On8B:
	while(.Active == 8 && !.Waiting) {
		set .@i, queuesize(.qid);
		if (.@i == 1) {
			set .Waiting,3;
			// Terminate QUEUE
			.@it = queueiterator(.qid);
			for ( .@aid = qiget(.@it); qicheck(.@it); .@aid = qiget(.@it) )
			.aid[.@c++] = .@aid;
			if (.@it) qiclear .@it;
			if(.qid) queuedel .qid;
			sleep 5000;
			for ( .@i = 0; .@i < .@c; ++.@i ) {
				attachrid .aid[.@i];
				announce "Congratulation to [ "+strcharinfo(PC_NAME)+" ] for winning the DICE EVENT!! ^^ !!",0;
				Etc(127,.8_points);
				set etatus,0;
				set Hp,ehp;
				set Sp,esp;
				warp elastmap$,elastx,elasty;
			}
			Event(8,0,0);
		} else if (.@i == 0) Event(8,0,0);
		else sleep 3000;
	}
	end;


On5A:
	if (.5_wait) {
		set .Waiting,1;
		announce "The Poring Bomb Survival Event is now active. 1 winnner of "+.5_points+" points. Type @event to join.", bc_all, C_AQUA, FW_BOLD, 16;	
		donpcevent strnpcinfo(0)+"::On0W";
		for(set .@i,.5_wait; .@i > 0; set .@i,.@i-1){
			announce "The PORING BOMB Survival Event Will begin in "+.@i+" min!. Please type @event to join. Don't worry, we will warp you back to your current location after the event ends.", bc_all, C_AQUA, FW_BOLD, 16;
			sleep 60 * .onesec;
		}
		if (!.Waiting) end;
		set .Waiting,0;
	}
	if (queuesize(.qid) < .5_min) {
		set .Waiting,0;
		announce "The "+.Events$[.Active]+" Event is canceled not enough players to continue!", bc_all, C_AQUA, FW_BOLD, 16;
		sleep 1000;
		Event(5,0,0);
		end;
	}

	set .Waiting,0;
	announce "The "+.Events$[.Active]+" Event has begun! Registration is now close. There are "+getarraysize(.aid)+" players joined this event.", bc_all, C_AQUA, FW_BOLD, 16;
	donpcevent strnpcinfo(0)+"::On5B";
	end;

On5B:
        mapannounce .5_Map$, "Welcome to Poring Bomb Survival Event", 0;
        sleep 3000;
        mapannounce .5_Map$, "This is an easy event", 0;
        sleep 3000;
        mapannounce .5_Map$, "Just stay AWAY from anything that you think its DANGEROUS!!", 0;
        sleep 3000;
        mapannounce .5_Map$, "Stay alive as long as YOU CAN!!!!", 0;
        sleep 3000;
        mapannounce .5_Map$, "Complete 5 Waves to win this event.", 0;
        sleep 3000;
        mapannounce .5_Map$, "event will start in 3", 0;
        sleep 1000;
        mapannounce .5_Map$, "2...", 0;
        sleep 1000;
        mapannounce .5_Map$, "1...", 0;
        sleep 1000;
        mapannounce .5_Map$, "Its time to run !!", 0;
	for (set .@r,1; .@r < 6; set .@r,.@r+1){
		if (.@r == 1) {
			mapannounce .5_Map$,"Round "+.@r+" !! The BOMB timing has Started to count down !!",0;
			sleep2 2000;
			mapannounce .5_Map$,queuesize(.qid)+" players has joined the event.",0,0x00FF00;
		} else {
			mapannounce .5_Map$,queuesize(.qid)+" players has survived to this round.",0,0x00FF00;
		}	
		sleep2 3000;
		if (.@r == 1) {
			mapannounce .5_Map$,"Alright !! Let's BLOW it up !!",0,0x00FF00;
		} else if (.@r == 2) {
			mapannounce .5_Map$,"Good Job !! Gratz to reach this stage !!",0,0x00FF00;
		} else if (.@r == 3) {
			mapannounce .5_Map$,"Keep In On !! 2 More Stage After this Stage !! ~",0,0x00FF00;
		} else if (.@r == 4) {
			mapannounce .5_Map$,"Incredible !! They Survive till this stage ~",0,0x00FF00;
		} else if (.@r == 5) {
			mapannounce .5_Map$,"OMG !!! They come to the FINAL STAGE !!! Who Will Survive till the END !?? ~ ",0,0x00FF00;
		}	
		sleep2 3000;
		if (.@r==1) {
			areamonster .5_Map$, 128,113,103,82, "Come On Baby!!!", 1904,5;
			areamonster .5_Map$, 128,113,103,82, "Come On Baby!!!", 1904,5;
			sleep2 13000;
			areamonster .5_Map$, 128,113,103,82, "Come On Baby!!!", 1904,5;
			areamonster .5_Map$, 128,113,103,82, "Come On Baby!!!", 1904,5;
		}
		if (.@r==2) {
			areamonster .5_Map$, 128,113,103,82, "Come On Baby!!!", 1904,1,strnpcinfo(0)+"::OnMobDied";
			areamonster .5_Map$, 128,113,103,82, "Come On Baby!!!", 1904,1,strnpcinfo(0)+"::OnMobDied";
			areamonster .5_Map$, 128,113,103,82, "Come On Baby!!!", 1904,5;
			areamonster .5_Map$, 128,113,103,82, "Come On Baby!!!", 1904,5;
			sleep 13000;
			areamonster .5_Map$, 128,113,103,82, "Come On Baby!!!", 1904,3;
			areamonster .5_Map$, 128,113,103,82, "Come On Baby!!!", 1904,3;
		}
		if (.@r==3) {
			areamonster .5_Map$, 128,113,103,82, "Come On Baby!!!", 1904,7;
			areamonster .5_Map$, 128,113,103,82, "Come On Baby!!!", 1904,7;
			sleep 5000;
			areamonster .5_Map$, 128,113,103,82, "Come On Baby!!!", 1904,5;
			areamonster .5_Map$, 128,113,103,82, "Come On Baby!!!", 1904,5;
			sleep 10000;
			areamonster .5_Map$, 128,113,103,82, "Come On Baby!!!", 1904,2,strnpcinfo(0)+"::OnMobDied";
			areamonster .5_Map$, 128,113,103,82, "Come On Baby!!!", 1904,2,strnpcinfo(0)+"::OnMobDied";
		}	
		if (.@r==4) {
			areamonster .5_Map$, 128,113,103,82, "Come On Baby!!!", 1904,1,strnpcinfo(0)+"::OnMobDied";
			areamonster .5_Map$, 128,113,103,82, "Come On Baby!!!", 1904,1,strnpcinfo(0)+"::OnMobDied";
			areamonster .5_Map$, 128,113,103,82, "Come On Baby!!!", 1904,5;
			areamonster .5_Map$, 128,113,103,82, "Come On Baby!!!", 1904,5;
			sleep 15000;
			areamonster .5_Map$, 128,113,103,82, "Come On Baby!!!", 1904,2,strnpcinfo(0)+"::OnMobDied";
			areamonster .5_Map$, 128,113,103,82, "Come On Baby!!!", 1904,2,strnpcinfo(0)+"::OnMobDied";
		}	
		if (.@r==5) {
			areamonster .5_Map$, 128,113,103,82, "Come On Baby!!!", 1904,1,strnpcinfo(0)+"::OnMobDied";
			areamonster .5_Map$, 128,113,103,82, "Come On Baby!!!", 1904,1,strnpcinfo(0)+"::OnMobDied";
			areamonster .5_Map$, 128,113,103,82, "Come On Baby!!!", 1904,15;
			areamonster .5_Map$, 128,113,103,82, "Come On Baby!!!", 1904,15;
			sleep 18000;
			areamonster .5_Map$, 128,113,103,82, "Come On Baby!!!", 1904,2,strnpcinfo(0)+"::OnMobDied";
			areamonster .5_Map$, 128,113,103,82, "Come On Baby!!!", 1904,2,strnpcinfo(0)+"::OnMobDied";
		}
		sleep2 10000;

		for(set .@i,5; .@i > 0; set .@i,.@i-1){
			mapannounce .5_Map$,.@i+" Second to go until next Round  !! ^^ !!",0;
			sleep 1 * .onesec;
		}
		sleep2 1000;
		mapannounce .5_Map$,"Round "+.@r+" Finished !! Please wait for next round !! ^^ !!",0;
		killmonsterall .5_Map$;
		sleep2 1000;
	}
	mapannounce .5_Map$,"Congratulation to "+queuesize(.qid)+" SURVIVORS xD  !! ^^ !!",0;
	killmonsterall .5_Map$;
	// Terminate QUEUE
	.@it = queueiterator(.qid);
	for ( .@aid = qiget(.@it); qicheck(.@it); .@aid = qiget(.@it) )
	.aid[.@c++] = .@aid;
	if(.@it) qiclear .@it;
	if(.qid) queuedel .qid;
	sleep 5000;
	for ( .@i = 0; .@i < .@c; ++.@i ) {
		attachrid .aid[.@i];
		Etc(127,.5_points);
		set etatus,0;
		set Hp,ehp;
		set Sp,esp;
		warp elastmap$,elastx,elasty;
	}
	Event(5,0,0);
	end;

OnMobDied:
	areamonster .5_Map$, 128,113,103,82, "Come On Baby!!!", 1904,1,strnpcinfo(0)+"::OnMobDied";
 	end;



OnDied:
OnWallDied:
OnPCDieEvent:
	end;

OnMapChange:
	if (.Active == 8) {
		if ( @Queue_Destination_Map$ == .8_Map$ ) end; 
		if (.qid) {
			queueremove .qid, getcharid(3);
			//debugmes(getcharid(3)+" has been ejected and was removed from que");
		}
		if (status) {
			set etatus,0;
			set Hp,ehp;
			set Sp,esp;
			warp elastmap$,elastx,elasty;
			set Hp,ehp;
			set Sp,esp;
		}
	}
	end;

OnQuit:
	if (.qid) queueremove .qid, getcharid(3);
	end;

OnPCLogoutEvent:
OnPCLoginEvent:
	if (.qid) { 
		queueremove .qid, getcharid(3);
		//debugmes(getcharid(3)+" did character select and was removed from que");
	}
	if (etatus) {
		set etatus,0;
		set Hp,ehp;
		set Sp,esp;
		warp elastmap$,elastx,elasty;
		set Hp,ehp;
		set Sp,esp;
	}
	end;	
OniDied:
	if ( strcharinfo(3) == .5_Map$) {			
		sleep2 5;
		set etatus,0;
		set Hp,ehp;
		set Sp,esp;
		warp elastmap$,elastx,elasty;
		set Hp,ehp;
		set Sp,esp;
		areamonster .5_Map$, 128,113,103,82, "Come On Baby!!!", 1904,1,strnpcinfo(0)+"::OnMobDied";
		dispbottom "What A Bad Luck...Join Us Again Next Time  ^^. ";
		if (.qid) queueremove .qid, getcharid(3);
		if (!queuesize(.qid)) {
			killmonsterall .5_Map$;
			Event(5,0,0);
		}
		end;
	}
	if ( strcharinfo(3) == .7_Map$) {
		sleep2 5;
		set etatus,0;
		set Hp,ehp;
		set Sp,esp;
		warp elastmap$,elastx,elasty;
		sleep2 1;
		set Hp,ehp;
		set Sp,esp;
		if (.qid) queueremove .qid, getcharid(3);
		if (!queuesize(.qid)) {
			Event(7,0,0);
		}
		end;
	}


OnPCLoadMapEvent:
	end;

function Etc {
	if (!getarg(0,0)) {
		if (getgmlevel() < .GMFull) {
			message strcharinfo(0),"You are not permitted to change this.";
			return 0;
		} else return 1;
	} else if (getarg(0) == 127) {
		if (getarg(1)) {
			#PCTIME += getarg(1);
			dispbottom "Gained "+getarg(1)+" Online Points [Total: "+#PCTIME+"]";
		}
		specialeffect(EF_ANGEL, AREA, playerattached());
		return;
	} else if (getarg(0) == 255) {
		if (getarg(1) < 1001) {
			message strcharinfo(0),"Invalid mob ID '"+getarg(1)+"'.";
			return 0;
		} else if (getmonsterinfo(getarg(1),0) == "" || getmonsterinfo(getarg(1),0) == "null") {
			message strcharinfo(0),"Invalid mob ID '"+getarg(1)+"'.";
			return 0;
		} else return 1;
	} else if (getarg(1,0)) {
		if (getarg(1) == .Active) {
			message strcharinfo(0),"You can't change settings while the event is active.";
			return 0;
		} else return 1;
	} else {
		input .@s$,2,12;
		if (getmapusers(.@s$) == -1 && .@s$ != "random") message strcharinfo(0),"Invalid map '"+.@s$+"'.";
		else setd "."+getarg(0)+"_Map$", .@s$;
		return;
	}
}

function Event {
	if (getd("."+getarg(0)+"_Map$") == "random") {	// Allowed 'random' town maps.
		setarray .@towns$[0],"geffen","payon","alberta","izlude","comodo","prontera";
		setd "."+getarg(0)+"_Map$", .@towns$[rand(getarraysize(.@towns$))];
	}

	switch(getarg(0)) {
		case 1:
			if (getarg(1)) {
				.qid = queue();
				queueopt .qid, QUEUEOPT_LOGOUT, strnpcinfo(0)+"::OnQuit";
				queueopt .qid, QUEUEOPT_MAPCHANGE, strnpcinfo(0)+"::OnMapChange";
				donpcevent strnpcinfo(0)+"::On1A";
			} else {
				if (.Waiting) {
					set .Waiting,0;
					awake strnpcinfo(0);
				}
			}
			break;
		case 2: // MvP Summon
			if (getarg(1)) {
		
				set .2_FaMum,.2_MumAmEvent+.2_MumAmEvent;
				donpcevent strnpcinfo(0)+"::On2A";
			} else {
				if (.Waiting) {
					set .Waiting,0;
					awake strnpcinfo(0);
				} else killmonster .2_Map$,"All";
			}
			break;
		case 3:
			if (getarg(1)) {
				.qid = queue();
				queueopt .qid, QUEUEOPT_LOGOUT, strnpcinfo(0)+"::OnQuit";
				queueopt .qid, QUEUEOPT_MAPCHANGE, strnpcinfo(0)+"::OnMapChange";

				monster .3_Map$,0,0,getmonsterinfo(.3_mobID,0),.3_mobID,.3_mobNum,strnpcinfo(0)+"::On3K";
				set .3_mobNum[1], .3_mobNum[0];
				channelmes("#event","The Monster Hunt event has begun in "+.3_Map$+"! Type @event to participate on this event.");
				channelmes("#event",.3_mobNum[1]+" "+getmonsterinfo(.3_mobID,0)+" have spawned!");
			} else {
				killmonster .3_Map$,"All";
				set .3_mobNum[1],0;
			}
			break;


		case 4:  // Poring Cather
			if (getarg(1)) {
				setmapflag .4_Map$, mf_noskill;	// Skills are not allowed in Poring Catcher.
				setmapflag .4_Map$, mf_nosave;
				setmapflag .4_Map$, mf_noicewall;
				setmapflag .4_Map$, mf_nowarp;
				.qid = queue();
				queueopt .qid, QUEUEOPT_LOGOUT, strnpcinfo(0)+"::OnQuit";
				queueopt .qid, QUEUEOPT_MAPCHANGE, strnpcinfo(0)+"::OnMapChange";
				maprespawnguildid .4_Map$,0,3;
				donpcevent strnpcinfo(0)+"::On4A";

			} else {
				if (.Waiting) {
					set .Waiting,0;
					awake strnpcinfo(0);
				} else killmonster .4_Map$,"All";
				maprespawnguildid .4_Map$,0,3;
			}
			break;
		case 5:	// Bomb Event
			if (getarg(1)) {
				.qid = queue();
				queueopt .qid, QUEUEOPT_LOGOUT, strnpcinfo(0)+"::OnQuit";
				queueopt .qid, QUEUEOPT_MAPCHANGE, strnpcinfo(0)+"::OnMapChange";
				queueopt .qid, QUEUEOPT_DEATH, strnpcinfo(0)+"::OniDied";

				maprespawnguildid .5_Map$,0,3;
				setmapflag .5_Map$, mf_nosave;
				setmapflag .5_Map$, mf_noskill;
				setmapflag .5_Map$, mf_noicewall;
				setmapflag .5_Map$, mf_nowarp;
				setmapflag .5_Map$, mf_noteleport;
				setmapflag .5_Map$, mf_nobranch;
				setmapflag .5_Map$, mf_notrade;
				setmapflag .5_Map$, mf_nomemo;
				setmapflag .5_Map$, mf_nopenalty;
				setmapflag .5_Map$, mf_partylock;
				setmapflag .5_Map$, mf_noreturn;
				setmapflag .5_Map$, mf_nochat;
				setmapflag .5_Map$, mf_novending;
				setmapflag .5_Map$, mf_loadevent;
				donpcevent strnpcinfo(0)+"::On5A";
			} else {
				if (.Waiting) {
					set .Waiting,0;
					awake strnpcinfo(0);
				} else killmonster .5_Map$,"All";

			}
			break;
		case 6: // Disguise Event
			if (getarg(1)) {
				set .6_rounds[1],0;
				.qid = queue();
				queueopt .qid, QUEUEOPT_LOGOUT, strnpcinfo(0)+"::OnQuit";
				queueopt .qid, QUEUEOPT_MAPCHANGE, strnpcinfo(0)+"::OnMapChange";

				donpcevent strnpcinfo(0)+"::On6A";
			} else {
				if (.Waiting < 3) npctalk "A GM has cancelled the event.";
              			  killmonster .6_Map$,strnpcinfo(0)+"::OnDied";
              			  killmonster .6_Map$,strnpcinfo(0)+"::OnWallDied";
				  setcell .6_Map$,.xy_area[0],.xy_area[1],.xy_area[2],.xy_area[3],cell_basilica,0;
        			  setcell .6_Map$,.xy_area[0],.xy_area[1],.xy_area[2],.xy_area[3],cell_walkable,1;


				if (.Waiting != 1) {
					setnpcdisplay(strnpcinfo(0),4_F_OPERATION);
					deletepset 1;
				}
				set .Waiting,0;
				awake strnpcinfo(0);
				setarray .6_mobID[0],0,0;
				set .6_rounds[1],0;
			}
			break;
		case 7: // Last Man Standing
			if (getarg(1)) {
				.qid = queue();
				queueopt .qid, QUEUEOPT_LOGOUT, strnpcinfo(0)+"::OnQuit";
				queueopt .qid, QUEUEOPT_MAPCHANGE, strnpcinfo(0)+"::OnMapChange";
				queueopt .qid, QUEUEOPT_DEATH, strnpcinfo(0)+"::OniDied";

				maprespawnguildid .7_Map$,0,3;

				setmapflag .7_Map$, mf_nosave;
				setmapflag .7_Map$, mf_noicewall;
				setmapflag .7_Map$, mf_nowarp;
				setmapflag .7_Map$, mf_pvp_noguild;
				setmapflag .7_Map$, mf_pvp_noparty;
				setmapflag .7_Map$, mf_nobranch;
				setmapflag .7_Map$, mf_notrade;
				setmapflag .7_Map$, mf_nomemo;
				setmapflag .7_Map$, mf_nopenalty;
				setmapflag .7_Map$, mf_partylock;
				setmapflag .7_Map$, mf_noreturn;
				setmapflag .7_Map$, mf_nochat;
				setmapflag .7_Map$, mf_novending;

				pvpoff .7_Map$;
				donpcevent strnpcinfo(0)+"::On7A";
			} else {
				if (.Waiting != 1) {
					//removemapflag .7_Map$, mf_loadevent;
					set .Waiting,1;
				} else set .Waiting,0;
				awake strnpcinfo(0);
				set .Waiting,0;
				maprespawnguildid .7_Map$,0,3;
				pvpoff .7_Map$;
			}
			break;
		case 8: // Dice Event
			if (getarg(1)) {
				setmapflag .8_Map$, mf_noskill;	
				setmapflag .8_Map$, mf_nosave;
				setmapflag .8_Map$, mf_noreturn;
				setmapflag .8_Map$, mf_nowarp;
				setmapflag .8_Map$, mf_noteleport;
				.qid = queue();
				queueopt .qid, QUEUEOPT_LOGOUT, strnpcinfo(0)+"::OnQuit";
				queueopt .qid, QUEUEOPT_MAPCHANGE, strnpcinfo(0)+"::OnMapChange";
				donpcevent strnpcinfo(0)+"::On8A";
			} else {
				if (.Waiting != 1) {
					set .Waiting,1;
				} else set .Waiting,0;
				awake strnpcinfo(0);
				set .Waiting,0;
			}
			break;

	}
	if (!getarg(1)) {
		announce "The "+.Events$[getarg(0)]+" event is now over!", bc_all, C_AQUA, FW_BOLD, 16;
		if (.Active==6) {
			setcell .6_Map$,.xy_area[0],.xy_area[1],.xy_area[2],.xy_area[3],cell_basilica,0;
			setcell .6_Map$,.xy_area[0],.xy_area[1],.xy_area[2],.xy_area[3],cell_walkable,1;
			//channelmes("#event","The Disguise Event has ended!");
		}

		// Terminate QUEUE
		.@it = queueiterator(.qid);
		for ( .@aid = qiget(.@it); qicheck(.@it); .@aid = qiget(.@it) )
			.aid[.@c++] = .@aid;
			if(.@it) qiclear .@it;
			if(.qid) queuedel .qid;
			sleep 5000;
			for ( .@i = 0; .@i < .@c; ++.@i ) {
				attachrid .aid[.@i];
				set etatus,0;
				set Hp,ehp;
				set Sp,esp;
				warp elastmap$,elastx,elasty;
			}
		set .Active[1],0;
	}
	set .Active, ((getarg(1))?getarg(0):0);
	if (getarg(2,0)) {
		mes "["+.Events$[getarg(0)]+"]";
		if (getarg(1)) mes "Event initiated.";
		else mes "Event terminated.";
		close;
	}
	return;
}

function ShowStatus {
	if (!.Active || getarg(0) != .Active) return 0;
	if (getarg(1,0)) mes "Event: ^0055FF"+.Events$[getarg(0)]+"^000000";
	else mes "Status: ^0055FFActive^000000";
	set .@map$, getd("."+getarg(0)+"_Map$");
	if (.@map$ != "") mes "Location: ^777777"+.@map$+"^000000";
	switch(getarg(0)) {
		case 1:
			mes "Status: ^777777Started^000000";
			mes "Special "+strmobinfo(1,.1_mobID)+" left: ^777777"+.1_mobNumS[1]+"^000000";
			mes "Normal "+strmobinfo(1,.1_mobID)+" left: ^777777"+.1_mobNum[1]+"^000000";
			mes "Points per kill: ^777777"+.1_points+"^000000";
			break;
		case 2:
			mes "Status: ^777777"+((.Waiting)?"Waiting...":"Started")+"^000000";
			mes "Osiris Reward: ^777777"+getitemname(.2_item4)+"^000000";
			mes "Pharao Reward: ^777777"+getitemname(.2_item3)+"^000000";
			mes "Anubis Reward: ^777777"+getitemname(.2_item2)+"^000000";
			mes "Points per kill: ^777777"+.2_points+"^000000";
			if (.Waiting != 1) mes "Players Joined: ^777777"+getmapusers(.2_Map$)+"^000000";
			break;
		case 3:
			mes strmobinfo(1,.3_mobID)+" left: ^777777"+.3_mobNum[1]+"^000000";
			mes "Points per kill: ^777777"+.3_points+"^000000";
			break;
		case 4:
			mes "Status: ^777777"+((.Waiting)?"Waiting...":"Started")+"^000000";
			if (!.Waiting) mes "Real Porings left: ^777777"+.4_mobNum+"^000000";
			mes "Points for winning: ^777777"+.4_points+"^000000";
			break;
		case 5:
			mes "Status: ^777777"+((.Waiting)?"Waiting...":"Started")+"^000000";
			if (.Waiting != 1) mes "Players remaining: ^777777"+getmapusers(.5_Map$)+"^000000";	
			mes "Points for winning: ^777777"+.5_points+"^000000";
			break;
		case 6:
			mes "Status: ^777777"+((.Waiting)?"Waiting...":"Started")+"^000000";
			mes "Rounds left: ^777777"+(.6_rounds[0]-.6_rounds[1])+"^000000";
			mes "Points per answer: ^777777"+.6_points+"^000000";
			break;
		case 7:
			mes "Status: ^777777"+((.Waiting)?"Waiting...":"Started")+"^000000";
			mes "Points for winning: ^777777"+.7_points+"^000000";
			if (.Waiting != 1) mes "Players remaining: ^777777"+getmapusers(.7_Map$)+"^000000";
			break;
		case 8:
			mes "Status: ^777777"+((.Waiting)?"Waiting...":"Started")+"^000000";
			mes "Points for winning: ^777777"+.8_points+"^000000";
			if (.Waiting != 1) mes "Players remaining: ^777777"+getmapusers(.8_Map$)+"^000000";
			break;

	}
	return 1;
}

function SetDefault {
	if (getarg(0)&1) {		// < Monster Summon >
		set .1_wait,0;		// Minutes before event starts, after an announcement.
		set .1_mobID,3384;	// ID of monster.
		set .1_mobNum,60;	// Number of 'normal' monsters.
		set .1_mobNumS,20;	// Number of 'special' monsters.
		set .1_points,1;	// Points per 'special' monster kill.
		set .1_Map$,"random";	// Event map (random = random town).
	}
	if (getarg(0)&2) {		// < MVP Summon >
		set .2_wait,3;		// Minutes before event starts, after an announcement.
		set .2_Fanubis,30;	// Amount of False anubis to summon
		set .2_MumAmEvent,60;	// Amount of Mummys to summon
		set .2_points,50;	// Points per 'special' monster kill.
		set .2_item2,30066;	// Item id of the reward to who kills the true Anubis
		set .2_item3,30066;	// Item id of the reward to who kills the Pharao
		set .2_item4,30066;	// Item id of the reward to who kills Osiris
		set .2_Map$,"izlude";	// Event map (random = random town).
	}
	if (getarg(0)&4) {		// < Monster Hunt >
		set .3_mobID,1084;	// ID of monster.
		setarray .3_pre[0],	// List of preset monster options.
		  1084,1330,1083;
		set .3_mobNum,rand(2,5);// Number of monsters.
		set .3_points,2;	// Points per kill.
		set .3_Map$,"random";	// Event map (random = random town).
	}
	if (getarg(0)&8) {		// < Poring Catcher >
		set .4_wait,3;		// Minutes before event starts, after an announcement.
		set .4_min,2;		// Minutes before event starts, after an announcement.
		set .4_mobNum,10;	// Special Poring
		set .4_mobFake,50;	// Wrong Poring
		set .4_points,5;	// Points for winning.
		set .4_Map$,"poring_w01";	// Event map (should be small).
		set .4_MapX,"100";	// Event map (should be small).
		set .4_MapY,"100";	// Event map (should be small).

	}
	if (getarg(0)&16) {		// < Poring Bomb Event >
		set .5_wait,3;		// Minutes before event starts, after an announcement.
		set .5_min,2;		// Points per 'special' zombie kill.
		set .5_points,10;	// Points per 'special' zombie kill.
		set .5_MapX,"115";	// Event map (should be small).
		set .5_MapY,"97";	// Event map (should be small)
		set .5_Map$,"bomb";	// Event map (should be large).
	}
	if (getarg(0)&32) {		// < Disguise Event >
		set .6_wait,2;		// Minutes before event starts, after an announcement.
		set .6_time,20;		// Seconds to guess the monster.
		set .6_rounds,20;	// Number of rounds.
		set .6_points,2;	// Points per correct response.
		set .6_Map$,"payon";	// Event map (should be small).
		set .6_MapX,"191";	// Event map (should be small).
		set .6_MapY,"130";	// Event map (should be small).
	}
	if (getarg(0)&64) {		// < Last Man Standing >
		set .7_wait,2;		// Minutes before event starts, after an announcement.
		set .7_min,4;		// Minimum players to start event.
		set .7_points,10;	// Points for winning.
		set .7_Map$,"ufc_pvp";	// Event map.
		set .7_MapX,"50";	// Event map (should be small).
		set .7_MapY,"50";	// Event map (should be small).
		set .7_MapXS,"49";	// Event map (should be small).
		set .7_MapYS,"36";	// Event map (should be small).
		set .7_job,0;		// Job Can Join
		set .7_min_level,1;
		set .7_max_level,1;
	}
	if (getarg(0)&128) {		// < Dice Event >
		set .8_wait,3;		// Minutes before event starts, after an announcement.
		set .8_min,2;		// Minimum players to start event.
		set .8_points,10;	// Points for winning.
		set .8_Map$,"quiz_01";// Event map.
		set .8_Map2$,"prontera";// Event map.
		set .8_MapX,"205";	// Event map (should be small).
		set .8_MapY,"92";	// Event map (should be small).

	}

	return;
}


       function        xy_wall {
                .@x = getarg(0);
                .@y = getarg(1);

                 monster .Map$,.@x,.@y,"",.wall_mob_id,1,strnpcinfo(0)+"::OnWallDied";
                setcell .Map$,.@x,.@y,.@x,.@y,cell_walkable,0;
                return;
        }


OnInit:

	bindatcmd("event","Event Manager::OnRunEvent",0,99);
	.onesec = 1000;
	.deadlock = 1;

// -------------------- [[ CONFIG START ]] --------------------

	setarray .Events$[1],	// Do NOT comment or delete these!
		"Monster Summon",	// [1]
		"MVP Summon",		// [2]
		"Monster Hunt",		// [4]
		"Poring Catcher",	// [8]
		"Poring Bomb",		// [16]
		"Disguise",		// [32]
		"Last Man Standing",	// [64]
		"Dice";			// [128]
	set .@EventOption,1|8|16|32|64|128;		// List of available events.
	set .GMBasic,10;	// GM level for limited access.
	set .GMFull, 10;	// GM level with full access.

		.wall_mob_id = 1085;
               setarray .xy_area,
                        186,136,
                        196,132;	
	
		getmapxy( .Map$,.npc_x,.npc_y,1 );

		setcell .Map$,.xy_area[0],.xy_area[1],.xy_area[2],.xy_area[3],cell_basilica,0;
		setcell .Map$,.xy_area[0],.xy_area[1],.xy_area[2],.xy_area[3],cell_walkable,1;


// --------------------- [[ CONFIG END ]] ---------------------

	SetDefault(.@EventOption);
	set .menu$,"";
	for(set .@i,1; .@i<getarraysize(.Events$); set .@i,.@i+1) {
		if (.@EventOption&(1<<(.@i-1)))
			set .menu$, .menu$+" > "+.Events$[.@i];
		set .menu$, .menu$+":";
	}
	set .Blacklist$,
		"1003,1006,1017,1021,1022,1027,1043,1062,1065,1072,1075,1098,1076,"+
		"1136,1137,1148,1154,1157,1162,1168,1171,1172,1173,1181,1182,1183,1184,1187,1198,"+
		"1201,1202,1210,1212,1217,1218,1220,1221,1222,1223,1224,1225,1226,1227,1228,1229,1230,1231,1232,1233,1234,"+
		"1235,1236,1237,1238,1239,1240,1241,1244,1245,1247,1284,1285,1286,1287,1288,1324,1325,1326,1327,1328,"+
		"1329,1330,1331,1332,1333,1334,1335,1336,1337,1338,1339,1340,1341,1342,1343,1344,1345,1346,1347,1348,"+
		"1349,1350,1351,1352,1353,1354,1355,1356,1357,1358,1359,1360,1361,1362,1363,1364,1373,1393,1394,1395,"+
		"1396,1397,1398,1399,1407,1413,1414,1419,1420,1421,1422,1423,1424,1425,1426,1427,1428,1429,1430,1431,"+
		"1432,1433,1434,1435,1436,1437,1438,1439,1440,1441,1442,1443,1444,1445,1446,1447,1448,1449,1450,1451,"+
		"1452,1453,1454,1455,1456,1457,1458,1459,1460,1461,1462,1463,1464,1465,1466,1467,1468,1469,1470,1471,"+
		"1472,1473,1474,1475,1476,1477,1478,1479,1480,1481,1482,1483,1484,1485,1486,1487,1488,1489,1490,1491,"+
		"1496,1501,1502,1518,1519,1520,1521,1522,1523,1524,1525,1526,1527,1528,1529,1530,1531,1532,1533,1534,"+
		"1535,1536,1537,1538,1539,1540,1541,1542,1543,1544,1545,1546,1547,1548,1549,1550,1551,1552,1553,1554,"+
		"1555,1556,1557,1558,1559,1560,1561,1562,1563,1564,1565,1566,1567,1568,1569,1570,1571,1572,1573,1574,"+
		"1575,1576,1577,1578,1579,1580,1581,1585,1588,1589,1590,1591,1592,1593,1594,1595,1596,1597,1598,1599,"+
		"1600,1601,1602,1603,1604,1605,1606,1607,1608,1609,1610,1611,1612,1624,1625,1629,1632,1633,1646,1647,"+
		"1648,1649,1650,1651,1659,1660,1661,1662,1663,1664,1665,1666,1667,1669,1674,1675,1683,1684,1689,1690,"+
		"1650,1651";
	setarray .mf[0],0,1,2,3,7,13,34;
	end;
}


