prt_in,290,134,4	script	Beginner Crafting	4_M_4THPRIN1,{
	callsub(StartTalking);
	end;
	
OnInit:
	/**
	 * General Configuration
	 */
	/* Chance of the enhancement process to fail. (0 - 99 in percent) */
	.chance_of_failure = 50;
	/* Delete the item on failure? (true/false) */
	.delete_on_failure = true;
	/* Required amount of zeny for a try. */
	.zeny_requirement = 500000;
	/* Minimum amount of the bonus value. 
	 * For negative effects or certain bonuses that require negative values
	 * Maximum possible value is -INT16_MAX)
	 */
	.minimum_bonus_amount = 1; // usually used with delay bonus options, although not provided in the script.
	/* Maximum amount of the bonus value. 
	 * Maximum possible value is INT16_MAX */
	.maximum_bonus_amount = 3;
	/* Disable selection of bonus value (true/false) */
	.enable_random_bonus = true;
	.enable_random_option = true;
	.debug = false;
	/* Allowed Armors */
	set .armors$,
		"2308,2310,2311,2313,2315,2317,2318,2319,2320,"+
		"2322,2324,2326,2327,2331,2333,2334,2336,"+
		"2337,2338,2340,2342,2343,2344,2347,"+
		"2349,2351,2353,2354,2356,2357,2364,2365,2366,"+
		"2367,2371,2374,2375,2386,2387,2388,2389,2390,"+
		"2391,2399";

	/* Item Option Descriptions */
	setarray(.options$[1],
		"MaxHP",
		"MaxSP",
 		"Str",
		"Agi",
		"Vit",
		"Int",
		"Luk",
		"MaxHP %", 
		"MaxSP %", 
		"HP regen", 
		"SP regen", 
		"Attack Power %", 
		"Magic Power %", 
		"Attack Speed", 
		"Attack Speed %",
		"Attack",
		"Hit",
		"Magic Attack",
		"Def",
		"Mdef",
		"Flee",
		"Perfect dodge",
		"Critical"
	);
	/* Item Option Constants */
	setarray(.option_constants[1],
		VAR_MAXHPAMOUNT,
		VAR_MAXSPAMOUNT,

		VAR_STRAMOUNT, 
		VAR_AGIAMOUNT, 
		VAR_VITAMOUNT, 
		VAR_INTAMOUNT, 
		VAR_DEXAMOUNT, 
		VAR_LUKAMOUNT,

		VAR_MAXHPPERCENT, 
		VAR_MAXSPPERCENT, 
		VAR_HPACCELERATION, 
		VAR_SPACCELERATION, 
		VAR_ATKPERCENT, 
		VAR_MAGICATKPERCENT, 
		VAR_PLUSASPD,
		VAR_PLUSASPDPERCENT,
		VAR_ATTPOWER,
		VAR_HITSUCCESSVALUE,
		VAR_ATTMPOWER,
		VAR_ITEMDEFPOWER,
		VAR_MDEFPOWER,
		VAR_AVOIDSUCCESSVALUE,
		VAR_PLUSAVOIDSUCCESSVALUE,
		VAR_CRITICALSUCCESSVALUE
	);
	end;
	
StartTalking:
	.@name$ = _("[ ^990099Beginner Crafting^000000 ]");
	disable_items();
	mes(.@name$);
	mesf("Hey there %s", strcharinfo(PC_NAME));
	mes("I am a beginner craftsman and I can only enhance the ^0000ff1st Equipment Options^000000.  I can enhance your armor ^ff0000up to +3^000000 on ^0000ffStr^000000, ^00cc00Agi^000000, ^ff9900Vit^000000, ^ff0055Int^000000 or ^ff0000Luk^000000.  Remember the stats and value are purely random.");
	next();
	if (.enable_random_bonus) {
		mes(.@name$);
		mes("Armor bonuses are added randomly in a slot!");
		mes("So if you wind up with a low amount of bonus, don't hesitate to override the slot.");
		next();
	}
	mes(.@name$);
	mes("Would you like me to add extra stats to your armor?");
	next();
	if (select("Of course!", "Meh, not right now.") == 2) {
		mes(.@name$);
		mes("Alright then, catch you later.");
		close();
	}

	// Check if it's worn.
	if (!getequipisequiped(EQI_ARMOR)) {
		mes(.@name$);
		mes("Brah, your armor ain't equipped.");
		close();
	// Check if it allows options
	} else if (!getequipisenableopt(EQI_ARMOR) || !compare(.armors$,""+getequipid(EQI_ARMOR)) ) {
		mes(.@name$);
		mes("Brah, this armor can't have options.");
		close();
	// Check if armor is identified.
	} else if (!getequipisidentify(EQI_ARMOR)) {
		mes(.@name$);
		mes("Brah, this armor ain't identified.");
		close();
	}

	// Present a list of currently infused options.
	do {
		.@menu$ = "";
		.@used = false;
		// Build the menu of current options.
		for (.@i = 1; .@i <= 1; ++.@i) {
			// call getequipoption(<equip_index>, <type>, <slot>);
			// if the return is <0, it's a script error.
			// if the return is 0, the slot is empty.
			// if the return is >0, the slot is unavailable.
			.@opt = getequipoption(EQI_ARMOR, .@i, IT_OPT_INDEX);
			if (.@opt > 0)
				.@menu$ += "^990000Slot #^000000"+.@i+" "+.options$[.@opt - 1 ] + ":";
			else
				.@menu$ += "^990000Slot #^000000"+.@i+" ^999999Empty^000000" + ":";
		}
		// Option Slot is the actual option slot 0-MAX_ITEM_OPTIONS (@see mmo.h)
		.@option_slot = select(.@menu$);
		// Check for used slot and request user action if found.
		if (getequipoption(EQI_ARMOR, .@option_slot, IT_OPT_INDEX) > 0) {
			mes(.@name$);
			mes("This slot is already used up!");
			if (select("^990000Override the slot.^000000", "Choose again.") == 2)
				.@used = true;
			next();
		}
	} while (.@used); // loop if the slot is not to be overridden
	.@option_variable = rand(3,7);
	.@value = rand(.minimum_bonus_amount,.maximum_bonus_amount);
	next();

	if (.debug) {
		mes "Option Variable: "+(.@option_variable);
		mes "Value: "+.@value;
	}



	// If there's a chance of failure, inform the user.
	if (.chance_of_failure) {
		mes(.@name$);
		mes("Alright so,");
		mes("I'll have you know...");
		mesf("There's a ^990000%d%% chance of failure^000000.", .chance_of_failure);
		mes("Because, well... I didn't go to school.");
		next();
		mes(.@name$);
		if (.delete_on_failure) {
			if(getitemslots(getequipid(EQI_ARMOR)) > 0) {
				mes("If I fail, your ^009900"+getitemname(getequipid(EQI_ARMOR))+" [1]^000000 will break and it ^990000will be destroyed^000000!");
			} else {
				mes("If I fail, your ^009900"+getitemname(getequipid(EQI_ARMOR))+"^000000 will break and it ^990000will be destroyed^000000!");
			}
		}
		mes("Are you still ready to go forward with this?");
		next();
		if (select("Fo shizzle.", "Hells naw, go back to school.") == 2) {
			mes(.@name$);
			mes("Geez, you don't have to be so harsh about it.");
			close();
		}
		next();
	}
	
	// If there's a Zeny Requirement, perform the usual.
	if (.zeny_requirement > 0) {
		mes(.@name$);
		mesf("You also have to pay ^990000%d Zeny^000000.", .zeny_requirement);
		next();
		if (select("Of course!", "No way!") == 2) {
			mes(.@name$);
			mes("Well, see you around then...");
			close();
		}
		if (Zeny < .zeny_requirement) {
			mes(.@name$);
			mes("You don't have enough ^990000Zeny^000000!");
			close();
		}
		Zeny -= .zeny_requirement;
	}
	
	// Check if there's a chance of failure, set and roll the dice.
	if (.chance_of_failure && rand(100) <= .chance_of_failure) {
		mes(.@name$);
		mes("^990000I failed!^000000");
		mes("Guess I should go back to school.");
		// Delete the item if flagged.
		if (.delete_on_failure)
			failedrefitem(EQI_ARMOR); // Simulate failed refinement of the item and delete.
	} else {
		// Set the Item Option bonuses in the slot see db/item_options.conf for more info.
		setequipoption(EQI_ARMOR, .@option_slot, .option_constants[.@option_variable + 1], .@value);
		mes(.@name$);
		mes("^009900Praise Jesus^000000");
		mes("I have added an option to your item.");
		mes("My skills are flawless!");
	}
	next();
	mes(.@name$);
	mes("See you around!");
	close();
}

prt_in,283,122,0	warp	itemopt#1	1,1,prontera,135,164
prontera,134,160,0	warp	itemopt#2	1,1,prt_in,283,127