yuno_fild03,36,135,0	script	Dungeon Access	4_M_CRU_SOLD,{

	.@party_id = getcharid(CHAR_ID_PARTY);
	.@p_name$ = getpartyname(.@party_id);
	.@md_name$ = _("Magma Dungeon");

	if (!instance_check_party(.@party_id, 2) && !getgmlevel() ) {
		mes("[ ^28bf00Exclussive Dungeon^000000 ]");
		mes("Make or join a party with more than 1 member and try again.");
		close();
	}
	if (getcharid(CHAR_ID_CHAR) == getpartyleader(.@party_id, 2)) {
		mes("[ ^28bf00Exclussive Dungeon^000000 ]");
		mes("Confirmed the party has been made.");
		next();
		switch (select(
			((getgmlevel() < 99)?":":"^FF0000GM Menu^000000:")+
			((has_instance("1@magdun") != "")?":":"^28bf00Rent Dungeon^000000 - ^FF0000"+callfunc("F_InsertComma",.rental)+"^000000z:")+
			((has_instance("1@magdun") == "")?":":"^28bf00Enter the Dungeon^000000:")+ 
			"Return to Prontera:"+ 
			"Cancel"
		)) {
		case 1:
			while(1) {
				switch(select(
					((getgmlevel() == 99)?"Price [ ^28bf00"+.rental+"^000000 ]:":":")+
					"- ^777777Close^000000"
				)) {
				case 1: 
					mes("[ ^28bf00Exclussive Dungeon^000000 ]");
					input .rental;
					break;	
				case 2:
					close();
				}
			}
			close();
		case 2:
			if (Zeny < .rental) {
				mes("[ ^28bf00Exclussive Dungeon^000000 ]");
				mes("Opppss. You don't have enought zeny.");
				close();
			}
			.@instance = instance_create(.@md_name$, .@party_id);
			if (.@instance < 0) {
				mes("[ ^28bf00Exclussive Dungeon^000000 ]");
				mesf("Party Name: %s", .@p_name$);
				mesf("Party Leader: %s", strcharinfo(PC_NAME));
				mesf("^0000ff%s ^000000- Reservation Failed!", .@md_name$);
				close();
			}
			Zeny -= .rental;
			mes("[ ^28bf00Exclussive Dungeon^000000 ]");
			mesf("^0000ff%s^000000 - Try to reserve", .@md_name$);
			mes("After making a reservation, you have to me again and select the menu 'Enter the Dungeon' to enter the dungeon.");
			for (.@i = 1; .@i <= 1; ++.@i) {
				if (instance_attachmap(.@i + "@magdun", .@instance) == "") {
					mesf("^0000ff%s ^000000- Reservation Failed!", .@md_name$);
					instance_destroy(.@instance);
					close();
				}
			}
			instance_set_timeout(14400, 300, .@instance);
			instance_init(.@instance);
			close();
		case 3:
			callsub(L_Enter, 0, 1, .@md_name$, .@p_name$);
		case 4:
			mes("[ ^28bf00Exclussive Dungeon^000000 ]");	
			mes("I will move you to Prontera.");
			close2();
			warp("prontera", 140, 179);
			end;
		case 5:
			close();
		}
	}
	mes("[ ^28bf00Exclussive Dungeon^000000 ]");
	mes("If your party has rented an exclussive dungeon, you can enter it.");
	next();
	switch (select("Enter the Dungeon", "Return to Prontera", "Cancel")) {
	case 1:
		callsub(L_Enter, 1, 1, .@md_name$, .@p_name$);
	case 2:
		mes("[ ^28bf00Exclussive Dungeon^000000 ]");
		mes("I will move you to Alberta.");
		close2();
		warp("prontera", 140, 179);
		end;
	case 3:
		end;
	}
	end;
L_Enter:
	if (has_instance("1@magdun") == "") {
		mes("[ ^28bf00Exclussive Dungeon^000000 ]");
		mesf("The %s does not exist.", getarg(2));
		mesf("The party leader did not rent an %s yet.", getarg(2));
		close();
	} else {
		mapannounce("yuno_fild03", sprintf(_$("%s of the party, %s, is entering %s"), strcharinfo(PC_NAME), getarg(3), getarg(2)), bc_map, C_SPRINGGREEN, FW_NORMAL, 12);
		warp("1@magdun", 49, 49);
		if (getarg(0) == 0)
			close();
		else
			end;
	}
	end;
OnInit:
	.rental = 300000;
	end;
}

//== Core Functions ========================================
1@magdun,4,2,0	script	ins_magdun	FAKE_NPC,{
end;

OnInstanceInit:
	.@map$ = instance_mapname("1@magdun");
	monster(.@map$, 0, 0, _("Blazer"), BLAZZER, 10, instance_npcname("ins_magdun")+"::On1367Dead");
	monster(.@map$, 0, 0, _("Nightmare Terror"), NIGHTMARE_TERROR, 15, instance_npcname("ins_magdun")+"::On1379Dead");
	monster(.@map$, 0, 0, _("Deleter"), DELETER, 5, instance_npcname("ins_magdun")+"::On1384Dead");
	monster(.@map$, 0, 0, _("Deleter"), DELETER_, 5, instance_npcname("ins_magdun")+"::On1385Dead");
	monster(.@map$, 0, 0, _("Gig"), GIG, 10, instance_npcname("ins_magdun")+"::On1387Dead");
	monster(.@map$, 0, 0, _("Diabolic"), DIABOLIC, 5, instance_npcname("ins_magdun")+"::On1382Dead");
	end;

On1367Dead:
	.@map$ = instance_mapname("1@magdun");
	monster(.@map$, 0, 0, _("Blazer"), BLAZZER, 1, instance_npcname("ins_magdun")+"::On1367Dead");
	end;
On1379Dead:
	.@map$ = instance_mapname("1@magdun");
	monster(.@map$, 0, 0, _("Nightmare Terror"), NIGHTMARE_TERROR, 1, instance_npcname("ins_magdun")+"::On1379Dead");
	end;
On1384Dead:
	.@map$ = instance_mapname("1@magdun");
	monster(.@map$, 0, 0, _("Deleter"), DELETER, 1, instance_npcname("ins_magdun")+"::On1384Dead");
	end;
On1385Dead:
	.@map$ = instance_mapname("1@magdun");
	monster(.@map$, 0, 0, _("Deleter"), DELETER_, 1, instance_npcname("ins_magdun")+"::On1385Dead");
	end;
On1387Dead:
	.@map$ = instance_mapname("1@magdun");
	monster(.@map$, 0, 0, _("Gig"), GIG, 1, instance_npcname("ins_magdun")+"::On1387Dead");
	end;
On1382Dead:
	.@map$ = instance_mapname("1@magdun");
	monster(.@map$, 0, 0, _("Diabolic"), DIABOLIC, 1, instance_npcname("ins_magdun")+"::On1382Dead");
	end;
}


