prontera,146,172,6	script	Iris#bgshop	4_F_IRIS,{
mes .npc$;
mes("Do you have the battlefield badges?");
mes("I can exchange Bravery Badges and Valor Badges for reward items.");
next;		
callfunc "bgshop";

OnInit:
	.npc$ = "[ ^FF3355Battleground Exchange^000000 ]";
	end;
}
// Script Core
//============================================================
-	script	bg_shop	FAKE_NPC,{
function rAdd; function rChk; function rSlot; function rA_An;
OnInit:
	.npc$ = "[ ^FF3355Battleground Exchange^000000 ]";
	freeloop(1);

// -----------------------------------------------------------
//  Basic shop settings.
// -----------------------------------------------------------

	set .Announce,0;	// Announce quest completion? (1: yes / 0: no)
	set .ShowSlot,1;	// Show item slots? (2: all equipment / 1: if slots > 0 / 0: never)
	set .ShowID,1;  	// Show item IDs? (1: yes / 0: no)
	set .ShowZeny,1;	// Show Zeny cost, if any? (1: yes / 0: no)
	set .MaxStack,1;	// Max number of quest items purchased at one time.
	setarray .bgshops$[1],"Weapons","Garmets/Shoes","Armors","Accessories","Usables";

// rAdd(category,ItemID,Qty,Cost,ItemID);

//Dagger/OneSword/TwoSword/TwoSpear
rAdd(1,13036,1,100,0,7828,100);
rAdd(1,13037,1,100,0,7829,100);
rAdd(1,13411,1,100,0,7828,100);
rAdd(1,13410,1,100,0,7829,100);
rAdd(1,1183,1,100,0,7828,100);
rAdd(1,1184,1,100,0,7829,100);
rAdd(1,1425,1,100,0,7828,100);
rAdd(1,1482,1,100,0,7829,100);
//Staff/Mace/TwoAxe/Shuriken
rAdd(1,1632,1,100,0,7828,100);
rAdd(1,1633,1,100,0,7829,100);
rAdd(1,1634,1,100,0,7828,100);
rAdd(1,1635,1,100,0,7829,100);
rAdd(1,1543,1,100,0,7828,100);
rAdd(1,1542,1,100,0,7829,100);
rAdd(1,1380,1,100,0,7828,100);
rAdd(1,1379,1,100,0,7829,100);
rAdd(1,13305,1,100,0,7828,100);
rAdd(1,13306,1,100,0,7829,100);
//Bow/Katar/Music/Whip
rAdd(1,1739,1,100,0,7828,100);
rAdd(1,1738,1,100,0,7829,100);
rAdd(1,1279,1,100,0,7828,100);
rAdd(1,1280,1,100,0,7829,100);
rAdd(1,1924,1,100,0,7828,100);
rAdd(1,1923,1,100,0,7829,100);
rAdd(1,1978,1,100,0,7828,100);
rAdd(1,1977,1,100,0,7829,100);
//Book/Knuckle
rAdd(1,1574,1,100,0,7828,100);
rAdd(1,1575,1,100,0,7829,100);
rAdd(1,1824,1,100,0,7828,100);
rAdd(1,1823,1,100,0,7829,100);
//Revolver/Rifle/Gatling/Shotgun/Launcher
rAdd(1,13108,1,100,0,7828,100);
rAdd(1,13171,1,100,0,7829,100);
rAdd(1,13172,1,100,0,7828,100);
rAdd(1,13173,1,100,0,7829,100);
rAdd(1,13174,1,100,0,7829,100);

//Garments / Shoes
rAdd(2,2538,1,50,0);
rAdd(2,2539,1,50,0);
rAdd(2,2540,1,50,0);
rAdd(2,2435,1,50,0);
rAdd(2,2436,1,50,0);
rAdd(2,2437,1,50,0);

// Armors
rAdd(3,2376,1,80,0);
rAdd(3,2377,1,80,0);
rAdd(3,2378,1,80,0);
rAdd(3,2379,1,80,0);
rAdd(3,2380,1,80,0);
rAdd(3,2381,1,80,0);
rAdd(3,2382,1,80,0);

// Accessories
rAdd(4,2733,1,500,0);
rAdd(4,2720,1,500,0);
rAdd(4,2721,1,500,0);
rAdd(4,2722,1,500,0);
rAdd(4,2723,1,500,0);
rAdd(4,2724,1,500,0);
rAdd(4,2725,1,500,0);

// Consumables
rAdd(5,12269,1,10,0);
rAdd(5,12269,1,10,0);

rAdd(5,30065,1,2,0);
rAdd(5,30066,1,2,0);
rAdd(5,12271,1,10,0);
rAdd(5,12272,1,10,0);
rAdd(5,12273,1,10,0);

// -----------------------------------------------------------

	freeloop(0);
	set .menu$,"";
	for(set .@i,1; .@i<=getarraysize(.bgshops$); set .@i,.@i+1) {
		set .menu$, .menu$+.bgshops$[.@i]+":";
		npcshopdelitem "bgshop"+.@i,909;
	}
	end;

OnMenu:
	set .@size, getarraysize(@i);
	if (!.@size) set .@i, select(.menu$);
	else if (.@size == 1) set .@i, @i[0];
	else {
		for(set .@j,0; .@j<.@size; set .@j,.@j+1)
			set .@menu$, .@menu$+.bgshops$[@i[.@j]]+":";
		set .@i, @i[select(.@menu$)-1];
	}
	deletearray @i[0],getarraysize(@i);
	if (.bgshops$[.@i] == "") {
		message strcharinfo(PC_NAME),"An error has occurred.";
		end;
	}
	dispbottom "Select one item at a time.";
	callshop "bgshop"+.@i,1;
	npcshopattach "bgshop"+.@i;
	end;

OnBuyItem:
	disable_items();
	setarray .@q[0],@bought_nameid[0],((@bought_quantity[0] > .MaxStack)?.MaxStack:@bought_quantity[0]);
	copyarray .@q[3],getd(".r_"+.@q[0]+"[0]"),getarraysize(getd(".r_"+.@q[0]));
	set .@q[2],.@q[1]*.@q[3];
	if (!.@q[2] || .@q[2] > 30000) {
		message strcharinfo(PC_NAME),"You can't purchase that many "+getitemname(.@q[0])+".";
		end;
	}
//	mes .npc$;
//	mes "You are about to rent:";
//	mes "Item: ^0055FF"+((.@q[2] > 1)?.@q[2]+"x ":"")+rSlot(.@q[0])+"^000000";
//	mes "for ^0055FF7 Days.^000000";
//	next;
	setarray @qe[1], getiteminfo(.@q[0], ITEMINFO_LOC), getiteminfo(.@q[0], ITEMINFO_VIEWSPRITE);
	if (@qe[2] > 0 && ((@qe[1] & EQP_HEAD_LOW) || (@qe[1] & EQP_HEAD_TOP) || (@qe[1] & EQP_HEAD_MID) || (@qe[1] & EQP_COSTUME_HEAD_TOP) || (@qe[1] & EQP_COSTUME_HEAD_MID) || (@qe[1] & EQP_COSTUME_HEAD_LOW) || (@qe[1] & EQP_GARMENT) || (@qe[1] & EQP_COSTUME_GARMENT)))
		set .@preview,1;
	addtimer 1000, strnpcinfo(NPC_NAME)+"::OnEnd";
	while(1) {
		switch(select(" ~ Exchange ^0055FF"+ getitemname(.@q[0]) +"^000000", ((.@preview && !@qe[7])?" ~ Preview...": ""), " ~ ^777777Cancel^000000")) {
		case 1:
			if (!checkweight(.@q[0],.@q[2])) {
				mes .npc$;
				mes "^FF0000You need "+(((.@q[2]*getiteminfo(.@q[0],6))+Weight-MaxWeight)/10)+" additional weight capacity to complete this exchange.^000000";
				close();
			}
			if (.@q[6] == 0 ) {
				mes .npc$;	
				mesf("You can exchange for this item with ^FF0000%d %s or %d %s^000000.", (.@q[4]*.@q[1]), getitemname(7828), (.@q[4]*.@q[1]), getitemname(7829));
				mes("Would you like to exchange?");
				next;
				switch(select("Do not exchange", "Exchange")) {
				case 1:
					mes .npc$;
					mes("Do you need more time to check the items?");
					break;
				case 2:
					mes .npc$;
					mes("Which Badge do you want to exchange?");
					mesf("You need ^3131FF%d Badges^000000 to exchange.", .@q[4]*.@q[1]);
					next;
					if ( .@q[6] < 12269 || .@q[6] > 12273 ) {
						mes .npc$;
						mes("Remember, Battleground Reward Items are ^FF0000Character Bound^000000. Are you sure you want this item?");
						next;
					}
					.@j = select("Bravery Badge", "Valor Badge", "Cancel");
					mes .npc$;
					if (.@j == 3) {
						mes("You cancelled the exchange.");
						break;
					}
					.@cost = ((.@j==1)?7828:7829);
					if (countitem(.@cost) >= (.@q[4]*.@q[1])) {
						mes("Thank you for exchanging.");
						delitem .@cost, (.@q[4]*.@q[1]);
						getitem .@q[0],1;
					}
					else mesf("You do not have enough %ss.", getitemname(.@cost));
					break;
				}
				close;
			}
			if(countitem(.@q[6]) < (.@q[4]*.@q[1])){
				mes .npc$;
				mes "You're ^0055FF"+getitemname(.@q[6])+"^000000 is not suffecient to buy the item.";
				close();
			}
			delitem .@q[6],(.@q[4]*.@q[1]);
			getitem .@q[0],1;
			close();
		case 2:
			setarray @qe[3], getlook(LOOK_HEAD_BOTTOM), getlook(LOOK_HEAD_TOP), getlook(LOOK_HEAD_MID), getlook(LOOK_ROBE), 1;
			if ((@qe[1] & 1) || (@qe[1] & 4096)) changelook LOOK_HEAD_BOTTOM, @qe[2];
			else if ((@qe[1] & 256) || (@qe[1] & 1024)) changelook LOOK_HEAD_TOP, @qe[2];
			else if ((@qe[1] & 512) || (@qe[1] & 2048)) changelook LOOK_HEAD_MID, @qe[2];
			else if ((@qe[1] & 4) || (@qe[1] & 8192)) changelook LOOK_ROBE, @qe[2];
			break;
		case 3:
			close();
		}
	}				

OnEnd:
	if (@qe[7]) {
		changelook LOOK_HEAD_BOTTOM, @qe[3];
		changelook LOOK_HEAD_TOP, @qe[4];
		changelook LOOK_HEAD_MID, @qe[5];
		changelook LOOK_ROBE, @qe[6];
	}
	deletearray @qe[0],8;
	end;

function rAdd {
	if (getitemname(getarg(1)) == "null") {
		debugmes "Quest reward #"+getarg(1)+" invalid (skipped).";
		return;
	}
	setarray .@j[0],getarg(2),getarg(3),getarg(4);
	for(set .@i,5; .@i<getargcount(); set .@i,.@i+2) {
		if (getitemname(getarg(.@i)) == "null") {
			debugmes "Quest requirement #"+getarg(.@i)+" invalid (skipped).";
			return;
		} else
			setarray .@j[.@i-2],getarg(.@i),getarg(.@i+1);
	}
	copyarray getd(".r_"+getarg(1)+"[0]"),.@j[0],getarraysize(.@j);
	npcshopadditem "bgshop"+getarg(0),getarg(1),((.ShowZeny)?getarg(3):0);
	return;
}

function rChk {
	if (getarg(0) < getarg(1)) {
		set @qe[0],1;
		return "^FF0000";
	} else
		return "^00FF00";
}

function rSlot {
	set .@s$,getitemname(getarg(0));
	switch(.rShowSlot) {
		case 1: if (!getitemslots(getarg(0))) return .@s$;
		case 2: if (getiteminfo(getarg(0),2) == 4 || getiteminfo(getarg(0),2) == 5) return .@s$+" ["+getitemslots(getarg(0))+"]";
		default: return .@s$;
	}
}

function rA_An {
	setarray .@A$[0],"a","e","i","o","u";
	set .@B$, "_"+getarg(0);
	for(set .@i,0; .@i<5; set .@i,.@i+1)
		if (compare(.@B$,"_"+.@A$[.@i])) return "an "+getarg(0);
	return "a "+getarg(0);
}
}


function	script	bgshop	{
	deletearray @i[0],getarraysize(@i);
	for(set .@i,0; .@i<getargcount(); set .@i,.@i+1)
		set @i[.@i],getarg(.@i);
	doevent "bg_shop::OnMenu";
	end;
}

// Dummy shop data -- copy as needed.
//============================================================
-	shop	bgshop1	FAKE_NPC,909:-1
-	shop	bgshop2	FAKE_NPC,909:-1
-	shop	bgshop3	FAKE_NPC,909:-1
-	shop	bgshop4	FAKE_NPC,909:-1
-	shop	bgshop5	FAKE_NPC,909:-1
