//===== eAthena Script =======================================
//= Magazine Dealer Kenny
//===== By: ==================================================
//= eAthena dev team
//===== Current Version: =====================================
//= 1.2a
//===== Compatible With: =====================================
//= eAthena 1.0+
//===== Description: =========================================
//= Turns bullets/spheres into packs/casings.
//===== Additional Comments: =================================
//= 1.0 First version. [SinSloth]
//= 1.1 Optimized version - Reduced to only one function [SinSloth]
//= 1.2 Optimized^2, corrected npc's name [ultramage]
//= 1.2a Optimized. Please, ommit extra NPC names [Lupus]
//============================================================

que_ng,187,149,3	script	Magazine Dealer Kenny	83,{

	mes "[Kenny]";	
	mes "I am the Casing Dealer, Kenny!";
	if(BaseJob != Job_Gunslinger) {
		mes "I'm here to package the Shells";
		mes "and Bullets for Gunslingers.";
		next;
		mes "[Kenny]";
		mes "But you don't look like a";
		mes "Gunslinger to me. I'm afraid";
		mes "that I must ask you to leave";
		mes "after you're done looking around.";
		close;
	}
	mes "If your bullets are getting";
	mes "too heavy, come to me!";
	next;
	mes "[Kenny]";
	mes "I can make you Casings and Packs,";
	mes "which will let you carry the";
	mes "Spheres at a lower weight!";
	mes "Come on! Take a look!";
	next;
	switch(select("Lightning Sphere Pack","Blind Sphere Pack","Poison Sphere Pack","Freezing Sphere Pack","Flare Sphere Pack","Bullet Casing","Shell of Blood Casing","Silver Bullet Casing","Cancel")) {
	case 1: callfunc "Func_Casing",13204,12144; break;
	case 2: callfunc "Func_Casing",13206,12145; break;
	case 3: callfunc "Func_Casing",13205,12146; break;
	case 4: callfunc "Func_Casing",13207,12147; break;
	case 5: callfunc "Func_Casing",13203,12148; break;
	case 6: callfunc "Func_Casing",13200,12149; break;
	case 7: callfunc "Func_Casing",13202,12150; break;
	case 8: callfunc "Func_Casing",13201,12151; break;
	default:
		mes "[Kenny]";
		mes "Alright. If there's";
		mes "something else I can help";
		mes "you with, please tell me.";
		close;
	}
	close;
}

function	script		Func_Casing	{

	mes "[Kenny]";
	mes "Please input the amount you want.";
	next;
	mes "[Kenny]";
	mes "" +getitemname(getarg(1))+ " will";
	if(getarg(0) == 13202) 
		mes "cost 500 Shells of Blood";
	else
		mes "cost 500 " +getitemname(getarg(0))+ "s";
	mes "and 500 zeny each.";
	next;
	mes "[Kenny]";
	mes "You can trade a maximum of 50.";
	mes "Input 0 if you want to cancel.";
	next;
	input .@amount;
	mes "[Kenny]";
	if(.@amount < 1) {
		mes "Alright. If there's";
		mes "something else I can help";
		mes "you with, please tell me.";
		close;
	}
	if(.@amount > 50)	{
		mes "You've exceeded the limit!";
		mes "Try again next time?";
		close;
	}
	//Weight checking
	if(checkweight(getarg(1), .@amount) != 1)	{
		mes "You are overweight.";
		mes "Please clear your inventory.";
		close;
	}
	
	//Materials checking
	if(countitem(getarg(0)) < .@amount * 500) {
		mes "Huh......";
		mes "You don't have enough";
		mes "materials to trade for";
		mes "the number of items you";
		mes "want. Please come with the";
		mes "correct amount of items.";
		close;
	}
	
	//Zeny checking
	if(Zeny < .@amount * 500) {
		mes "Erm... You don't have enough money.";
		mes "The fee is 500 zeny";
		mes "Check your zeny and come again.";
		close;
	}

	mes "Ah very well!";
	mes "The number is confirmed!";
	if(getarg(1) < 12149)
		mes "I'll get you the Packs right away.";
	else
		mes "I'll get you the Casings right away.";
	set Zeny, Zeny - .@amount * 500;
	delitem getarg(0), .@amount * 500;
	getitem getarg(1), .@amount;
	close;
}