//===== rAthena Script ======================================= 
//= Kafra Express - Pvp Warping Module
//===== By: ================================================== 
//= Skotlex 
//===== Current Version: ===================================== 
//= 1.7
//===== Compatible With: ===================================== 
//= rAthena SVN R3424+
//===== Description: ========================================= 
//= Part of the Kafra Express Script Package.
//= Offers warping to the PvP arenas.
//===== Additional Comments: ================================= 
//= See config.txt for configuration.
//============================================================ 

-	script	keInit_warpPvp	-1,{
OnInit:	//Load Config
	donpcevent "keConfig::OnLoadWarpPvp";
	end;
}

function	script	F_keWarpPvp	{

	function SF_pvpMenu;

	set @cost,callfunc("F_keCost",1,100);
	if ($@kewp_advanced == 0) {
		SF_pvpMenu 1,$@kewp_cost,100,0,0;
		return;
	}

	do {
		if ($@kewp_showOnline) { 
			set @kmenu, select(
				"- Cancel",
				"- All Levels Rooms ("+($@kewp_cost*@cost)+"z/"+(getmapusers("pvp_n_8-1")+getmapusers("pvp_n_8-2")
					+getmapusers("pvp_n_8-3")+getmapusers("pvp_n_8-4")+getmapusers("pvp_n_8-5"))+" "+$@ked_users$+")",
				"- Levels "+($@kewp_baseLv1-$@kewp_range)+"-"+($@kewp_baseLv1+$@kewp_range)+" Rooms ("+($@kewp_cost1*@cost)+"z/"
					+(getmapusers("pvp_n_1-1")+getmapusers("pvp_n_1-2")+getmapusers("pvp_n_1-3")
					+getmapusers("pvp_n_1-4")+getmapusers("pvp_n_1-5"))+" "+$@ked_users$+")",
				"- Levels "+($@kewp_baseLv2-$@kewp_range)+"-"+($@kewp_baseLv2+$@kewp_range)+" Rooms ("+($@kewp_cost2*@cost)+"z/"
					+(getmapusers("pvp_n_2-1")+getmapusers("pvp_n_2-2")+getmapusers("pvp_n_2-3")
					+getmapusers("pvp_n_2-4")+getmapusers("pvp_n_2-5"))+" "+$@ked_users$+")",
				"- Levels "+($@kewp_baseLv3-$@kewp_range)+"-"+($@kewp_baseLv3+$@kewp_range)+" Rooms ("+($@kewp_cost3*@cost)+"z/"
					+(getmapusers("pvp_n_3-1")+getmapusers("pvp_n_3-2")+getmapusers("pvp_n_3-3")
					+getmapusers("pvp_n_3-4")+getmapusers("pvp_n_3-5"))+" "+$@ked_users$+")",
				"- Levels "+($@kewp_baseLv4-$@kewp_range)+"-"+($@kewp_baseLv4+$@kewp_range)+" Rooms ("+($@kewp_cost4*@cost)+"z/"
					+(getmapusers("pvp_n_4-1")+getmapusers("pvp_n_4-2")+getmapusers("pvp_n_4-3")
					+getmapusers("pvp_n_4-4")+getmapusers("pvp_n_4-5"))+" "+$@ked_users$+")",
				"- Levels "+($@kewp_baseLv5-$@kewp_range)+"-"+($@kewp_baseLv5+$@kewp_range)+" Rooms ("+($@kewp_cost5*@cost)+"z/"
					+(getmapusers("pvp_n_5-1")+getmapusers("pvp_n_5-2")+getmapusers("pvp_n_5-3")
					+getmapusers("pvp_n_5-4")+getmapusers("pvp_n_5-5"))+" "+$@ked_users$+")",
				"- Levels "+($@kewp_baseLv6-$@kewp_range)+"-"+($@kewp_baseLv6+$@kewp_range)+" Rooms ("+($@kewp_cost6*@cost)+"z/"
					+(getmapusers("pvp_n_6-1")+getmapusers("pvp_n_6-2")+getmapusers("pvp_n_6-3")
					+getmapusers("pvp_n_6-4")+getmapusers("pvp_n_6-5"))+" "+$@ked_users$+")",
				"- Levels "+($@kewp_baseLv7-$@kewp_range)+"-"+($@kewp_baseLv7+$@kewp_range)+" Rooms ("+($@kewp_cost7*@cost)+"z/"
					+(getmapusers("pvp_n_7-1")+getmapusers("pvp_n_7-2")+getmapusers("pvp_n_7-3")
					+getmapusers("pvp_n_7-4")+getmapusers("pvp_n_7-5"))+" "+$@ked_users$+")"
			);
		} else {
			set @kmenu, select(
				"- Cancel",
				"- No Level Restriction Rooms ("+($@kewp_cost*@cost)+"z)",
				"- Levels "+($@kewp_baseLv1-$@kewp_range)+"-"+($@kewp_baseLv1+$@kewp_range)+" Rooms ("+($@kewp_cost1*@cost)+"z)",
				"- Levels "+($@kewp_baseLv2-$@kewp_range)+"-"+($@kewp_baseLv2+$@kewp_range)+" Rooms ("+($@kewp_cost2*@cost)+"z)",
				"- Levels "+($@kewp_baseLv3-$@kewp_range)+"-"+($@kewp_baseLv3+$@kewp_range)+" Rooms ("+($@kewp_cost3*@cost)+"z)",
				"- Levels "+($@kewp_baseLv4-$@kewp_range)+"-"+($@kewp_baseLv4+$@kewp_range)+" Rooms ("+($@kewp_cost4*@cost)+"z)",
				"- Levels "+($@kewp_baseLv5-$@kewp_range)+"-"+($@kewp_baseLv5+$@kewp_range)+" Rooms ("+($@kewp_cost5*@cost)+"z)",
				"- Levels "+($@kewp_baseLv6-$@kewp_range)+"-"+($@kewp_baseLv6+$@kewp_range)+" Rooms ("+($@kewp_cost6*@cost)+"z)",
				"- Levels "+($@kewp_baseLv7-$@kewp_range)+"-"+($@kewp_baseLv7+$@kewp_range)+" Rooms ("+($@kewp_cost7*@cost)+"z)"
			);
		}
		switch(@kmenu) {
		case 2: //No restrictions
			SF_pvpMenu 8,$@kewp_cost,100,0,0;
			break;
		case 3:
			SF_pvpMenu 1,$@kewp_cost1,100,$@kewp_baseLv1-$@kewp_range,$@kewp_baseLv1+$@kewp_range;
			break;
		case 4:
			SF_pvpMenu 2,$@kewp_cost2,100,$@kewp_baseLv2-$@kewp_range,$@kewp_baseLv2+$@kewp_range;
			break;
		case 5:
			SF_pvpMenu 3,$@kewp_cost3,100,$@kewp_baseLv3-$@kewp_range,$@kewp_baseLv3+$@kewp_range;
			break;
		case 6:
			SF_pvpMenu 4,$@kewp_cost4,100,$@kewp_baseLv4-$@kewp_range,$@kewp_baseLv4+$@kewp_range;
			break;
		case 7:
			SF_pvpMenu 5,$@kewp_cost5,100,$@kewp_baseLv5-$@kewp_range,$@kewp_baseLv5+$@kewp_range;
			break;
		case 8:
			SF_pvpMenu 6,$@kewp_cost6,100,$@kewp_baseLv6-$@kewp_range,$@kewp_baseLv6+$@kewp_range;
			break;
		case 9:
			SF_pvpMenu 7,$@kewp_cost7,100,$@kewp_baseLv7-$@kewp_range,$@kewp_baseLv7+$@kewp_range;
			break;
		}
	} while (@kmenu > 1);
	return;

//SubFunction: SF_pvpMenu (int map-group, int cost, int min level, int max level)
//Displays the list of the five available Pvp rooms to warp to.
//map-group is the first index of the pvp map names (in pvp_n_2-3 it would be 2)
function SF_pvpMenu {
	if (getarg(4)) {
		if (BaseLevel < getarg(3)) {
			callfunc "F_keIntro", e_sry, "Sorry, you need at least level "+getarg(2)+" to enter these arenas.";
			return;
		}
		if (BaseLevel > getarg(4)) { 
			callfunc "F_keIntro", e_bzz, "Sorry, people above level "+getarg(3)+" are not allowed within these arenas.";
			return;
		}
		set @msg$,"levels "+getarg(3)+"-"+getarg(3);
	} else
		set @msg$,"all levels";
	if ($@kewp_showOnline) {
		set @submenu, select(
			"- Cancel Warp (Rooms for "+@msg$+"/"+(getarg(1)*@cost)+"z)",
			"- Room Sandwich ("+getmapusers("pvp_n_"+getarg(0)+"-1")+" "+$@ked_users$+")",
			"- Room Rock On ("+getmapusers("pvp_n_"+getarg(0)+"-2")+" "+$@ked_users$+")",
			"- Four Room ("+getmapusers("pvp_n_"+getarg(0)+"-3")+" "+$@ked_users$+")",
			"- Room Undercross ("+getmapusers("pvp_n_"+getarg(0)+"-4")+" "+$@ked_users$+")",
			"- Room Compass ("+getmapusers("pvp_n_"+getarg(0)+"-5")+" "+$@ked_users$+")"
		);
	} else {
		set @submenu, select(
			"- Cancel Warp (Rooms for "+@msg$+"/"+(getarg(1)*@cost)+"z)",
			"- Room Sandwich",
			"- Room Rock On",
			"- Four Room",
			"- Room Undercross",
			"- Room Compass"
		);
	}
	switch (@submenu) {
	case 2:
		callfunc "F_keWarp",getarg(1),getarg(2),e_com,"pvp_n_"+getarg(0)+"-1",-1,-1;
		break;
	case 3:
		callfunc "F_keWarp",getarg(1),getarg(2),e_com,"pvp_n_"+getarg(0)+"-2",-1,-1;
		break;
	case 4:
		callfunc "F_keWarp",getarg(1),getarg(2),e_com,"pvp_n_"+getarg(0)+"-3",-1,-1;
		break;
	case 5:
		callfunc "F_keWarp",getarg(1),getarg(2),e_com,"pvp_n_"+getarg(0)+"-4",-1,-1;
		break;
	case 6:
		callfunc "F_keWarp",getarg(1),getarg(2),e_com,"pvp_n_"+getarg(0)+"-5",-1,-1;
		break;
	}
}

}
