Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

[ES/TUT] Creating a Bank

Creating a Bank
by Draken

Introduction
We are familiar with banks, the long queues and dull atmosphere. Although, they are very useful places, as we all know. They help us manage our money so that we don't overspend, and even give us interest! So I thought, why not bring this type of money management into RMXP? I am sure most of you can easily create a bank system, but I haven't seen a tutorial on these forums yet!

NOTE: This topic is aimed at less experienced RMXP users, so I will make the instructions as clear as possible.

Required Knowledge

  • Switches
  • Variables
  • Events and Event Commands (Conditional Branches etc.)
  • Common Events


Let's Get Started!

Although this is indeed aimed at those less experienced with RMXP, there is still a minimum knowledge requirement, but those are the most basic requirements for a RMXP user.

So, first off, we are going to sort out the Bank Balance and how to show your current Bank Balance in-game. In my demo, I used a small note against a wall to show your Balance, you can do this however you wish. Quite simply, create a new event where you would like the player to see their balance, be it a note on the wall or table. Make this event triggered by the Action Button, and create a new [Show Text]. In this event, type the following:
Code:
Bank Balance: \v[1]
What's that "\v[1]" about?
That funny little code there is RMXP's way of showing variables in messages. the number (1) is the ID of the variable, and in that case, Variable Number 1. This variable is where we will hold the bank balance.

Depositing and Withdrawing
Well, that was easy! (Wasn't it?)
Now, we are going to get to the fun part! Depositing in the bank, is quite simply taking money that you have on you and placing it into your account, this will then gain interest. Withdrawal is when you take money out of your account and into your pockets.

Depositing
Right! Create a new event, I used one of the Shop Keeper sprites for the graphic. To start, use the [Control Variables] command, make a second variable and call it "Deposit" (The first variable is "BankBalance"). While you are still in the [Control Variables] command box, make sure that you set the variable to 0. This is to avoid adding extra money to the player's account from earlier deposits.
Now, use a [Show Text] command, and ask the player if he wants to deposit any money. Afterwards, simply use the [Show Choices] command and leave it at the default. Under the "When [Yes]" option, create a new [Conditional Branch] event. In the command box, search for the Gold option and set it to 1 or more. Make sure the "Set handling when conditions do not apply" box is ticked. Under the "Else" option, create a [Show Text] command, and type in something appropriate saying that they can't deposit money due to not actually having any on them.
Now, on the other [Conditional Branch] option (the one where conditions are met) create another [Show Text] command asking the player how much he wishes to deposit.
Then, create a [Input Number] command and set it to the "Deposit" variable, set the digit limit to as much as you like (I used 4).
Now, create a [Wait] command, and set it to 2 frames (this is to make sure that variable controls aren't skipped, at least 1 frame should be spread between them).
Next, you'll have to create another [Control Variable] command, and make it so that the "Deposit" variable is added to the "BankBalance" variable. The event code should look something like this:
Code:
Control Variables: [0001: BankBalance] += Variable [0002: Deposit]
Create another [Wait] command, again waiting 2 frames.
Now, use the [Change Gold] command and make it decrease, decrease it by the variable "Deposit".
Finally, create a thank you message after the gold has been decreased and you have finished your deposit event! Congratulations!

http://img523.imageshack.us/img523/9554/depositeventty6.png[/img]

Withdrawing
Withdrawing works similarly to Depositing, except it does the opposite thing. It takes money out of your account, and stuffs it in your pockets or wallet.

Ok, create a new [Control Variables] command, and create a new variable. Call it "Withdraw". Set it to 0.
Make a [Conditional Branch] command and this time set it so that the variable "BankBalance" is greater than 0 (Well, you can't withdraw the money if it's not there in the first place!), then click OK. When the conditions are met, use the [Show Text] command to ask if the player wants to withdraw.
Under "Yes", create another [Show Text] command asking how much they wish to withdraw. Again, use the [Input Number] command and set it to the Withdraw variable.
Create yet another [Conditional Branch] to check if the "Withdraw" variable is bigger than the "BankBalance". When the conditions are met, create a [Show Text] command, telling the player he has attempted to withdraw too much.
Under Else, make a [Control Variables] command subtracting the "Withdraw" variable from the "BankBalance" variable. The code should look similar to this:
Code:
Control Variables: [0001: BankBalance] -= Variable [0003: Withdraw]

Well, that's about it for withdrawal! Minus the little nitbits of conversation, if you want to add that, you will find it in the event's screenshot.
http://img187.imageshack.us/img187/3843/withdraweventsy0.png[/img]

Interest
This is where it gets a little complicated. First, go into the Database and create a new Common Event, call this "Interest". Make a [Conditional Branch] to make sure that the "BankBalance" variable is over 0. In this, make it wait a certain amount of time (I used 100 frames for testing purposes, but I suggest using a good amount of 999 frames). Now create a [Control Variables] command, and use a fourth variable ("Interest") and make it equal to the "BankBalance" variable. Create another [Control Variables] command, making the "Interest" variable multiplied by 1000 (The reason behind this is that RMXP only calculates in integers, and it is hard to get an accurate percentage this way).
Create yet another [Control Variables] event and divide the "Interest" Variable by 100. Create another and multiply it by whatever you want the interest rate to be (I used 10, so the interest will be 10%, most banks are only around 3%). Now, create another [Control Variables] command, and divide the "Interest" variable by 1000.
Finally, create the last [Control Variables] command, and make it so that the "Interest" variable is added to the "BankBalance" variable.

NOTE: Remember to keep [Wait] commands waiting for at least 1 frame between the [Control Variables] and [Control Switches] commands. This is to prevent RMXP from skipping certain commands.

Now, for this common event, set the trigger to Parallel (Someone's gonna eat my head off for this, but I had no other way) and call the condition switch "InterestON". You can place this switch wherever you please. I simply made an autorun event at the start of the demo which turned this on.

http://img456.imageshack.us/img456/5817/interesteventup3.png[/img]

Demo

http://www.denis.static-media.com/rmxp/BankSystem.rar

No credit needed if you are to use this tutorial and/or demo.
 
Very good Draken! Though, I would reccomend you track interest by "Number of Steps Taken" instead. That way someone can't just leave RMXP on and go watch TV or something.
 
Yeah, good point. But interest could take a long time depending on the person. He could make it wait 1,000,000 frames which is a long time :)
 
There's a bug in the event scripting. When you have more then 1 Gold in your possesion you can deposit any amount of money it doens't matter how much you have aslong you atleast have 1 Gold. You should make another control variable after the [control variables] deposit with [control variables] : 0003 = Gold. Then make another conditional branch after the input number which should check if variable 1 deposit is larger than variable 3 gold if it is the banker should say something like "you're trying to deposit more than you have." else would be balance + deposit wait gold - deposit wait "thank you"

But otherwise good script and 1,000,000 frames wait is far too long ^^ it's almost 7 houres OO, keeping track with steps is better than that :P
 
i saw this and thought... this would be a sweet thing to do... but when i tried to make the gold as a variable and check it with the deposits i had and error... i had this
if vgold < vdeposits
'can't do that, blah blah...'

else
-blah gold
+blah gold to bankbalance...

it says it can't do whatever with the gold and depsits...

also, it doesn't subtract the gold from the user, it keeps it and depsites...???

what did i do wrong...
 
Wouldn't it jsut be easier to have it run a command, MoneyDeposited <= Gold, Please correct me if I'm wrong, I haven't opened RMXP in months and forgot most all it could do with variables, Other than that, Really nice script :yes:
 

Azule

Member

Ok... I'm having a little problem. It's one that I always seem to get... I've got everything in correctly, but when I deposit 1 gold coin, it doesn't actually deposit the coin. Why? Hit me back with a response please.
 

Azule

Member

Also, I have it set up so when I start it up, it already has 1 gold in the account (until i can fix the problem), and it shows, but when I withdraw it; it says that there is still 1 gold in the account... any fixes? or, does anybody have a demo i can use and just copy the event into my game, and then I can place you in my credits...
 
@Azule Sounds weird, It's almost as if it's not pulling from the variables, Could you take some screens from the script?
 
Nice tutorial. Its well-organized and works out perfectly. I was wondering if anyone had come up with a way to use steps instead of frames. Thanks in advanced.
 
Ok so has anyone figured out how to fix the error with depositing any amount of money, even though you don't have it? I've tried tons of things, couldn't figure it out, either it will let me deposit any amount, or I can't deposit anything, lol.
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top