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
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:
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:
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!
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:
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.
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.
Demo
http://www.denis.static-media.com/rmxp/BankSystem.rar
No credit needed if you are to use this tutorial and/or demo.
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]
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]
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.