//===== eAthena Script ======================================= 
//= PvP
//===== By: ================================================== 
//= kobra_k88
//===== Current Version: ===================================== 
//= 1.2a
//===== Compatible With: ===================================== 
//= eAthena 0.5.2 +
//===== Description: ========================================= 
//=
//===== Additional Comments: ================================= 
//= v1.1 Fixed arena names for Nightmare mode.  Added room limit
//= check.[kobra_k88]
//= v1.2 Fixed the bug that you aways savepoint in geffen.[shadowlady]
//= v1.2a Added PvP Narrator function. Using args for Fight
//= Square Helpers. [kobra_k88]
//============================================================ 


//==========================================================================
//			PvP Narrators
//==========================================================================

// Alberta -----------------------------------------
alberta_in.gat,22,146,4	script	PvP Narrator#1	84,{
	callfunc "F_PvPNarr", "alberta_in.gat", 24, 143;
	end;
}
// Payon -------------------------------------
payon_in01.gat,173,109,3	script	PvP Narrator#2	84,{
	callfunc "F_PvPNarr", "payon_in01.gat", 169, 108;
	end;
}
// Prontera -------------------------------------
prt_in.gat,56,140,4	script	PvP Narrator#3	84,{
	callfunc "F_PvPNarr", "prt_in.gat", 54, 137;
	end;
}
// Morocc --------------------------------------
morocc_in.gat,144,138,4	script	PvP Narrator#4	84,{
	callfunc "F_PvPNarr", "morocc_in.gat", 141, 140;
	end;
}
// Geffen --------------------------------------
geffen_in.gat, 67,63,4	script	PvP Narrator#5	84,{
	callfunc "F_PvPNarr", "geffen_in.gat", 64, 60;
	end;
}

//******************************************************//
//	Function: PvP Narrator
//******************************************************//
// arg(0): mapname
// arg(1): savepoint x cord.
// arg(2): savepoint y cord.
//=============================
function	script	F_PvPNarr	{
	mes "[PvP Narrator]";
	mes "Hello and welcome! I am in charge of explaining the PvP mode to all of those who inquire.  I am the PvP Narrator!";
	M_Menu:
	next;
	menu "What is PvP?",M_0, "What are the PvP modes?",M_1, "What are the rules for PvP?",M_2, "Save position.",M_3;

	M_0:
		mes "[PvP Narrator]";
		mes "PvP is short for 'Player versus Player'! It is a unique play mode that allows players to duel other players!";
		next;
		mes "[PvP Narrator]";
		mes "If you're interested just speak with the ^5533FFGate Keeper'^000000.  He will let you into the PvP square.";
		next;
		mes "[PvP Narrator]";
		mes "That IS, IF you have at least a base level of 31 and you have 500 zeny to pay for the enterance fee.";
		mes "Those are the requirements to participate in PvP.";
		goto M_Menu;
	M_1:
		mes "[PvP Narrator]";
		mes "There are 2 PvP modes to choose from.";
		mes "One is called ^5533FF'Yoyo'^000000 Mode and the other is called ^5533FF'Nightmare'^000000 Mode.";
		next;
		mes "[PvP Narrator]";
		mes "Yoyo mode essentially lets you play risk free.  You can experience the thrill of PvP without any restrictions or penalties.";
		mes "It is recomended that you practice your skills in this mode before you move on.";
		next;
		mes "[PvP Narrator]";
		mes "Nightmare Mode is very dangerous! Please use caution when trying this mode of play.";
		mes "You will lose some of your real EXP if you are defeated.  There is also the small chance that you will drop some items and equipment.";
		next;
		mes "[PvP Narrator]";
		mes "Of course if you win, the rewards can be great!! Even so you should really think twice before you attempt Nightmare Mode.";
		mes "Anyways, good luck.";
		goto M_Menu;
	M_2:
		mes "[PvP Narrator]";
		mes "Before you enter any actual PvP areana, you must first choose your level of ability based on your base level.";
		mes "You will do this in the pre-fight room.  There will be a row of narrators, each one representing a set of player levels.";
		next;
		mes "[PvP Narrator]";
		mes "Speak to the narrator that represents your base level.  You will then be asked to choose from five different fight maps.";
		mes "You will be able to see how many people are currently participating in any given map.";
		next;
		mes "[PvP Narrator]";
		mes "This will be represented by the 'Attendee/Total' figure in the corner of the screen.  There is a limit to how many can play on a map.";
		mes "There is a hidden EXP value in PvP mode.  This EXP will only apply inside of the PvP zone and not outside.";
		next;
		mes "[PvP Narrator]";
		mes "Every one will recieve a base EXP of 5 points when they first start.  If you win a match your EXP with increase by 1 point.";
		mes "If you loose your EXP will drop by 5 points, so be carefull!";
		next;
		mes "[PvP Narrator]";
		mes "If you are defeated and your EXP is equal to or less than 0, you will be removed from the PvP arena.";
		mes "If your EXP is more than 0 than you may continue fighting and even get help from healers.";
		next;
		mes "[PvP Narrator]";
		mes "The fighting commands inside of PvP are the same as outside.  Just remember that you won't be able to save inside a PvP arena.";
		next;
		mes "[PvP Narrator]";
		mes "Remember these rules well as they can help to ensure your victory.";
		goto M_Menu;
	M_3:
		savepoint getarg(0), getarg(1), getarg(2);
		mes "[PvP Narrator]";
		mes "Your position has been saved.";
		close;
}


//==========================================================================
//			Gate Keepers
//==========================================================================

// Alberta -----------------------------------
alberta_in.gat, 26,146,4	script	Gate Keeper#1::GateKeep	83,{
	mes "[Gate Keeper]";
	mes "Hi.  I'm glad to be of service.  I will open the PvP fight square for you!";
	mes "If you have any questions about the PvP modes or rules, please ask the Narrator.....";
	next;
	menu	"^5533FF'PvP Yoyo Mode'^000000 Fight Square.",M_0, 
		"^FF5533'PvP Nightmare Mode'^000000 Fight Square.",M_1, 
		"^5533FF'PvP Duel (Fighting) Mode'^000000 Combat Square.",M_2, "End Conversation.",M_End;
	M_0:
		set @mode$, "Yoyo";
		set @players1, 128;
		set @players2, 128;
		set @room1$, "Prontera";
		set @room2$, "Izlude";
		set @room3$, "Payon";
		set @room4$, "Alberta";
		set @room5$, "Morroc";
		callsub sF_Move;
		warp "pvp_y_room.gat", 51, 23;
		end;
	M_1:
		set @mode$, "Nightmare";
		set @players1, 64;
		set @players2, 32;
		set @room1$, "Sandwhich Arena";
		set @room2$, "Rock Arena";
		set @room3$, "Four Arena";
		set @room4$, "UnderCross Arena";
		set @room5$, "Copass Arena";
		callsub sF_Move;
		warp "pvp_n_room.gat", 51, 23;
		end;
	M_2:

		mes "[Gate Keeper]";
		mes "To enter the Duel (Fighting) Mode square you must have an admission ticket.  Do you have one?";
		next;
		menu "Yes I do.",-, "No I don't.",sM_1;

			if(countitem(7029) < 1) goto sM_1;
			delitem 7029, 1;
			set @mode$, "Fighting";
			callsub sF_Move;
			warp "pvp_y_room.gat", 51, 23;
			end;

		sM_1:
			mes "[Gate Keeper]";
			mes "Eh? You don't have one? I'm sorry but this fight square is only for people who have admission or viewing tickets.";
			mes "You cannot come in without one.";
			close;
	M_End:
		mes "[Gate Keeper]";
		mes "In this war between Monsters and Humans this competition between people, PvP, encourages all of us to become stronger.";
		mes "Come again anytime.  We welcome your challenge!";
		close;

sF_Move:
	mes "[Gate Keeper]";
	mes "The admission fee is 500 Zeny.  Do you want to move to the "+@mode$+" fight square?";
	next;
	menu "Yes",-, "No",M_End;

		if(BaseLevel < 31) goto sL_LowLvl;
		if(Zeny < 500) goto sL_NdZeny;
		set Zeny, Zeny - 500;
		mes "[Gate Keeper]";
		mes "Prepare to be warped to the arena.....";
		next;
		return;

		sL_LowLvl:
			mes "[Gate Keeper]";
			mes "In order to participate in PvP you must have a base level of at least ^FF4444'31'^000000.";
			close;
		sL_NdZeny:
			mes "[Gate Keeper]";
			mes "As I stated, the admission fee is ^FF4444'500'^000000 Zeny.  You seem to be short on Zeny.";
			close;
}

// Geffen --------------------------------------------
geffen_in.gat, 63,63,4	duplicate(GateKeep)	Gate Keeper#2	83
// Morroc----------------------------------------------
morocc_in.gat, 144,142,4	duplicate(GateKeep)	Gate Keeper#3	83
// Payon ----------------------------------------------
payon_in01.gat,175,106,3	duplicate(GateKeep)	Gate Keeper#4	83
// Prontera -------------------------------------------
prt_in.gat,52,140,4	duplicate(GateKeep)	Gate Keeper#5	83



//==========================================================================//
// 		PvP Yoyo Mode Fight Square Helpers
//==========================================================================//

// LV31 ~ 40 ---------------------------------
pvp_y_room.gat,30,85,4	script	Fight Square Helper::YHelper1	105,{
	callfunc "F_PvPRoom", "y_1", 31, 40;
OnInit:
	waitingroom "LV31 ~ LV40",0;
	end;
}

// LV41 ~ 50 --------------------------------
pvp_y_room.gat,38,85,4	script	Fight Square Helper::YHelper2	105,{
	callfunc "F_PvPRoom", "y_2", 41, 50;
OnInit:
	waitingroom "LV41 ~ LV50",0;
	end;
}

// LV51 ~ 60 ---------------------------------
pvp_y_room.gat,46,85,4	script	Fight Square Helper::YHelper3	105,{
	callfunc "F_PvPRoom", "y_3", 51, 60;
OnInit:
	waitingroom "LV51 ~ LV60", 0;
	end;
}

// LV61 ~ 70 ------------------------------------
pvp_y_room.gat,54,85,4	script	Fight Square Helper::YHelper4	105,{
	callfunc "F_PvPRoom", "y_4", 61, 70;
OnInit:
	waitingroom "LV61 ~ LV70", 0;
	end;
}

// LV71 ~ 80 ------------------------------------
pvp_y_room.gat,62,85,4	script	Fight Square Helper::YHelper5	105,{
	callfunc "F_PvPRoom", "y_5", 71, 80;
OnInit:
	waitingroom "LV71 ~ LV80", 0;
	end;
}

// LV81 ~ 90 --------------------------------------
pvp_y_room.gat,70,85,4	script	Fight Square Helper::YHelper6	105,{
	callfunc "F_PvPRoom", "y_6", 81, 90;
OnInit:
	waitingroom "LV81 ~ LV90", 0;
	end;
}

// LV91 ~  --------------------------------------------
pvp_y_room.gat,78,85,4	script	Fight Square Helper::YHelper7	105,{
	callfunc "F_PvPRoom", "y_7", 91, 255;
OnInit:
	waitingroom "LV91 ~ ", 0;
	end;
}

// No Limit  -----------------------------------------
pvp_y_room.gat,86,85,4	script	Fight Square Helper::YHelper8	105,{
	callfunc "F_PvPRoom", "y_8", 0, 255;
OnInit:
	waitingroom "No Limit", 0;
	end;
}


//==========================================================================//
// 		PvP Nightmare Mode Fight Square Helpers
//==========================================================================//
// LV31 ~ 40 -------------------------------------
pvp_n_room.gat,30,85,4	script	Fight Square Helper#N1	105,{
	callfunc "F_PvPRoom", "n_1", 31, 40;
OnInit:
	waitingroom "LV31 ~ LV40",0;
	end;
}

// LV41 ~ 50 --------------------------------------
pvp_n_room.gat,38,85,4	script	Fight Square Helper#N2	105,{
	callfunc "F_PvPRoom", "n_2", 41, 50;
OnInit:
	waitingroom "LV41 ~ LV50",0;
	end;
}

// LV51 ~ 60 -------------------------------------
pvp_n_room.gat,46,85,4	script	Fight Square Helper#N3	105,{
	callfunc "F_PvPRoom", "n_3", 51, 60;
OnInit:
	waitingroom "LV51 ~ LV60", 0;
	end;
}

// LV61 ~ 70 ------------------------------------
pvp_n_room.gat,54,85,4	script	Fight Square Helper#N4	105,{
	callfunc "F_PvPRoom", "n_4", 61, 70;
OnInit:
	waitingroom "LV61 ~ LV70", 0;
	end;
}

// LV71 ~ 80 -----------------------------------
pvp_n_room.gat,62,85,4	script	Fight Square Helper#N5	105,{
	callfunc "F_PvPRoom", "n_5", 71, 80;
OnInit:
	waitingroom "LV71 ~ LV80", 0;
	end;
}

// LV81 ~ 90 ------------------------------------
pvp_n_room.gat,70,85,4	script	Fight Square Helper#N6	105,{
	callfunc "F_PvPRoom", "n_6", 81, 90;
OnInit:
	waitingroom "LV81 ~ LV90", 0;
	end;
}

// LV91 ~  ---------------------------------------
pvp_n_room.gat,78,85,4	script	Fight Square Helper#N7	105,{
	callfunc "F_PvPRoom", "n_7", 91, 255;
OnInit:
	waitingroom "LV91 ~ ", 0;
	end;
}

// No Limit  ----------------------------------
pvp_n_room.gat,86,85,4	script	Fight Square Helper#N8	105,{
	callfunc "F_PvPRoom", "n_8", 0, 255;
OnInit:
	waitingroom "No Limit", 0;
	end;
}


//***************************************************************//
//	Function: PvP Fight Square Helper
//***************************************************************//
// arg(0): pvp room name
// arg(1): minimum base lvl to enter arena
// arg(2): maximum base lvl allowed to enter arena
//===============================================
function	script	F_PvPRoom	{

	mes "[Fight Square Helper]";
	if(BaseLevel < getarg(1)) goto L_LowLvl;
	if(BaseLevel > getarg(2)) goto L_HiLvl;
	mes "Please choose an arena to fight in...";
	M_Menu:
	next;
	menu 	@room1$ + " [" + getmapusers("pvp_" + getarg(0) + "-1.gat") + "/" +@players1+ "]",M_Rm1, 
		@room2$ + " [" + getmapusers("pvp_" + getarg(0) + "-2.gat") + "/" +@players2+ "]",M_Rm2, 
		@room3$ + " [" + getmapusers("pvp_" + getarg(0) + "-3.gat") + "/" +@players2+ "]",M_Rm3, 
		@room4$ + " [" + getmapusers("pvp_" + getarg(0) + "-4.gat") + "/" +@players2+ "]",M_Rm4, 
		@room5$ + " [" + getmapusers("pvp_" + getarg(0) + "-5.gat") + "/" +@players2+ "]",M_Rm5, "Cancel",M_End;
	M_Rm1:
		if (getmapusers("pvp_" + getarg(0) + "-1.gat") == @players1) goto L_Full;
		warp "pvp_" + getarg(0) + "-1.gat",0,0;
		end;
	M_Rm2:
		if (getmapusers("pvp_" + getarg(0) + "-2.gat") == @players2) goto L_Full;
		warp "pvp_" + getarg(0) + "-2.gat",0,0;
		end;
	M_Rm3:
		if (getmapusers("pvp_" + getarg(0) + "-3.gat") == @players2) goto L_Full;
		warp "pvp_" + getarg(0) + "-3.gat",0,0;
		end;
	M_Rm4:
		if (getmapusers("pvp_" + getarg(0) + "-4.gat") == @players2) goto L_Full;
		warp "pvp_" + getarg(0) + "-4.gat",0,0;
		end;
	M_Rm5:
		if (getmapusers("pvp_" + getarg(0) + "-5.gat") == @players2) goto L_Full;
		warp "pvp_" + getarg(0) + "-5.gat",0,0;
		end;
	M_End:
		close;

	L_LowLvl:
		mes "I'm sorry but you do not meet the Base Level requirements to enter.  Please try a lower level room.";
		close;
	L_HiLvl:
		mes "I'm sorry but you exceed the Base Level requirements to enter.  Please try a higher level room.";
		close;
	L_Full:
		mes "[Fight Square Helper]";
		mes "I'm sorry but this arena is full.  Please choose another one to participate in....";
		goto M_Menu;
}
