AbyssalLord
Member
Banking System
I'm going to be explaining how to make a simple banking system that includes interest rates and a loan system. This tutorial might seem a bit long, but don't worry! It's a simple process to follow. There is a demo toward the bottom for anyone who would like to try it out!
What does this do?
Requirements:
This is where the tutorial really begins. This tutorial consists of several parts: Deposit, Withdraw, Interest, Loans, HUD, and Putting It All Together. Each part will explain step by step how to set up the event and eventually how to put them all together. Without further ado, let us begin the tutorial!
Part One: Deposit
Part Two: Withdraw
Part Three: Interest
Part Four: Loans
Part Five: The HUD
Part Six: Putting It All Together
Credits
You can credit me for helping you out, but it's not necessary. It IS necessary to credit me (and anyone else I mentioned at the beginning of the script) if you use the script.
Demo
As I promised at the beginning, here's my demo:
Banking System - Version 2.0
OLD VERSION--Banking System Demo
Thankyou everyone for taking the time to read this, and I hope it helps you all out!
I'm going to be explaining how to make a simple banking system that includes interest rates and a loan system. This tutorial might seem a bit long, but don't worry! It's a simple process to follow. There is a demo toward the bottom for anyone who would like to try it out!
What does this do?
- Unlimited gold storage
- Interest rates (customizable)
- NEW: Loan System
- NEW: Loan System Interest
- NEW: HUD
- Prevention against storing more than one has in one's inventory
- Prevention against taking out more than one has in the bank
- Prevention of withdrawing more than one can carry (to prevent loss of gold)
- Premade banker diolog (in demo)
- Allows the player to deposit (and withdraw) the exact amount of gold that said player would like into (or out of)the bank
- more...
Requirements:
- Eight variables
- Seven conditional branches
- Five common events
This is where the tutorial really begins. This tutorial consists of several parts: Deposit, Withdraw, Interest, Loans, HUD, and Putting It All Together. Each part will explain step by step how to set up the event and eventually how to put them all together. Without further ado, let us begin the tutorial!
Part One: Deposit
In this first part of my tutorial, I will explain to you how to make the deposit common event. It allows the player to store as much money as he/she has in his/her inventory, but nothing more. Before I continue, create a common event named "Deposit," and set the trigger to "none."
To set this up, you first have to define a variable, which I will refer to as [gold in inventory], and SET it
to the amount of gold in the player's inventory.
Next, just add whatever text you want the banker to say before you input the amount of gold/money that
you would like to deposit.
Then, allow the player to input a value of SEVEN digits. Any more or less could potentially cause
issues based on player input. Save this value as the variable, [Deposit Value].
Now, you need to create a conditional branch specifying that [Gold in Inventory] is greater than or equal to [Deposit Value]. This will prevent the player from storing more than he/she has (which would result in very rich players very fast).
If the conditions are met:
Subtract the [Deposit Value] from the player's gold.
Add the [Deposit Value] to [Gold in Bank]. This will add your money into the bank account.
Now, just reset the [Deposit Value] to 0 (just to be on the safe side).
Add the banker's closing text.
If the conditions are not met:
Insert the banker's text saying something like: "Hmm...it seems you don't have that much gold."
Guess what. Your done with part one! Simple, right?
To set this up, you first have to define a variable, which I will refer to as [gold in inventory], and SET it
to the amount of gold in the player's inventory.
Next, just add whatever text you want the banker to say before you input the amount of gold/money that
you would like to deposit.
Then, allow the player to input a value of SEVEN digits. Any more or less could potentially cause
issues based on player input. Save this value as the variable, [Deposit Value].
Now, you need to create a conditional branch specifying that [Gold in Inventory] is greater than or equal to [Deposit Value]. This will prevent the player from storing more than he/she has (which would result in very rich players very fast).
If the conditions are met:
Subtract the [Deposit Value] from the player's gold.
Add the [Deposit Value] to [Gold in Bank]. This will add your money into the bank account.
Now, just reset the [Deposit Value] to 0 (just to be on the safe side).
Add the banker's closing text.
If the conditions are not met:
Insert the banker's text saying something like: "Hmm...it seems you don't have that much gold."
Guess what. Your done with part one! Simple, right?
Part Two: Withdraw
This part of the tutorial will teach you how to make a withdraw system. If you had trouble with the part above, I just want to warn you that this part may be a bit more complicated. This part of the system will allow the player to withdraw money from their account. To make sure the player cannot lose money in the process, I have included a conditional branch that will not allow one to withdraw more than said player can carry. With that, let us begin.
First, create a common event called "Withdraw," and set its trigger to "none."
Like deposit, you should add some text that the banker says before you input how much you would like to withdraw.
The next thing you should do is to allow the player to input a SEVEN digit number to be stored as the variable, [withdraw value].
Set [Gold in Inventory] to the amount of gold in the player's inventory, and add that with [Withdraw Value]. When adding, make sure [Gold in Inventory] comes before [Withdraw Value].
ex: [Gold in Inventory] + [Withdraw Value]
Now, to ensure that the player is not going to withdraw more than it's possible for the player to carry, create a conditional branch that says:
[Gold in Inventory] > 9999999
If the condition is met, set the banker's message (telling the player that he/she cannot carry that much
gold).
If the condition is not met, create another conditional branch that specifies that [Gold in Bank] is greater
than or equal to [Withdraw Value]. This will make sure that the player cannot withdraw more than
he/she is keeping in the bank.
If the conditions are met:
The next steps are just simple calculations.
1) Add the [Withdraw Value] to your gold with the change gold command.
2) Subtract the [Withdraw Value] from [Gold in Bank]
3)Set the [Withdraw Value] to 0
4) Insert banker text.
If the conditions are not met:
Insert the banker's text saying something like: "You do not have that much gold in your account."
If you're still with me here, you've just finished part two. That means you've made it more than halfway (part 3 and 4 are much shorter). So, why don't you take a break, get yourself a cookie, watch TV with some friends, and then come back and finish up your event?
First, create a common event called "Withdraw," and set its trigger to "none."
Like deposit, you should add some text that the banker says before you input how much you would like to withdraw.
The next thing you should do is to allow the player to input a SEVEN digit number to be stored as the variable, [withdraw value].
Set [Gold in Inventory] to the amount of gold in the player's inventory, and add that with [Withdraw Value]. When adding, make sure [Gold in Inventory] comes before [Withdraw Value].
ex: [Gold in Inventory] + [Withdraw Value]
Now, to ensure that the player is not going to withdraw more than it's possible for the player to carry, create a conditional branch that says:
[Gold in Inventory] > 9999999
If the condition is met, set the banker's message (telling the player that he/she cannot carry that much
gold).
If the condition is not met, create another conditional branch that specifies that [Gold in Bank] is greater
than or equal to [Withdraw Value]. This will make sure that the player cannot withdraw more than
he/she is keeping in the bank.
If the conditions are met:
The next steps are just simple calculations.
1) Add the [Withdraw Value] to your gold with the change gold command.
2) Subtract the [Withdraw Value] from [Gold in Bank]
3)Set the [Withdraw Value] to 0
4) Insert banker text.
If the conditions are not met:
Insert the banker's text saying something like: "You do not have that much gold in your account."
If you're still with me here, you've just finished part two. That means you've made it more than halfway (part 3 and 4 are much shorter). So, why don't you take a break, get yourself a cookie, watch TV with some friends, and then come back and finish up your event?
Part Three: Interest
This part of the banking system creates the interest rate. It's much shorter than the last two parts, and all it is really is a little math. This interest system is really just a simple equation that I came up with:
([Interest Rate]/100 * [Gold in bank])+[Gold in Bank]
Simple really. So, let's start.
Create a common event, and name it "Interest
Define a variable called [Interest Rate] and set it to whatever number you want (based on interest percentage).
This variable sets the interest rate:
3 = 3% interest
10 = 10% interest
79 = 79% interest
etc.
You can change the interest rate to suit your needs.
Next up comes the dreaded MATH...
The way RMXP is, you have to multiply before you divide or else it will come out to interest = 0 (which is
in no way helpful). So...
[Interest Rate] * [Gold in Bank]
IN THAT ORDER
Then divide [Interest Rate] by 100.
Finally, add [Interest Rate] to [Gold in Bank] and you have your interest system!
([Interest Rate]/100 * [Gold in bank])+[Gold in Bank]
Simple really. So, let's start.
Create a common event, and name it "Interest
Define a variable called [Interest Rate] and set it to whatever number you want (based on interest percentage).
This variable sets the interest rate:
3 = 3% interest
10 = 10% interest
79 = 79% interest
etc.
You can change the interest rate to suit your needs.
Next up comes the dreaded MATH...
The way RMXP is, you have to multiply before you divide or else it will come out to interest = 0 (which is
in no way helpful). So...
[Interest Rate] * [Gold in Bank]
IN THAT ORDER
Then divide [Interest Rate] by 100.
Finally, add [Interest Rate] to [Gold in Bank] and you have your interest system!
Part Four: Loans
This is the new part of the system, and it's more complicated than anything else so far. For that reason, I will be color coding it! Please bear with me as I explain the loan system, as tedious as it may be. It will be rewarding in the end!
This section of the event system will allow the player to borrow money from the bank.
First, create a variable called [Loan]. Insert a conditional branch saying:
if [Loan] >= 1
If the condition is met...
Insert some banker text saying that you need to pay back the loan before you take out more.
Now create a new variable called [Return Loan]. Set up another input digits command (no more than
SEVEN).
Now, set [Gold in Inventory] = Gold (use the change gold command)
Guess what? Time for another conditional branch...
if [Gold in Inventory] >= [Return Loan]
If the condition is met...
Now, insert yet ANOTHER conditional branch (don't worry, this is annoying me too):
if [Loan] >= [Return Loan]
If the condition is met...
Subtract [Return Loan] from the gold in the player's inventory using the Change Gold command.
Then subtract [Return Loan] from [Loan].
Insert banker text.
If the condition is not met...
Insert banker text saying that you do not owe that much money.
If the condition is not met...
Insert banker text saying that you do not have that much gold.
If the condition is not met...
Insert text asking how much gold you would like to borrow.
Next, just add another input value (I'll use four, but use SEVEN MAX), and save it as the variable [Loan].
Now, let's say 'hello' to our good buddy, the [Gold in Inventory] variable. Once again, set it to the gold in
the player's inventory. Then add [Gold in Inventory] with [Loan]. Make sure [Gold in Inventory] is first:
[Gold in Inventory] + [Loan]
WOOOOOT!!!! Time for another CONDITIONAL BRANCH:
if [Gold in Inventory] > 9999999
This is probably not necessary, but it's a precaution for an unlikely but problematic glitch.
If the condition is met...
Isnert banker text saying that you cannot carry that much gold.
If the condition is not met...
Just add that [Loan] value to the player's gold, and insert some banker text.
Interest
The loan interest system works in the exact same way as the [Gold in Bank] interest system. Follow that guide, and replace [Gold in Bank] with [Loan]. That's all there is to it!
YES! DONE! Happy you made it all the way through that? You should be, now you have an awesome interest system to go along with the rest of your banking system!
This section of the event system will allow the player to borrow money from the bank.
First, create a variable called [Loan]. Insert a conditional branch saying:
if [Loan] >= 1
If the condition is met...
Insert some banker text saying that you need to pay back the loan before you take out more.
Now create a new variable called [Return Loan]. Set up another input digits command (no more than
SEVEN).
Now, set [Gold in Inventory] = Gold (use the change gold command)
Guess what? Time for another conditional branch...
if [Gold in Inventory] >= [Return Loan]
If the condition is met...
Now, insert yet ANOTHER conditional branch (don't worry, this is annoying me too):
if [Loan] >= [Return Loan]
If the condition is met...
Subtract [Return Loan] from the gold in the player's inventory using the Change Gold command.
Then subtract [Return Loan] from [Loan].
Insert banker text.
If the condition is not met...
Insert banker text saying that you do not owe that much money.
If the condition is not met...
Insert banker text saying that you do not have that much gold.
If the condition is not met...
Insert text asking how much gold you would like to borrow.
Next, just add another input value (I'll use four, but use SEVEN MAX), and save it as the variable [Loan].
Now, let's say 'hello' to our good buddy, the [Gold in Inventory] variable. Once again, set it to the gold in
the player's inventory. Then add [Gold in Inventory] with [Loan]. Make sure [Gold in Inventory] is first:
[Gold in Inventory] + [Loan]
WOOOOOT!!!! Time for another CONDITIONAL BRANCH:
if [Gold in Inventory] > 9999999
This is probably not necessary, but it's a precaution for an unlikely but problematic glitch.
If the condition is met...
Isnert banker text saying that you cannot carry that much gold.
If the condition is not met...
Just add that [Loan] value to the player's gold, and insert some banker text.
Interest
The loan interest system works in the exact same way as the [Gold in Bank] interest system. Follow that guide, and replace [Gold in Bank] with [Loan]. That's all there is to it!
YES! DONE! Happy you made it all the way through that? You should be, now you have an awesome interest system to go along with the rest of your banking system!
Part Five: The HUD
This probably should be in Submitted Scripts, but since I made it for the sole purpose of working with this banking system, I've put it here. I will also explain how to use it (this is still part of the tutorial).
This HUD will display (based on variables and switches) either the gold in your inventory, the gold in the bank, or the gold you owe the bank.
First of all, let's look at the beginning of the script:
GOLD_IN_BANK = 3 #Variable index where bank gold is kept (replace the "3" with the ID of [Gold in Bank])
GOLD_OWED = 6 #Variable index where owed gold is kept (replace the "6" with the ID of [Loan])
DRAW_GOLD= 9 #Variable index that decides which gold to draw (replace the "9" with whatever variable you would like. I will refer to this variable as Draw_Gold)
This refers to the value of Draw_Gold:
Value Display
# 0 : Display nothing
# 1 : Display party gold
# 2 : Display gold savings
# 3 : Display gold owed
So, if DRAW_GOLD is equal to 2, the amount of gold you have stored in the bank will be displayed.
Ok, got that? Now, this can be found toward the bottom of the script:
VISIBILITY_SWITCH = 1
The "1" is the switch ID. If the switch is off, the HUD is invisible. If the switch is on, the HUD will appear.
That's about all there is to configuring the HUD. Let's talk a little bit about implementing it in your banking system.
Basically, when you want to display the value, turn the switch above on along with setting the variable, DRAW_GOLD to either 1, 2, or 3. At the end of the event, just turn the switch off and set DRAW_GOLD to 0.
So, let's use deposit as an example. Right after to set [Gold in Inventory] to the player's gold, turn the switch on, and SET the variable DRAW_GOLD to 1.
At the very end of the event (after the last "Branch End"), turn the switch off, and SET DRAW_GOLD to 0. Just do that with all of the common events (Deposit, Withdraw, and Loan) and you have a completed system. Make sure to set the variable to the correct value or else it will display either the wrong amount of gold or a blank box.
Hope this will be of use to you! Here's the code:
This HUD will display (based on variables and switches) either the gold in your inventory, the gold in the bank, or the gold you owe the bank.
First of all, let's look at the beginning of the script:
GOLD_IN_BANK = 3 #Variable index where bank gold is kept (replace the "3" with the ID of [Gold in Bank])
GOLD_OWED = 6 #Variable index where owed gold is kept (replace the "6" with the ID of [Loan])
DRAW_GOLD= 9 #Variable index that decides which gold to draw (replace the "9" with whatever variable you would like. I will refer to this variable as Draw_Gold)
This refers to the value of Draw_Gold:
Value Display
# 0 : Display nothing
# 1 : Display party gold
# 2 : Display gold savings
# 3 : Display gold owed
So, if DRAW_GOLD is equal to 2, the amount of gold you have stored in the bank will be displayed.
Ok, got that? Now, this can be found toward the bottom of the script:
VISIBILITY_SWITCH = 1
The "1" is the switch ID. If the switch is off, the HUD is invisible. If the switch is on, the HUD will appear.
That's about all there is to configuring the HUD. Let's talk a little bit about implementing it in your banking system.
Basically, when you want to display the value, turn the switch above on along with setting the variable, DRAW_GOLD to either 1, 2, or 3. At the end of the event, just turn the switch off and set DRAW_GOLD to 0.
So, let's use deposit as an example. Right after to set [Gold in Inventory] to the player's gold, turn the switch on, and SET the variable DRAW_GOLD to 1.
At the very end of the event (after the last "Branch End"), turn the switch off, and SET DRAW_GOLD to 0. Just do that with all of the common events (Deposit, Withdraw, and Loan) and you have a completed system. Make sure to set the variable to the correct value or else it will display either the wrong amount of gold or a blank box.
Hope this will be of use to you! Here's the code:
Code:
#=================================================================================
#Bank HUD by AbyssalLord
#Version 1.0
#=================================================================================
#This is a simple HUD that is intended to be used with my evented bank system. It
#can display gold in the player's inventory, gold in the bank, and gold owed as a
#result of loans. All of these are based on activating switches and variables
#through my event system.
#=================================================================================
#Credits go to AbyssalLord, khmp, and Yeyinde
#I learned a lot from those two!
#=================================================================================
#**Window_GoldHUD
#---------------------------------------------------------------------------------
#This class is used to display amounts of gold.
#=================================================================================
class Window_GoldHUD < Window_Base
#--------------------------------------------------------------------------
# * @gold_draw
# 0 : Display nothing
# 1 : Display party gold
# 2 : Display gold savings
# 3 : Display gold owed
#--------------------------------------------------------------------------
#--------------------------------------------------------------------------
# * Constant Variables
#--------------------------------------------------------------------------
GOLD_IN_BANK = 3 #Variable index where bank gold is kept
GOLD_OWED = 6 #Variable index where owed gold is kept
DRAW_GOLD= 9 #Variable index that decides which gold to draw
#==========================================================================
#Initialize
#==========================================================================
def initialize
super(440,0,200,60)
self.contents = Bitmap.new(width - 32, height - 32)
@gold_draw = 0
refresh
end
#==========================================================================
#Refresh
#==========================================================================
def refresh
#Clear the HUD
self.contents.clear
reset_gold
#Return if nothing is meant to be drawn
return if @gold_draw == 0
return if @gold_draw < 0
return if @gold_draw > 3
gold,amount = ","
case @gold_draw
when 1
gold = 'Gold'
amount = @gold.to_s
when 2
gold = 'Gold'
amount = @bank_gold.to_s
when 3
gold = 'Owed'
amount = @loan_gold.to_s
end
#Draw the contents
self.contents.draw_text(-60, 0, 150, 32, amount, 2)
self.contents.draw_text(100, 0, 150, 32, gold)
end
#=========================================================================
#Reset the values
#=========================================================================
def reset_gold
@gold = $game_party.gold
@bank_gold = $game_variables[GOLD_IN_BANK]
@loan_gold = $game_variables[GOLD_OWED]
@gold_draw = $game_variables[DRAW_GOLD]
end
#=========================================================================
#Update
#=========================================================================
def update
super()
refresh if ( @gold_draw != $game_variables[DRAW_GOLD] or
@gold != $game_party.gold or
@bank_gold != $game_variables[GOLD_IN_BANK] or
@loan_gold != $game_variables[GOLD_OWED] )
end
end
#=========================================================================
#**Scene_Map
#-------------------------------------------------------------------------
#This class performs map screem processing
#=========================================================================
class Scene_Map
#=========================================================================
#Alias Methods
#=========================================================================
alias goldhud_main main
alias goldhud_update update
#==========================================================================
#Contant Variables
#==========================================================================
VISIBILITY_SWITCH = 1 #The switch ID that determines the HUD's visibility
#==========================================================================
#Main Processing
#==========================================================================
def main
@goldhud = Window_GoldHUD.new
@goldhud.visible = $game_switches[VISIBILITY_SWITCH]
goldhud_main
@goldhud.dispose
end
#==========================================================================
#Update
#==========================================================================
def update
@goldhud.visible = $game_switches[VISIBILITY_SWITCH]
@goldhud.update
goldhud_update
end
end
Part Six: Putting It All Together
This is by far the simplest part yet. Basically, to put your banking system together, you just need some diolog and some choices. I'll just give you a simple example:
Text: Welcome to the bank, how can I help you?
Show Choices (Deposit, Withdraw)
When Deposit
Call Common Event: Deposit
When Withdraw
Call Common Event: Withdraw
Branch End
I think you get the idea. Now, a little about interest. If you have a day/night system, you could call the interest common event every night (or whenever you like). You could really call it whenever you see fit, it's fully customizable.
Honestly, that's about all there is to putting it all together. Congratulations, you got through the whole tutorial! You should now have a fully functional banking system.
Text: Welcome to the bank, how can I help you?
Show Choices (Deposit, Withdraw)
When Deposit
Call Common Event: Deposit
When Withdraw
Call Common Event: Withdraw
Branch End
I think you get the idea. Now, a little about interest. If you have a day/night system, you could call the interest common event every night (or whenever you like). You could really call it whenever you see fit, it's fully customizable.
Honestly, that's about all there is to putting it all together. Congratulations, you got through the whole tutorial! You should now have a fully functional banking system.
Credits
You can credit me for helping you out, but it's not necessary. It IS necessary to credit me (and anyone else I mentioned at the beginning of the script) if you use the script.
Demo
As I promised at the beginning, here's my demo:
Banking System - Version 2.0
OLD VERSION--Banking System Demo
Thankyou everyone for taking the time to read this, and I hope it helps you all out!