//@unloadnpc Banker
//@loadnpc npc/thor/bank.txt


office,117,18,0	script	Banker	1_F_LIBRARYGIRL,{
	disable_items;
	mes .npc$;
	mes "Hello " + strcharinfo( PC_NAME ) + ", Please sit down. What can i do for you?";
	next;
	switch( select( ( !#activated ? "" : "Deposit:Withdraw:Balance Inquiry:" ) + "Nothing" ) ) {
		case 1: 
			mes .npc$;
			mes "Hi, how much would you like to deposit? Maximum amount per transaction is "+callfunc("F_InsertComma",.maxtransaction)+ " zeny";
			next;
			input .@amount;
			if ( !.@amount || .@amount > .maxtransaction ) {
				mes .npc$;
				mes "Invalid amount. Maximum amount per transaction is "+callfunc("F_InsertComma",.maxtransaction)+ " zeny";
				break;
			}
			mes .npc$;
			mes "Are you sure you want to deposit " +callfunc("F_InsertComma",.@amount)+ " zeny to your bank account?";
			next;
			if ( select( "Yes:No" ) - 1 ) break;
			mes .npc$;
			mes "Let me check if you have the corresponding amount on your character";
			next;
			if ( Zeny < .@amount ) {
				mes .npc$;
				mes "Seems like you don't have that kind of amount. I will terminate this transaction then.";
				break;
			}
			mes .npc$;
			mes callfunc("F_InsertComma",.@amount)+ " zeny have been deposited on your account. Thank you for using this ATM system";
			query_sql "UPDATE `bank` SET `money` = `money` + '" + .@amount + "' WHERE `account_id` = '" + getcharid( 3 ) + "'";
			Zeny -= .@amount;
			break;
		case 2: 
			mes .npc$;
			mes "Hi, how much would you like to withdraw? Maximum amount per transaction is "+callfunc("F_InsertComma",.maxtransaction)+ " zeny";
			next;
			input .@amount;
			if ( !.@amount || .@amount > .maxtransaction ) {
				mes .npc$;
				mes "Invalid amount. Maximum amount per transaction is "+callfunc("F_InsertComma",.maxtransaction)+ " zeny";
				break;
			}
			mes .npc$;
			mes "Are you sure you want to withdraw " +callfunc("F_InsertComma",.@amount)+ " zeny from your bank account?";
			next;
			if ( select( "Yes:No" ) - 1 ) break;
			mes .npc$;
			mes "Let me check if you have the corresponding amount on your bank account";
			next;
			query_sql "SELECT `money` FROM `bank` WHERE `account_id` = '" + getcharid( 3 ) + "'", .@balance;
			if ( .@balance < .@amount ) {
				mes .npc$;
				mes "Seems like you don't have that kind of amount. I will terminate this transaction then.";
				break;
			}
			mes .npc$;
			mes "Let me check if you can hold the corresponding amount";
			next;
			if ( ( Zeny + .@amount ) > 2000000000 ) {
				mes .npc$;
				mes "You cannot afford to hold this kind of zeny. The maximum zeny you can hold is 2,000,000,000 zeny only.";
				break;
			}
			mes .npc$;
			mes callfunc("F_InsertComma",.@amount)+ " zeny have been withdrew on your account. Thank you for using this ATM system";
			query_sql "UPDATE `bank` SET `money` = `money` - '" + .@amount + "' WHERE `account_id` = '" + getcharid( 3 ) + "'";
			Zeny += .@amount;
			break;
		case 3: 
			query_sql "SELECT `money` FROM `bank` WHERE `account_id` = '" + getcharid( 3 ) + "'", .@balance;
			mes .npc$;
			mes "Your account balance is : " +callfunc("F_InsertComma",.@balance)+ " zeny";
			break;
		case 4: 
			mes .npc$;
			mes "Okay then, see you around!";
			break;
		default: 
			break;
		}
		close;

OnInit:
	waitingroom "Bank Teller",0;
	.npc$ = "[ ^996600ATM System^000000 ]";
	.maxtransaction = 10000000;

	query_sql "CREATE TABLE IF NOT EXISTS `bank` ( `account_id` INT NOT NULL DEFAULT '0', `money` BIGINT NOT NULL DEFAULT '0', PRIMARY KEY( `account_id` ) ) ENGINE=MyISAM";
	end;

OnPCLoginEvent:
	if ( #activated ) {
		end;
	}
	#activated = 1;
	query_sql "INSERT INTO `bank` ( `account_id`, `money` ) VALUES ( '" + getcharid( 3 ) + "', '0' )";
	end;
}