//@unloadnpc BG_Queue_Handler
//@unloadnpc BG_Register
//@unloadnpc Therapist
//@unloadnpc Teleporter#bat
//@unloadnpc Guillaume camp#bat
//@unloadnpc Croix camp#bat
//@unloadnpc Prince Croix#hBG
//@unloadnpc General Guillaume#hBG
//@unloadnpc bat_aid
//@loadnpc npc/amatsu/features/hBG/bg_common.txt



/**
 * Hercules Script
 *
 * Feature: Hercules Battlegrounds
 * Version: 1.0
 * Author: Smokexyz
 *
 * Description: Hercules Battlegrounds plugin.
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

/**
 * Map Flags
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
bat_room	mapflag	loadevent

function	script	get_arena_id	{
	set .@arena$, getarg(0);

	if (strcmp(.@arena$, "Tierra_TI") == 0) {
		return 1;
	} else if (strcmp(.@arena$, "Flavius_TD") == 0) {
		return 2;
	}
	
	/*
	if (strcmp(.@arena$, "Flavius_CTF") == 0) {
		return 1;
	} else if (strcmp(.@arena$, "Tierra_EOS") == 0) {
		return 2;
	} else if (strcmp(.@arena$, "Tierra_TI") == 0) {
		return 3;
	} else if (strcmp(.@arena$, "Flavius_TD") == 0) {
		return 4;
	} else if (strcmp(.@arena$, "Tierra_Boss") == 0) {
		return 5;
	} else if (strcmp(.@arena$, "Conquest") == 0) {
		return 6;
	} else if (strcmp(.@arena$, "Flavius_SC") == 0) {
		return 7;
	} else if (strcmp(.@arena$, "Tierra_DOM") == 0) {
		return 8;
	} else if (strcmp(.@arena$, "Rush") == 0) {
		return 9;
	}
	*/
	return 0;
}
/**
 * Battleground Queue Handler
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
-	script	BG_Queue_Handler	FAKE_NPC,{
	end;

OnInit:

	// Arena Configuration
	// All Arena settings are listed below, newer ones can be appended to the arrays.
	// Arenas when listed will be available in the auto-rotation.
	///setarray .BG_Arenas$[0],       "Flavius_CTF",    "Tierra_EOS",   "Tierra_TI",     "Flavius_TD", "Tierra_Boss","Conquest",  "Flavius_SC",  "Tierra_DOM",   "Rush";
	setarray .BG_Arenas$[0],      "Tierra_TI",   "Flavius_TD";

	// Battleground Arena Name for announcements.
	//setarray .BG_Names$[0],      "Capture the Flag","	","Triple Inferno","Team DeathMatch","Bossnia",  "Conquest",  "Stone Control","Domination",   "Rush";
	setarray .BG_Names$[0],     "Triple Inferno","Team DeathMatch";

	// Minimum Players required to start the Battleground.
	setarray .BG_Players_Min[0],        1,               1;
	// Maximum Players per Team
	setarray .BG_Players_Max[0],        12,              12;
	// Battleground announcement colors.
	setarray .BG_Color$[0],         "0x2F9F2D",      "0xDDA0DD";
	// Battleground @bgmode interger colors.
	setarray .BG_Color2[0],         0x2F9F2D,     0xDDA0DD;
	// Team Building Mode :
	// 0 = Lineal [Keeps parties together]
	// 1 = Random
	.TeamBuildingMode = 1;
	.allowjoin = 1;
	// Battleground @commands (@joinbg, @leavebg).
	.BGCommandsEnabled = 1; // (1 to enable, 0 to disable)

	// Minimum Level to join the BG queue.
	.BGQueue_Level_Min = 80;

	if (.BGCommandsEnabled) {
		/* Admin / GM Commands */
		bindatcmd "bgstart","BG_Queue_Handler::OnBGStartCommand",99,99;
		bindatcmd "bgstop","BG_Queue_Handler::OnBGStopCommand",99,99;
		bindatcmd "bgmode","BG_Queue_Handler::OnBGModeCommand",99,99;
		bindatcmd "bgsize","BG_Queue_Handler::OnBGSizeCommand",99,99;
		/* Player Commands */
		bindatcmd "bg","BG_Queue_Handler::OnDoJoin",0,99;
	}

	/* * * * * DO NOT TOUCH ANYTHING BELOW THIS LINE * * * * * * * * * * * * * * * */
	.TotalArenas = getarraysize(.BG_Arenas$);
	.BG_Queue = hBG_queue_create("Battleground Arena","BG_Queue_Handler::OnQueueJoinEvent",.BGQueue_Level_Min);
	.FFA_Queue = hBG_queue_create("Free For All Arena","BG_Queue_Handler::OnFFAQueueJoinEvent",.BGQueue_Level_Min);

	// Move to Next Arena
	if ($BG_Index >= .TotalArenas)
		$BG_Index = 0; // Restart Rotation

	.BG_Arena$ = .BG_Arenas$[$BG_Index];
	initnpctimer; // Initiate rotation timer.
	.hBGEnabled$ = "battle_configuration/hBG_enabled";
	setbattleflag .hBGEnabled$, 0;
	end;
	
// @bgmode <1-10>
OnBGModeCommand:
	.@x = atoi(.@atcmd_parameters$[0]);
	if (.@x <= .TotalArenas+1 && .@x > 0) {
		if (.@x == 1)
			set $BG_Index, rand(.TotalArenas)-1;
		else
			set $BG_Index, .@x-3;
		message strcharinfo(0),"["+.BG_Names$[$BG_Index+1]+"] has been set.";
		donpcevent "BG_Queue_Handler::OnRotate";
		end;
	} else {
		message strcharinfo(0), "Usage: @bgmode <1-"+(.TotalArenas+1)+">";
		dispbottom "#1 - Random",0xFFFFFF;
		for (.@i = 0; .@i<.TotalArenas; .@i++)
			dispbottom "#"+(.@i+2)+" - "+.BG_Names$[.@i],.BG_Color2[.@i];			
		end;
	}
		
// @bgsize <1-10> <min> <max>
OnBGSizeCommand:
	.@x = atoi(.@atcmd_parameters$[0]);
	.@x2 = atoi(.@atcmd_parameters$[1]);
	.@x3 = atoi(.@atcmd_parameters$[2]);
	if (.@x2 == 0 || .@x3 == 0) {
		message strcharinfo(0), "Usage: @bgsize <0-"+.TotalArenas+"> <min players> <max players>";
		dispbottom "#0 - All Arenas",0xFFFFFF;
		for (.@i = 0; .@i<.TotalArenas; .@i++)
			dispbottom "#"+(.@i+1)+" - "+.BG_Names$[.@i],.BG_Color2[.@i];			
		end;
	} else if (.@x2 > .@x3) {
		message strcharinfo(0), "@bgsize failed: min players is higher than max players. ";
		end;
	}	
	if (.@x <= .TotalArenas && .@x > 0) {
		message strcharinfo(0),"["+.BG_Names$[.@x-1]+"] min players is <"+.@x2+"> and max players is <"+.@x3+">.";
		setarray .BG_Players_Min[.@x-1],.@x2;
		setarray .BG_Players_Max[.@x-1],.@x3;
	} else {
		message strcharinfo(0),"[All Arenas] min players is <"+.@x2+"> and max players is <"+.@x3+">.";
		setarray .BG_Players_Min[0],.@x2,.@x2,.@x2,.@x2,.@x2,.@x2,.@x2,.@x2,.@x2;
		setarray .BG_Players_Max[0],.@x3,.@x3,.@x3,.@x3,.@x3,.@x3,.@x3,.@x3,.@x3;
	}
	end;

OnClock1000:
OnClock1900:		
OnBGStartCommand:
	setbattleflag .hBGEnabled$, 1;
	message strcharinfo(0),"Battlegrounds have been enabled.";
	donpcevent "BG_Queue_Handler::OnRotate";
	callsub OnEndArena;

OnClock1200:
OnClock2100:
OnBGStopCommand:
	setbattleflag .hBGEnabled$, 0;
	message strcharinfo(0),"Battlegrounds have been disabled.";
	.@msg$ = "[Battlegrounds] Arenas and Queuing session today has ended. See you again next time.";
	announce .@msg$, 0, 0x00FFFF, 0x190, 12, 100, 100;
	if ($@Arena_Status != 0)
		donpcevent .BG_Arena$+"::OnMatchEnd";
	callsub OnEndArena;

// @joinbg
OnDoJoin:
	if (getbattleflag(.hBGEnabled$) == 0) {
		message strcharinfo(0),"Battlegrounds are currently disabled.";
		end;
	} else if (questprogress(8506,PLAYTIME) == 2) {
		erasequest 8506;
	} else if (questprogress(8506,PLAYTIME) == 1) {
		dispbottom "[You are a Deserter. You can't participate until the indicator goes off]";
		end;
	}

	if (getmapflag(strcharinfo(3), mf_nowarp) || getmapflag(strcharinfo(3), mf_noteleport)) {
		if ( 	strcharinfo(PC_MAP) == "bat_a02" ||
			strcharinfo(PC_MAP) == "bat_a03" ||
			strcharinfo(PC_MAP) == "bat_a04" ||
			strcharinfo(PC_MAP) == "bat_a05" ||

			strcharinfo(PC_MAP) == "bat_b02" ||
			strcharinfo(PC_MAP) == "bat_b03" ||
			strcharinfo(PC_MAP) == "bat_b04" ||
			strcharinfo(PC_MAP) == "bat_b05" ||

			strcharinfo(PC_MAP) == "bat_c02" ||
			strcharinfo(PC_MAP) == "bat_c03" ||
			strcharinfo(PC_MAP) == "bat_c04" ||
			strcharinfo(PC_MAP) == "bat_c05" ||
			strcharinfo(PC_MAP) == "bat_c05" ||
			strcharinfo(PC_MAP) == "bat_c07" ||
			strcharinfo(PC_MAP) == "bat_c08" ||

			strcharinfo(PC_MAP) == "schg_cas06" ||
			strcharinfo(PC_MAP) == "schg_cas07" ||
			strcharinfo(PC_MAP) == "schg_cas08" ||

			strcharinfo(PC_MAP) == "arug_cas06" ||
			strcharinfo(PC_MAP) == "arug_cas07" ||
			strcharinfo(PC_MAP) == "arug_cas08" ||

			strcharinfo(PC_MAP) == "rush_cas01" ||
			strcharinfo(PC_MAP) == "rush_cas02" ||
			strcharinfo(PC_MAP) == "rush_cas03" ||
			strcharinfo(PC_MAP) == "rush_cas04" ||

			strcharinfo(PC_MAP) == "region_8"

		) {
		} else {
			mes "[Battle Recruiter]";
			mes "Sorry, you can't join the battle ground from this map.";
			close;
		}
	}
	mes "[Battle Recruiter]";
	mes "What do you want to do?";
	next;
	switch(select(
	  ((!bgstatus)?" > ^0055FFJoin Battle^000000:":":")+
	  ((bgstatus)?" > ^0055FFLeave Battle^000000:":":")+
	  " > ^777777Close^000000"
	)) {		
	case 1:
		if (!.allowjoin){
			mes "[Battle Recruiter]";
			mes "Sorry, Battle Ground queue is now close.  Please wait for the next session.";
			close;
		}
		hBG_queue_join getvariableofnpc(.BG_Queue,"BG_Queue_Handler");
		set bgstatus,1;
		set bghp,Hp;
		set bgsp,Sp;
		close;
	case 2:
		hBG_queue_leave getvariableofnpc(.BG_Queue,"BG_Queue_Handler");
		bg_leave();	
		if (getmapflag(strcharinfo(3),mf_battleground)) {
			set bgstatus,0;
			set Hp,bghp;
			set Sp,bgsp;
			warp "prontera",140,179;
		} else {
			set bgstatus,0;
		}
		close;
	case 3:
		close;
	}	

// Triggers after an arena has ended.
OnEndArena:
	set $@Arena_Status, 0;
	.allowjoin = 1;
	if ($@BG_Team1 == 0 && $@BG_Team2 == 0 && $@BG_Team3 == 0)
		end;
	// Warps teams back to the battle room.
	bg_warp $@BG_Team1,"bat_room",155,150;
	bg_warp $@BG_Team2,"bat_room",155,150;
	bg_warp $@BG_Team3,"bat_room",155,150;
	// Destroy Teams
	if ($@BG_Team1 != 0) hBG_destroy $@BG_Team1; set $@BG_Team1, 0;
	if ($@BG_Team2 != 0) hBG_destroy $@BG_Team2; set $@BG_Team2, 0;
	if ($@BG_Team3 != 0) hBG_destroy $@BG_Team3; set $@BG_Team3, 0;
	// Fall through

OnPCLoadMapEvent:
	if ( strcharinfo(3) == "bat_room" && bgstatus ) {
		hBG_leave;
		set bgstatus,0;
		set Hp,bghp;
		set Sp,bgsp;
		warp "prontera",140,179;
	}		
	end;

// Start Arena rotation.
OnRotate:
// Rotate every n seconds.
OnTimer30000:
	.allowjoin = 1;
	if (getbattleflag(.hBGEnabled$) == 0) end;
	// Restart from index 0, if reached max.
	$BG_Index = $BG_Index + 1;
	if ($BG_Index >= .TotalArenas)
		$BG_Index = 0;

	.BG_Arena$ = .BG_Arenas$[$BG_Index];
	initnpctimer;
	// Fall through
// Called every time someone joins the Queue.
OnQueueJoinEvent:
	// BG Status Types -
	// 0 - Idle, ready to start.
	// 1 - Running, others can join.
	// 2 - Ending, Battleground is clearing up.
	if ($@Arena_Status == 2)
		end;

	.@Queue_Count = hBG_queue_data(.BG_Queue,0);
	switch($@Arena_Status) {
	case 0: // Idle, ready to start.
		// Set total Arena teams
		if (.BG_Arena$ == "Tierra_TI")
			.@TotalTeams = 3;
		else
			.@TotalTeams = 2;

		// Set total minimum Arena players.
		.@Req = .BG_Players_Min[$BG_Index] * .@TotalTeams;

		// Check if the required number of players have been reached, and process.
		if (.@Queue_Count >= .@Req) {
			donpcevent .BG_Arena$ + "::OnBuildTeams";

			// Fill Teams with Queue Members
			if (.@TotalTeams == 3)
				hBG_queue2teams .BG_Queue,.BG_Players_Min[$BG_Index],.BG_Players_Max[$BG_Index],.TeamBuildingMode,$@BG_Team1,$@BG_Team2,$@BG_Team3;
			else
				hBG_queue2teams .BG_Queue,.BG_Players_Min[$BG_Index],.BG_Players_Max[$BG_Index],.TeamBuildingMode,$@BG_Team1,$@BG_Team2;

			// Stop Arena Rotation.
			stopnpctimer;

			// Set BG Status as Ongoing.
			$@Arena_Status = 1;

			.@msg$ = "[Battlegrounds] " + .BG_Names$[$BG_Index] + " is commencing. Type @bg to join the Battle Ground.";
			announce .@msg$,0,.BG_Color$[$BG_Index],0x190,12,100,100;

			// Start Battleground Events.
			donpcevent .BG_Arena$ + "::OnReady";
		} else { // Required players have not been reached.
			.@msg$ = "[Battlegrounds] "+.BG_Names$[$BG_Index]+" requires "+(.@Req - .@Queue_Count)+" more player(s) to start. Type @bg to join the Battle Ground.";
			announce .@msg$,0,.BG_Color$[$BG_Index],0x190,12,100,100;
		}
		break;
	case 1: // Running, others can join.
		if (.@Queue_Count > 0) {
			if (.BG_Arena$ == "Tierra_TI") {
				hBG_balance_teams .BG_Queue,.BG_Players_Max[$BG_Index],.TeamBuildingMode,$@BG_Team1,$@BG_Team2,$@BG_Team3;
				.@BG_Count1 = hBG_get_data($@BG_Team1, 0);
				.@BG_Count2 = hBG_get_data($@BG_Team2, 0);
				.@BG_Count3 = hBG_get_data($@BG_Team3, 0);
				.@msg$ = "[Battlegrounds] " + .BG_Names$[$BG_Index] + " is ongoing. Blue Team: " + .@BG_Count1 + "/" + .BG_Players_Max[$BG_Index] + ", Red Team: " + .@BG_Count2 + "/" + .BG_Players_Max[$BG_Index] + ", Green Team: " + .@BG_Count3 + "/" + .BG_Players_Max[$BG_Index] + ". Type @bg to join the Battle Ground.";
			} else {
				hBG_balance_teams .BG_Queue,.BG_Players_Max[$BG_Index],.TeamBuildingMode,$@BG_Team1,$@BG_Team2;
				.@BG_Count1 = hBG_get_data($@BG_Team1, 0);
				.@BG_Count2 = hBG_get_data($@BG_Team2, 0);
				.@msg$ = "[Battlegrounds] " + .BG_Names$[$BG_Index] + " is ongoing. Blue Team: " + .@BG_Count1 + "/" + .BG_Players_Max[$BG_Index] + ", Red Team: " + .@BG_Count2 + "/" + .BG_Players_Max[$BG_Index] + ". Type @bg to join the Battle Ground.";
			}
			announce .@msg$, 0, .BG_Color$[$BG_Index], 0x190, 12, 100, 100;
		}
	default:
		break;
	}
	end;

OnFFAQueueJoinEvent:
	if ($@FFA_Arena_Status != 0)
		end;

	.@Queue_Count = hBG_queue_data(.FFA_Queue, 0);

	if (.@Queue_Count >= 10) {
		donpcevent "FFA_Arena::OnBuildTeams";
		hBG_queue2teams .FFA_Queue,1,0,$@FFA_Team[0],$@FFA_Team[1],$@FFA_Team[2],$@FFA_Team[3],$@FFA_Team[4],$@FFA_Team[5],$@FFA_Team[6],$@FFA_Team[7],$@FFA_Team[8],$@FFA_Team[9];
		set $@FFA_Arena_Status,1;
		announce "[Battlegrounds] Free For All is commencing.",0,0x483D8B;
		donpcevent "FFA_Arena::OnReady";
	} else {
		announce "[Battlegrounds] Free For All requires " + (10 - .@Queue_Count) + " more player(s) to start. Type @bg to join the Battle Ground.",0,0x483D8B;
	}
	end;
}
/**
 * Battleground Recruiter
 */
-	script	BG_Register	FAKE_NPC,{
	set .@name$, "[^FFA500Battle Recruiter^000000]";
	if (getvariableofnpc(.Ready,"BG_Queue_Handler") == 0)
		donpcevent "BG_Queue_Handler::OnInit";

	mes .@name$;
	mes "Good day, adventurer.";
	mes "I'm a knight from a far country called Maroll Kingdom.";
	next;
	mes .@name$;
	mes "The two princes of the kingdom are now battling for the throne of Maroll, and are in need of experienced soldiers like you.";
	mes "How would you like to lend your power to one of the princes in the Maroll Kingdom?";
	next;
	switch(select("^FFA500Battleground Arenas^000000:^0000FFFree For All Arena^000000:Warp to Battle Room")) {
	case 1:
		mes .@name$;
		mes "Battleground Arenas are different kinds of games where teams fight for victory.";
		mes "What do you want to do?";
		next;
		switch(select("Register:Party Register:Leave Queue:Battleground Help")) {
		case 1:
			if (BaseLevel < .BGQueue_Level_Min) {
				mes .@name$;
				mes "The minimum required level to join a battleground is "+.BGQueue_Level_Min+".";
				close;
			}
			if (questprogress(8506,PLAYTIME) == 2)
				erasequest 8506;

			if (questprogress(8506,PLAYTIME) == 1) {
				mes .@name$;
				mes "You are a Deserter. You can't participate until the indicator goes off.";
				close;
			}

			mes .@name$;
			mes "Let's proceed with the registration...";
			mes "You must wait in any City until BG starts.";
			mes "Close this window to continue...";
			close2;
			hBG_queue_join getvariableofnpc(.BG_Queue,"BG_Queue_Handler");
			end;
		case 2:
			if (getcharid(1) == 0) {
				mes .@name$;
				mes "You are not in a Party.";
				close;
			}

			mes .@name$;
			mes "Let's proceed with the registration,";
			mes "You must wait in any City until the BG starts.";
			mes "* close this window to continue *";
			close2;
			hBG_queue_partyjoin getcharid(1),getvariableofnpc(.BG_Queue,"BG_Queue_Handler");
			end;
		case 3:
			mes .@name$;
			mes "If you are queued, you will be removed from the Battleground queue.";
			mes "Are you sure you want to proceed?";
			next;
			if (select("Yes, leave the queue.:No, I will stay queued.") == 2) {
				mes .@name$;
				mes "Ok, nothing to change.";
				close;
			}

			mes .@name$;
			mes "* close this window to continue *";
			close2;
			hBG_queue_leave getvariableofnpc(.BG_Queue,"BG_Queue_Handler");
			end;
		case 4:
			mes .@name$;
			mes "So which battleground would you like to learn about?";
			next;
			switch(select("Capture the Flag:Team Death Match:Stone Control:Eye of Storm:Bossnia:Domination:Triple Inferno:Conquest:Rush"))
			{
			case 1:
				mes .@name$;
				mes "The objective of the ^990022Flavius Battle CTF^000000 is to score 3 points before your enemy, by capturing their Flag.";
				next;
				mes .@name$;
				mes "To capture a Flag you need to take the Enemy Flag, and bring it to your base.";
				next;
				mes .@name$;
				mes "If your base flag is captured, you need to kill the Flag carrier and take the flag back to your base.";
				next;
				mes .@name$;
				mes "Also make sure to protect the Flag carrier on your team from your enemies.";
				break;
			case 2:
				mes .@name$;
				mes "Both teams start with 100 points.";
				mes "Killing a player costs the team 1 point.";
				mes "Kill all the enemy players to reduce their points until they have none.";
				mes "Protect our army!";
				break;
			case 3:
				mes .@name$;
				mes "Take the stones in the middle of the battlefield and place them at your base.";
				next;
				mes .@name$;
				mes "Each stone will give points to your team over time. First team to reach 99 points wins the game.";
				next;
				mes .@name$;
				mes "Team Stones can also be captured by the enemy team, so protect them well!";
				break;
			case 4:
				mes .@name$;
				mes "There are two bases, located towards the North and South, which teams can capture by holding their position for longer than their opposition.";
				next;
				mes .@name$;
				mes "Each base will give you points every 5 seconds. If your team controls both bases, the amount of points drastically increases.";
				next;
				mes .@name$;
				mes "To get aditional points, capture a flag that spawns in the middle of the map and put it on any of your team Bases.";
				next;
				mes .@name$;
				mes "The first team to reach 99 points wins the match.";
				break;
			case 5:
				mes .@name$;
				mes "Attack the enemy base and destroy each MVP Guardian. To do damage to the guardian your team must capture the Balance Flag in the middle base.";
				next;
				mes .@name$;
				mes "Each team has 5 guardians in total, to be protected or killed.";
				break;
			case 6:
				mes .@name$;
				mes "There are three bases, North, Center and South which teams can capture by holding their position on them.";
				next;
				mes .@name$;
				mes "Each base will give you points for every 5 seconds of domination.";
				next;
				mes .@name$;
				mes "The first team to reach 99 points wins the match.";
				break;
			case 7:
				mes .@name$;
				mes "There are 3 teams in this Arena, all enemies of each other.";
				next;
				mes .@name$;
				mes "Kill the enemy players, collect their skulls and bring them to the Sacrifice Totem to win points.";
				next;
				mes .@name$;
				mes "You can collect your own team skulls and bring them to your Sacrifice Totem to avoid other teams to score.";
				next;
				mes .@name$;
				mes "If you get killed, all your skulls will be dropped on to the floor, including your own skull. First Team to get 80 points wins the battle.";
				break;
			case 8:
				mes .@name$;
				mes "In the Conquest arena,";
				mes "If you are Attacking, destroy the enemy's defenses and their flag.";
				mes "If you are Defending, protect your castle defenses and your flag.";
				break;
			case 9:
				mes .@name$;
				mes "In the Rush arena,";
				mes "Fight to capture the Castle and organize your team to defend it.";
				mes "If you fail on the first capture, kill the defender and take it for your team.";
				break;
			}
			break;
		}
		close;
	case 2:
		mes .@name$;
		mes "The Free For All arena is a killfest between 10 players. There are no teams.";
		mes "The first player to reach 25 kills wins.";
		mes "What would you like to do?";
		next;
		switch(select("Register for FFA Arena:Leave the Queue:Cancel")) {
		case 1:
			if (BaseLevel < .BGQueue_Level_Min) {
				mes .@name$;
				mes "Minimum required level to join a battleground is "+.BGQueue_Level_Min+".";
				close;
			}
			if (questprogress(8506,PLAYTIME) == 2)
				erasequest 8506;

			if (questprogress(8506,PLAYTIME) == 1) {
				mes .@name$;
				mes "You are a deserter. You can't participate until the indicator goes off.";
				close;
			}

			mes .@name$;
			mes "Let's proceed with the registration...";
			mes "You must wait in any city until BG starts.";
			mes "* close this window to continue *";
			close2;
			hBG_queue_join getvariableofnpc(.FFA_Queue,"BG_Queue_Handler");
			end;
		case 2:
			mes .@name$;
			mes "If you are registered, you will be removed.";
			mes "Are you sure?";
			next;
			if (select("Yes, leave queue:No, I will stay") == 2)
			{
				mes .@name$;
				mes "Ok, nothing to change.";
				close;
			}

			mes .@name$;
			mes "* close this window to continue *";
			close2;
			hBG_queue_leave getvariableofnpc(.FFA_Queue,"BG_Queue_Handler");
			end;
		case 3:
			close2;
		}
		break;
	case 3:
		mes .@name$;
		mes "May the blessings of the war Gods be with you.";
		close2;
		warp "bat_room",155,150;
		end;
	}
	end;
}

/*
bat_room,161,154,3	duplicate(BG_Register)	Battle Recruiter#bat	4_F_JOB_KNIGHT
prontera,149,175,4	duplicate(BG_Register)	Battle Recruiter#prt	4_F_JOB_KNIGHT
comodo,173,143,4	duplicate(BG_Register)	Battle Recruiter#cmd	4_F_JOB_KNIGHT
morocc,172,87,1	duplicate(BG_Register)	Battle Recruiter#moc	4_F_JOB_KNIGHT
geffen,136,56,3	duplicate(BG_Register)	Battle Recruiter#gef	4_F_JOB_KNIGHT
payon,147,80,6	duplicate(BG_Register)	Battle Recruiter#pay	4_F_JOB_KNIGHT
alberta,201,120,3	duplicate(BG_Register)	Battle Recruiter#alb	4_F_JOB_KNIGHT
aldebaran,153,108,5	duplicate(BG_Register)	Battle Recruiter#ald	4_F_JOB_KNIGHT
izlude,106,114,5	duplicate(BG_Register)	Battle Recruiter#izl	4_F_JOB_KNIGHT
yuno,141,178,5	duplicate(BG_Register)	Battle Recruiter#yun	4_F_JOB_KNIGHT
amatsu,192,95,5	duplicate(BG_Register)	Battle Recruiter#ama	4_F_JOB_KNIGHT
gonryun,148,114,4	duplicate(BG_Register)	Battle Recruiter#gon	4_F_JOB_KNIGHT
comodo,173,143,4	duplicate(BG_Register)	Battle Recruiter#comodo	4_F_JOB_KNIGHT
*/

/**
 * General Guillaume
 */
bat_room,160,159,3	script	General Guillaume#hBG	4_M_KY_KIYOM,{
	cutin "bat_kiyom2",2;
	set .@name$, "[General Guillaume]";
	mes .@name$;
	mes "Hot-blooded adventurer, we need the aid of your abilities to win this battle.";
	next;
	cutin "bat_kiyom1",2;
	mes .@name$;
	mes "Our great king, Marcel Marollo VII, is very sick lately. His Majesty has declared to choose either me or Prince Croix as the next king amongst his 9 sons.";
	next;
	mes .@name$;
	mes "Two kings can't share a nation!";
	mes "Only the one victorious from his majesty's appointed battle will be enthroned.";
	next;
	mes .@name$;
	mes "This is however, not just a battle between us. This battle will determine the future of this country. I pledge on my honor to prove that I'm the one who can protect this Maroll from outside threats.";
	next;
	mes .@name$;
	mes "I'll be the one who will capture the flag!";
	close2;
	cutin "",255;
	end;
}

/**
 * Prince Croix
 */
bat_room,160,140,3	script	Prince Croix#hBG	4_M_CRU_CRUA,{
	cutin "bat_crua1",2;
	set .@name$, "[Prince Croix]";
	mes .@name$;
	mes "Wise adventurer, why don't you lend us your power for victory?";
	next;
	cutin "bat_crua2",2;
	mes .@name$;
	mes "I do not wish to shed blood, but I have no choice but to fight for the possibility of peace and for the sake of my people.";
	next;
	mes .@name$;
	mes "General Guillaume may have an advantage in this battle as he is the great general of Maroll, but that doesn't automatically mean he'll win. I want to win this battle so that I can grant a better future for my people.";
	next;
	mes .@name$;
	mes "For Maroll!";
	close2;
	cutin "",255;
	end;
}

/**
 * Battleground Dummy Guards
 */
bat_room,161,141,3	script	Prince Croix's Aid::bat_aid	4_M_CRU_HEAD,{ end; }
bat_room,161,139,3	duplicate(bat_aid)	Prince Croix's Aid::bat_aid2	4_M_CRU_HEAD
bat_room,161,160,3	duplicate(bat_aid)	General Guillaume's Aid::bat_aid3	4_M_KY_HEAD
bat_room,161,158,3	duplicate(bat_aid)	General Guillaume's Aid::bat_aid4	4_M_KY_HEAD

/**
 * Battleground Flags
 */
-	script	Guillaume camp#bat	1_FLAG_LION,{ end; }
-	script	Croix camp#bat	1_FLAG_EAGLE,{ end; }

/**
 *  Battleground Exit Teleporter
 */
bat_room,148,150,4	script	Teleporter#bat	4_F_TELEPORTER,{
	set .@name$, "[Teleporter]";
	mes .@name$;
	mes "Do you wish to leave the battlefield? Use my service to return to town.";
	next;
	if (select("I wish to leave.:I wish to stay.") == 2) {
		mes .@name$;
		mes "I'll be here whenever you're in need of my service.";
		close;
	}

	switch(@ArenaPVP_out) {
		// Rune Midgard Republic
		case 1: warp "prontera",149,92; break;
		case 2: warp "payon",165,98; break;
		case 3: warp "morocc",153,94; break;
		case 4: warp "umbala",121,143; break;
		case 5: warp "comodo",196,140; break;
		case 6: warp "niflheim",214,193; break;
		case 7: warp "aldebaran",143,111; break;
		case 8: warp "geffen",107,53; break;
		// Schwarzard Republic
		case 9: warp "yuno",151,177; break;
		case 10: warp "hugel",99,143; break;
		case 11: warp "lighthalzen",167,93; break;
		case 12: warp "einbroch",70,194; break;
		case 13: warp "einbech",168,130; break;
		// Arunafelz Republic
		case 14: warp "rachel",118,114; break;
		case 15: warp "veins",207,122; break;
		// Islands
		case 16: warp "nameless_n",161,179; break;
		case 17: warp "louyang",213,106; break;
		case 18: warp "gonryun",154,111; break;
		case 19: warp "ayothaya",148,109; break;
		case 20: warp "moscovia",229,195; break;
		case 21: warp "xmas",151,127; break;
		case 22: warp "amatsu",203,107; break;
		case 23: warp "izlude",126,114; break;
		case 24: warp "brasilis",195,211; break;
		case 25: warp "manuk",279,214; break;
		case 26: warp "splendide",200,174; break;
		// Anyplace else
		default:
			set .@spoint$, getsavepoint(0);
			set .@x, getsavepoint(1);
			set .@y, getsavepoint(2);
			mes .@name$;
			mes "You will be sent back to " + .@spoint$ + ".";
			close2;
			warp .@spoint$, .@x, .@y;
			break;
	}

	set @ArenaPVP_out, 0;
	end;
}

// Battleground Therapist

-	script	Therapist	4_F_SISTER,{
	mes "[Therapist in battle]";
	mes "Just close your eyes, and take a deep breathe.";
	mes "You can be free from pain.";
	specialeffect(EF_HEAL2, AREA, playerattached()); percentheal 100,100;
//	specialeffect(EF_INCAGILITY, AREA, playerattached()); sc_start SC_INC_AGI,240000,10;
//	specialeffect(EF_BLESSING, AREA, playerattached()); sc_start SC_BLESSING,240000,10;
	repairall;
	close2;
	openstorage;
	end;
}

// Battleground Therapist Duplicates
// bg_conquest Therapist

schg_cas06,260,383,5	duplicate(Therapist)	Therapist#cq1	4_F_SISTER
schg_cas06,299,383,3	duplicate(Therapist)	Therapist#cq2	4_F_SISTER
schg_cas07,86,315,5	duplicate(Therapist)	Therapist#cq3	4_F_SISTER
schg_cas07,117,315,3	duplicate(Therapist)	Therapist#cq4	4_F_SISTER
schg_cas08,23,50,6	duplicate(Therapist)	Therapist#cq5	4_F_SISTER
schg_cas08,92,50,4	duplicate(Therapist)	Therapist#cq6	4_F_SISTER
arug_cas06,26,385,5	duplicate(Therapist)	Therapist#cq7	4_F_SISTER
arug_cas06,122,361,5	duplicate(Therapist)	Therapist#cq8	4_F_SISTER
arug_cas07,304,342,3	duplicate(Therapist)	Therapist#cq9	4_F_SISTER
arug_cas07,304,305,1	duplicate(Therapist)	Therapist#cq0	4_F_SISTER
arug_cas08,310,154,6	duplicate(Therapist)	Therapist#cqa	4_F_SISTER
arug_cas08,333,154,4	duplicate(Therapist)	Therapist#cqb	4_F_SISTER

// bg_flavius_ctf Therapist

bat_b02,390,13,5	duplicate(Therapist)	Therapist#ctf1	4_F_SISTER
bat_b02,10,293,5	duplicate(Therapist)	Therapist#ctf2	4_F_SISTER

// bg_flavius_sc Therapist

bat_b04,390,13,5	duplicate(Therapist)	Therapist#sc1	4_F_SISTER
bat_b04,10,293,5	duplicate(Therapist)	Therapist#sc2	4_F_SISTER

// bg_flavius_td Therapist

bat_b03,390,13,5	duplicate(Therapist)	Therapist#td1	4_F_SISTER
bat_b03,10,293,5	duplicate(Therapist)	Therapist#td2	4_F_SISTER

// bg_rush Therapist

rush_cas01,198,230,6	duplicate(Therapist)	Therapist#rh1	4_F_SISTER
rush_cas01,198,226,6	duplicate(Therapist)	Therapist#rh2	4_F_SISTER
rush_cas02,142,50,6	duplicate(Therapist)	Therapist#rh3	4_F_SISTER
rush_cas02,142,46,6	duplicate(Therapist)	Therapist#rh4	4_F_SISTER
rush_cas03,60,17,4	duplicate(Therapist)	Therapist#rh5	4_F_SISTER
rush_cas03,64,17,4	duplicate(Therapist)	Therapist#rh6	4_F_SISTER
rush_cas04,266,292,6	duplicate(Therapist)	Therapist#rh7	4_F_SISTER
rush_cas04,266,288,6	duplicate(Therapist)	Therapist#rh8	4_F_SISTER

// bg_tierra_boss Therapist

bat_a03,53,377,3	duplicate(Therapist)	Therapist#tb1	4_F_SISTER
bat_a03,45,18,3	duplicate(Therapist)	Therapist#tb2	4_F_SISTER

// bg_tierra_dom Therapist

bat_a04,53,377,3	duplicate(Therapist)	Therapist#DOM1	4_F_SISTER
bat_a04,45,18,3	duplicate(Therapist)	Therapist#DOM2	4_F_SISTER

// bg_tierra_eoe Therapist

bat_a02,53,377,3	duplicate(Therapist)	Therapist#eoe1	4_F_SISTER
bat_a02,45,18,3	duplicate(Therapist)	Therapist#eoe2	4_F_SISTER

// bg_tierra_ti Therapist

region_8,7,52,5	duplicate(Therapist)	Therapist#ti_1	4_F_SISTER
region_8,52,92,3	duplicate(Therapist)	Therapist#ti_2	4_F_SISTER
region_8,92,52,3	duplicate(Therapist)	Therapist#ti_3	4_F_SISTER


bat_room	mapflag	nopenalty