//@unloadnpc DeathMatch
//@unloadnpc Healer#deathmatch
//@unloadnpc dmwarp
//@loadnpc npc/amatsu/deathmatch.txt


-	script	DeathMatch	FAKE_NPC,{

OnPCDieEvent:
	if ( strcharinfo(3) == "guild_vs1" ) {
		message strcharinfo(0), "You will respawn in 3 seconds";
		sleep2 3000;
		warp "guild_vs1", 0,0;
		percentheal 100,100;
	
		skilleffect AL_BLESSING,0;
		sc_start SC_BLESSING,240000,10;

		skilleffect AL_INCAGI,0;
		sc_start SC_INC_AGI,240000,10;
		heal -15,0;
		sleep2 1000;
	}
	end;

OnPCLoginEvent:
	if (deathmatch == 1) {
		set deathmatch, 0;
		sc_end SC_BLESSING;
		sc_end SC_INC_AGI;
		set Hp,dhp;
		set Sp,dsp;
		warp dlastmap$, dlastx, dlasty;
	}
	end;

OnInit:
	pvpon "guild_vs1";
	end;
}

guild_vs1,7,49,2	script	dmwarp	WARPNPC,1,1,{
	callfunc "dmexit";
	end;
}

guild_vs1,49,92,0	duplicate(dmwarp)	dmwarp#2	WARPNPC,1,1
guild_vs1,92,50,2	duplicate(dmwarp)	dmwarp#3	WARPNPC,1,1
guild_vs1,50,7,2	duplicate(dmwarp)	dmwarp#4	WARPNPC,1,1


function	script	dmexit	{
	query_sql("REPLACE INTO `pvp_rank` (`char_id`, `account_id`, `char`, `kill`, `death`, `kdr`, `killingstreak`, `multikill`,  `nemesiskill`, `feedcount`,`killingspree`, `dominating`, `megakill`, `unstoppable`, `wickedsick`, `monsterkill`, `godlike`, `beyondgodlike`, `doublekill`, `triplekill`, `ultrakill`, `rampage`, `ownage`) VALUES ("+getcharid(0)+","+getcharid(3)+", '"+strcharinfo(PC_NAME)+"', "+Kill+", "+Death+", '"+callfunc("KDR_Calc", Kill, ( !Death ? 1 : Death ))+"', "+KillingStreak+", "+MultiKill+",  "+NemesisKill+", "+FeedCount+", "+KillingSpree+", "+Dominating+", "+MegaKill+", "+Unstoppable+", "+WickedSick+", "+MonsterKill+", "+Godlike+", "+BeyondGodlike+", "+DoubleKill+", "+TripleKill+", "+UltraKill+", "+Rampage+", "+Ownage+")");
	set deathmatch,0;
	sc_end SC_BLESSING;
	sc_end SC_INC_AGI;
	set Hp,dhp;
	set Sp,dsp;
	warp dlastmap$, dlastx, dlasty;
	end;
}


/* Healer */

guild_vs1,50,50,2	script	Healer#deathmatch	4_F_SON,{
	.@Delay = 10;	// Heal delay, in seconds
	if (@HD > gettimetick(2)) end;
	percentheal 100,100;
	skilleffect AL_BLESSING,0;
	sc_start SC_BLESSING,240000,10;
	skilleffect AL_INCAGI,0;
	sc_start SC_INC_AGI,240000,10;
	heal -15,0;
	if (.@Delay) @HD = gettimetick(2)+.@Delay;
	end;
}

/* NPC */

morocc,149,105,4	script	pvp#mor	4_M_KY_HEAD,{
OnCommand:
	getmapxy(.@map$, @x, @y, 0);
	if (BaseLevel < 90){
		mes "[ PvP Gatekeeper ]";
		mes "Sorry, only LvL 90+ may enter the arena.";
		close;
	}
	if (getmapflag(strcharinfo(3), mf_nowarp) || getmapflag(strcharinfo(3), mf_noteleport) ) {
		mes "[ PvP Gatekeeper ]";
		mes "Sorry, you can't join deathmatch from this map";
		close;
	}
	if (getmapflag(strcharinfo(3), mf_pvp)) {
		mes "[ PvP Gatekeeper ]";
		mes "Sorry, you can't use that command at this map";
		close;
	}
	if (.deadlock && !Hp) {
		mes "[ PvP Gatekeeper ]";
		mes "You may not use event when you are dead.";
		close;
	}
	if (estatus){
		mes "[ PvP Gatekeeper ]";
		mes "You are currently joining an event.  Leave the event before joining the DeathMatch!";
		close;
	}
	mes "[ PvP Gatekeeper ]";
	mes "Please select PvP Room:";
	next;
	if(select("Deathmatch","Yoyo Mode - Izlude") == 1 ){
		specialeffect(EF_ANGEL3, AREA, playerattached());
		if( strcharinfo(PC_MAP) != "morocc") {
			mes "Please wait . . . . .";
			progressbar "ffffff",3;
		}
		set dlastmap$,.@map$;
		set dlastx,@x;
		set dlasty,@y;
		set deathmatch,1;
		set dhp,Hp;
		set dsp,Sp;
		chanmsg("#battle",""+strcharinfo(0)+" has entered DeathMatch Arena ("+(1+getmapusers("guild_vs1"))+" users). Type @pvp to join the fun.");
		warp "guild_vs1",0,0;
		percentheal 100,100;
		sleep2 1000;
		skilleffect AL_BLESSING,0;
		sc_start SC_BLESSING,240000,10;
		skilleffect AL_INCAGI,0;
		sc_start SC_INC_AGI,240000,10;
		heal -15,0;
		sleep2 1000;
		end;
	}
	specialeffect(EF_ANGEL3, AREA, playerattached());
	if(strcharinfo(PC_MAP) != "morocc") {
		mes "Please wait . . . . .";
		progressbar "ffffff",3;
	}
	chanmsg("#battle",""+strcharinfo(0)+" has entered PvP Izlude ("+(1+getmapusers("pvp_y_8-2"))+" users). Type @pvp to join the fun.");
	progressbar "ffffff",3;
	warp "pvp_y_8-2",0,0;	 
	end;
OnInit:
	delwaitingroom;
	waitingroom "PVP Arena",0;	
	bindatcmd "pvp","pvp#mor::OnCommand",0,99;
	end;
}


guild_vs1	mapflag	nocommand	2
guild_vs1	mapflag	zone	DeathMatch
guild_vs1	mapflag	nobranch
guild_vs1	mapflag	nomemo
guild_vs1	mapflag	noteleport
guild_vs1	mapflag	nosave
guild_vs1	mapflag	novending
guild_vs1	mapflag	nowarp
guild_vs1	mapflag	nobranch
guild_vs1	mapflag	partylock

