function	script	getBookRequirements	{
	switch( handicrafting_skill ) {
		case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7: case 8: case 9: .@book = 1553; break;
		case 10: case 11: case 12: case 13: case 14: case 15: case 16: case 17: case 18: case 19: .@book = 1556; break; 
		case 20: case 21: case 22: case 23: case 24: case 25: case 26: case 27: case 28: case 29: .@book = 11037; break; 
		default: .@book = 11040; break;
	}
	return countitem( .@book ) ? 1 : 0;
}
einbech,51,36,3	script	Smelting Furnace	63,{
	mes .npc$;
	mes "Hello " + strcharinfo( 0 ) + ", What item do you want to dismantle?";
	next;
	for ( .@i = 0; .@i < getarraysize( .items ); .@i++ ) {
		.@menu$ += "- ";
		.@menu$ += getitemname( .items[ .@i ] );
		.@menu$ += ":";
	}
	.@s = select( .@menu$ ) - 1;
	if ( !countitem( .items[ .@s ] ) ) {
		mes .npc$;
		mes "Seems like i cannot find any ^000099" + getitemname( .items[ .@s ] ) + "^000000 on your inventory";
		close;
	}
	switch ( .@s ) {
		case 0: .@lumber_id = 1019; break;
		case 1: .@lumber_id = 1066; break;
		case 2: .@lumber_id = 1067; break;
		case 3: .@lumber_id = 1068; break;
		case 4: .@lumber_id = 1019; break;
		default: break;
	}
	.@chance = rand( 1, 10 ); // random from 1% to 10% chance to get 2x basic ingredients of the crafted item
	mes .npc$;
	mes "Dismantling ^000099" + getitemname( .items[ .@s ] ) + "^000000 will have a chance (" + .@chance + "%) to get the double amount of basic ingredients of this crafted item.";
	next;
	mes .npc$;
	mes "So! Are you sure you want to dismantle ^000099" + getitemname( .items[ .@s ] ) + "^000000?";
	next;
	if ( select( "Yes:No" ) - 1 ) end;
	mes .npc$;
	mes "There you go! Enjoy!";
	delitem .items[ .@s ], 1;
	getitem .@lumber_id, ( rand( 100 ) < .@chance ) ? 12 : 6;
	close;
	OnInit:
		.npc$ = "[ ^000099" + strnpcinfo( 1 ) + "^000000 ]";
		setarray .items[ 0 ], 1984, 1913, 1701, 11040, 2003; // item id of equipment to be dismantled
		end;
}
einbech,54,43,3	script	Metalworking Furnace	63,{
	mes .npc$;
	mes "What can i do for you?";
	next;
	switch( select( "- Work Order Crafting:- Book Crafting:- Equipment Crafting:- Nothing" ) ) {
		case 1: if ( !callfunc( "getBookRequirements" ) ) {
					mes .npc$;
					mes "You don't have the corresponding handicrafting guide. Please check below the handicrafting guide you need.";
					for ( .@i = 0; .@i < getarraysize( .handicrafting_guide ); .@i++ ) 
						mes "[Lvl : " + .handicrafting_guide_level[ .@i ] + "] - " + getitemname( .handicrafting_guide[ .@i ] );
					break;
				}
				if ( work_order_done ) {
					mes .npc$;
					mes "Seems like you have a pending work order that is still not claimed. Please see Handicrafting Master to claim the pending work order.";
					break;
				}
				if ( handicrafting_skill == 40 ) {
					mes .npc$;
					mes "You cannot take any work orders anymore. You handicrafting skill is already at max";
					break;
				}
				mes .npc$;
				mes "Your handicrafting skill level is " + handicrafting_skill + " so i would only allow the following items to be crafted";
				next;
				switch( handicrafting_skill ) {
					case 0: case 1: case 2: case 3: case 4: 
						.@craft_item = 1019;
						.@denarius_earned = 1;
						setarray .@ingredients[ 0 ], 902, 50, 1061, 30; // item_id, item_amount
						break;
					case 5: case 6: case 7: case 8: case 9:
						.@craft_item = 1066;
						.@denarius_earned = 2;
						setarray .@ingredients[ 0 ], 902, 50, 1061, 30; // item_id, item_amount
						break;
					case 10: case 11: case 12: case 13: case 14: 
						.@craft_item = 1067;
						.@denarius_earned = 3;
						setarray .@ingredients[ 0 ], 902, 50, 1061, 30; // item_id, item_amount
						break;
					case 15: case 16: case 17: case 18: case 19:
						.@craft_item = 1068;
						.@denarius_earned = 4;
						setarray .@ingredients[ 0 ], 902, 50, 1061, 30; // item_id, item_amount
						break;
					case 20: case 21: case 22: case 23: case 24: 
						.@craft_item = 1019;
						.@denarius_earned = 5;
						setarray .@ingredients[ 0 ], 902, 50, 1061, 30; // item_id, item_amount
						break;
					case 25: case 26: case 27: case 28: case 29:
						.@craft_item = 1066;
						.@denarius_earned = 6;
						setarray .@ingredients[ 0 ], 902, 50, 1061, 30; // item_id, item_amount
						break;
					case 30: case 31: case 32: case 33: case 34:
						.@craft_item = 1067;
						.@denarius_earned = 7;
						setarray .@ingredients[ 0 ], 902, 50, 1061, 30; // item_id, item_amount
						break;
					case 35: case 36: case 37: case 38: case 39: case 40:
						.@craft_item = 1068;
						.@denarius_earned = 8;
						setarray .@ingredients[ 0 ], 902, 50, 1061, 30; // item_id, item_amount
						break;
					default: break;
				}
				mes .npc$;
				mes "Crafted item : " + getitemname( .@craft_item );
				mes "Denarius to be earned : " + .@denarius_earned;
				mes "Ingredients : ";
				for ( .@i = 0; .@i < getarraysize( .@ingredients ); .@i += 2 ) 
					mes "> " + ( countitem( .@ingredients[ .@i ] ) >= .@ingredients[ .@i + 1 ] ? "^006600" : "^FF0000" ) + .@ingredients[ .@i + 1 ] + "x " + getitemname( .@ingredients[ .@i ] ) + "^000000"; 
				next;
				mes .npc$;
				mes "So do you have the following items?";
				next;
				if ( select( "Yes:No" ) - 1 ) end;
				for ( .@i = 0; .@i < getarraysize( .@ingredients ); .@i += 2 ) {
					if ( countitem( .@ingredients[ .@i ] ) < .@ingredients[ .@i + 1 ] ) {
						mes .npc$;
						mes "You lack some requirements";
						close;
					}
				}
				for ( .@i = 0; .@i < getarraysize( .@ingredients ); .@i += 2 )
					delitem .@ingredients[ .@i ], .@ingredients[ .@i + 1 ];
				.@s = rand( 1, 2 );
				mes .npc$;
				mes "Congratulations! You have crafted " + .@s + "x " + getitemname( .@craft_item ) + ". Please return to handicrafting master to earn denarius points and to gain experience on handicrafting";
				denarius_earned += .@denarius_earned;
				getitem .@craft_item, .@s;
				work_order_done = 1;
				break;
		case 2: if ( work_order_done ) {
					mes .npc$;
					mes "Seems like you have a pending work order that is still not claimed. Please see Handicrafting Master to claim the pending work order.";
					break;
				}
				/* I will not check book requirements here since this is a book crafting */
				mes .npc$;
				mes "Which book would you like to craft?";
				next;
				setarray .@books[ 0 ], 1553, 1556, 11037, 11040; // item id of handicrafting guide
				for ( .@i = 0; .@i < getarraysize( .@books ); .@i++ ) {
					.@menu$ += "- ";
					.@menu$ += getitemname( .@books[ .@i ] );
					.@menu$ += ":";
				}
				.@s = select( .@menu$ ) - 1;
				mes .npc$;
				mes "Here are the requirements on crafting the ^000099" + getitemname( .@books[ .@s ] ) + "^000000";
				switch ( .@s ) {
					/* Case 0 = First book ingredients, Case 1 = Second book ingredients and so on.. */
					case 0: setarray .@book_ingredients[ 0 ], 902, 10, 1061, 10; break; // First book ingredients
					case 1: setarray .@book_ingredients[ 0 ], 902, 20, 1061, 20; break; // Second book ingredients
					case 2: setarray .@book_ingredients[ 0 ], 902, 30, 1061, 30; break; // Third book ingredients
					case 3: setarray .@book_ingredients[ 0 ], 902, 40, 1061, 40; break; // Fourth book ingredients
					default: break;
				}
				for ( .@i = 0; .@i < getarraysize( .@book_ingredients ); .@i += 2 ) 
					mes "> " + ( countitem( .@book_ingredients[ .@i ] ) >= .@book_ingredients[ .@i + 1 ] ? "^006600" : "^FF0000" ) + .@book_ingredients[ .@i + 1 ] + "x " + getitemname( .@book_ingredients[ .@i ] ) + "^000000"; 
				next;
				mes .npc$;
				mes "So do you have the following items?";
				next;
				if ( select( "Yes:No" ) - 1 ) end;
				for ( .@i = 0; .@i < getarraysize( .@book_ingredients ); .@i += 2 ) {
					if ( countitem( .@book_ingredients[ .@i ] ) < .@book_ingredients[ .@i + 1 ] ) {
						mes .npc$;
						mes "You lack some requirements";
						close;
					}
				}
				for ( .@i = 0; .@i < getarraysize( .@book_ingredients ); .@i += 2 )
					delitem .@book_ingredients[ .@i ], .@book_ingredients[ .@i + 1 ];
				mes .npc$;
				mes "Congratulations! You have crafted " + getitemname( .@books[ .@s ] );
				getitem .@books[ .@s ], 1;
				break;
		case 3: if ( work_order_done ) {
					mes .npc$;
					mes "Seems like you have a pending work order that is still not claimed. Please see Handicrafting Master to claim the pending work order.";
					break;
				}
				if ( !callfunc( "getBookRequirements" ) ) {
					mes .npc$;
					mes "You don't have the corresponding handicrafting guide. Please check below the handicrafting guide you need.";
					for ( .@i = 0; .@i < getarraysize( .handicrafting_guide ); .@i++ ) 
						mes "[Lvl : " + .handicrafting_guide_level[ .@i ] + "] - " + getitemname( .handicrafting_guide[ .@i ] );
					break;
				}
				mes .npc$;
				mes "So which item do you like to craft?";
				next;
				setarray .@items, 1984, 1913, 1701, 11040, 2003; // item id of equipment to be crafted
				for ( .@i = 0; .@i < getarraysize( .@items ); .@i++ ) {
					.@menu$ += "- ";
					.@menu$ += getitemname( .@items[ .@i ] );
					.@menu$ += ":";
				}
				.@s = select( .@menu$ ) - 1;
				mes .npc$;
				mes "Here are the requirements on crafting the ^000099" + getitemname( .@items[ .@s ] ) + "^000000";
				switch ( .@s ) {
					/* Case 0 = First item ingredients, Case 1 = Second item ingredients and so on.. */
					case 0: setarray .@item_ingredients[ 0 ], 902, 10, 1061, 10; break; // First book ingredients
					case 1: setarray .@item_ingredients[ 0 ], 902, 20, 1061, 20; break; // Second book ingredients
					case 2: setarray .@item_ingredients[ 0 ], 902, 30, 1061, 30; break; // Third book ingredients
					case 3: setarray .@item_ingredients[ 0 ], 902, 40, 1061, 40; break; // Fourth book ingredients
					case 4: setarray .@item_ingredients[ 0 ], 902, 50, 1061, 50; break; // Fifth book ingredients
					default: break;
				}
				for ( .@i = 0; .@i < getarraysize( .@item_ingredients ); .@i += 2 ) 
					mes "> " + ( countitem( .@item_ingredients[ .@i ] ) >= .@item_ingredients[ .@i + 1 ] ? "^006600" : "^FF0000" ) + .@item_ingredients[ .@i + 1 ] + "x " + getitemname( .@item_ingredients[ .@i ] ) + "^000000"; 
				next;
				mes .npc$;
				mes "So do you have the following items?";
				next;
				if ( select( "Yes:No" ) - 1 ) end;
				for ( .@i = 0; .@i < getarraysize( .@item_ingredients ); .@i += 2 ) {
					if ( countitem( .@item_ingredients[ .@i ] ) < .@item_ingredients[ .@i + 1 ] ) {
						mes .npc$;
						mes "You lack some requirements";
						close;
					}
				}
				.@total_chance = 10 + ( handicrafting_skill / 2 ) + ( countitem( .artisan_charm_id ) ? 10 : 0 ); // chance is 10 + handicrafting skill divided by 2. So if handicrafting skill is 40. the chance is 30%
				mes .npc$;
				mes "You have a total chance of " + .@total_chance + "% on crafting this item. Would you like to continue? Note that if it fails the ingredients will be gone.";
				if ( select( "Yes:No" ) - 1 ) end;
				for ( .@i = 0; .@i < getarraysize( .@item_ingredients ); .@i += 2 )
					delitem .@item_ingredients[ .@i ], .@item_ingredients[ .@i + 1 ];
				if ( rand( 100 ) < .@total_chance ) {
					mes .npc$;
					mes "Congratulations! You have crafted " + getitemname( .@items[ .@s ] );
					getitem .@items[ .@s ], 1;
				} else {
					mes .npc$;
					mes "Too bad " + strcharinfo( 0 ) + ", You failed to craft this item. Better luck next time";
				}
				break;
		case 4:
		default: 
			break;
	}
	close;
	OnInit:
		.npc$ = "[ ^000099" + strnpcinfo( 1 ) + "^000000 ]";
		.artisan_charm_id = 705;
		/* Handicrafting Guide */
		setarray .handicrafting_guide[ 0 ], 1553, 1556, 11037, 11040; // item id of handicrafting guide
		setarray .handicrafting_guide_level[ 0 ], 0, 10, 20, 30; // level needed respectively
		end;
}
einbech,33,50,3	script	Metalworking Master	63,{
	if ( invited ) {
		if ( select( "Information:Claim my denarius for work order" ) - 1 ) {
			if ( !denarius_earned ) {
				mes .npc$;
				mes "You don't have any pending denarius to be earned. Please see handicrafting table and do some work orders.";
			} else {
				denarius += denarius_earned;
				mes .npc$;
				mes "You have earned ^000099" + denarius_earned + "^000000 denarius points and have a total of ^000099" + denarius + "^000000 points";
				denarius_earned = 0;
				next;
				mes .npc$;
				.@a = rand( 1, 5 ); // Random 1% - 5% experience points
				mes "You also gained " + .@a + " handicrafting experience points";
				handicrafting_exp += .@a;
				/* Earn handicrafting skill if experience is still greather than 100 */
				while ( 1 ) {
					if ( handicrafting_exp >= 100 ) {
						handicrafting_exp -= 100; // deduct 100 experience points since we will add one handicrafting skill level
						handicrafting_skill++; // every 100 handicrafting experience is equal to 1 handicrafting skill level
					} else break;
				}
				work_order_done = 0;
			}
		} else {
			mes .npc$;
			mes "Some work orders are needed to be done. You can complete this work orders to earn ^000099Denarius^000000, a type of currency used to buy higher skill level books. Since this is also crafting, you can gain skill levels by crafting the items for the work order.";
			next;
			mes .npc$;
			mes "When accepting a work order, it tells you the items required to fill it. Keep repeating the process of crafting items for the order until you reach a 5 level marker. Every 5 Skill Levels will make the master give you a new work order.";
			next;
			mes .npc$;
			mes "So what information you would like to know?";
			next;
			if ( select( "Check my handicrafting skill information:Check my denarius" ) - 1 ) {
				mes .npc$;
				mes "Your character have ^000099" + denarius + "^000000 denarius point" + ( denarius > 1 ? "s" : "" ) + " as of now.";
			} else {
				mes .npc$;
				mes "Level : ^000099" + handicrafting_skill + "^000000";
				mes "Experience : ^000099" + handicrafting_exp + "%^000000";
			}
		}
		close;
	}
	mes .npc$;
	mes "I am inviting you to practice some handicrafting. So are you willing to practice some handicrafting with me?";
	next;
	if ( select( "Yes:No" ) - 1 ) end;
	mes .npc$;
	mes "That's good! Speak to me again if you are ready to practice some handicrafting";
	invited = 1;
	close;
	OnInit:
		.npc$ = "[ ^000099" + strnpcinfo( 1 ) + "^000000 ]";
		end;
}