//===== Hercules Script ======================================= //= Automated Teller Machine Script //===== By: ================================================== //= Patskie //===== Current Version: ===================================== //= 2.0 //===== Description: ========================================= //= Enhanced atm system //===== Additional Comments: ================================= //= Do not remove the credits //= 1.0 - Initial Release //= 2.0 - Massive Update! Check here! //= - http://hercules.ws/board/topic/402-atm-system/ //============================================================ - script BankSystem -1,{ OnInit: bindatcmd "atm", strnpcinfo( 3 ) + "::OnBankTransaction"; .npc$ = "[ ^996600ATM System^000000 ]"; 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"; .interest_rate = 1000; // 1000 zeny interest rate every day .number_of_bank_account_reminder = 5; // times the npc will inform the user about their account number end; OnClock0000: query_sql "UPDATE `bank` SET `money` = `money` - '" + .interest_rate + "' WHERE `money` > '" + .interest_rate + "'"; end; OnPCLoginEvent: if ( #activated ) { if ( #bank_account_reminder < .number_of_bank_account_reminder ) { #bank_account_reminder++; message strcharinfo( 0 ), "Your bank account number is " + getcharid( 3 ) + ". Please remember this so you can use our ATM system. Thank you!"; } end; } #activated = 1; query_sql "INSERT INTO `bank` ( `account_id`, `money` ) VALUES ( '" + getcharid( 3 ) + "', '0' )"; message strcharinfo( 0 ), "Your account has activated the ATM system of this server"; end; OnBankTransaction: mes .npc$; mes "Hello " + strcharinfo( 0 ) + ", What can i do for you?"; next; switch( select( ( !#activated ? "" : "Deposit:Withdraw:Balance Inquiry:" ) + "Nothing" ) ) { case 1: mes .npc$; mes "Please enter your account number before proceeding"; next; input .@account_number; if ( .@account_number != getcharid( 3 ) ) { mes .npc$; mes "You put the wrong account number. If you feel you have lost your account number. Please contact the administrator of this game for further assistance."; break; } mes .npc$; mes "Hi, how much would you like to deposit?"; next; input .@amount; if ( !.@amount || .@amount > 2147483647 ) { mes .npc$; mes "Invalid amount"; break; } mes .npc$; mes "Are you sure you want to deposit " + .@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 .@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 "Please enter your account number before proceeding"; next; input .@account_number; if ( .@account_number != getcharid( 3 ) ) { mes .npc$; mes "You put the wrong account number. If you feel you have lost your account number. Please contact the administrator of this game for further assistance."; break; } mes .npc$; mes "Hi, how much would you like to withdraw?"; next; input .@amount; if ( !.@amount || .@amount > 2147483647 ) { mes .npc$; mes "Invalid amount"; break; } mes .npc$; mes "Are you sure you want to withdraw " + .@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 .@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 : " + .@balance + " zeny"; break; case 4: mes .npc$; mes "Okay then, see you around!"; break; default: break; } close; }