How do I make a Bank where you can store money/items?

From OHRRPGCE-Wiki
Jump to navigation Jump to search
Revise.png
This article or section is not complete. If you wish, you may finish it, and remove this tag when you are done.

The easy part: money storage basics[edit]

Making a "bank" that stores extra money is easy enough. You just need a global variable to be the "bank account" and two scripts, one to deposit (remove money from the party and increase the account by the same amount) and one to withdraw (remove money from the account and add it to the party). Add in a few checks to make sure you don't overflow the account and to disallow withdrawing or depositing money you don't have, and you'll likely end up with scripts along these lines:

global variable (63, bank balance)	# variable to store your money
define constant (2147483647, max savings)	# maximum bank balance, equal to the highest number that can be stored in a variable

script, deposit, amount=0, begin
 # check to make sure this deposit won't exceed the maximum bank balance and the player
 # actually has the amount of money they're depositing
 if (((max savings -- bank balance) >= amount) && pay money (amount)) then, begin
  # pay money (amount) already removed the money from the player's cash on hand so
  # just add it to the bank balance
  bank balance := bank balance + amount
 end
end

script, withdraw, amount=0, begin
 # check to make sure the requested money actually exists in the bank and that this
 # withdrawal won't cause the player's money to overflow
 if (((2000000000 -- party money) >= amount) && bank balance >= amount) then, begin
  # remove money from bank balance and add it to the player's money
  bank balance := bank balance -- amount
  get money (amount)
 end
end

This simple system can store up to $2147483647 of your hard-earned cash, which will generally be more than anyone could possibly need. If you're expecting your players to be able to become multibillionaires, you'll need to write your own math functions for working with excessively large numbers. Conversely, you can set max savings to something lower if you don't want the player's funds to be able to go quite that high.

The somewhat harder part: money storage in-game[edit]

Now, to actually use that bank system, you need to make a user interface for it that the player can access. There are several ways to do this, but here's what I (Andrusi) came up with:

  • First, add a tag to your RPG. Call it Withdraw.
  • Next, you'll need to create a total of three text boxes. The first text box is some kind of entry for your bank function. For instance:
Welcome to Geable National Bank!
How may I help you today, sir?

This text box needs to have a choice. One of the options should be along the lines of "Withdraw" and turn tag:Withdraw on. The other should be "Deposit" and turn tag:Withdraw off.

  • The second text box is your input screen for a withdrawal. It can look like whatever, but it should have ${V63} (your bank money) and ${V64} (your current money) in it. For example:
Withdraw from Savings
          Current Balance: ${V63}
             Cash On Hand: ${V64}
  Enter Withdrawal Amount:

  • The third and final text box is just the withdraw screen reworked to refer to deposits. This isn't strictly necessary--you can use plotscripting to make one box do both--but I think doing it this way is slightly easier to follow.
Deposit into Savings
          Current Balance: ${V63}
             Cash On Hand: ${V64}
     Enter Deposit Amount:

  • Next, you'll want to export an HSI file. You can do this under Script Management.
  • Now you need to add the bank plotscript and globals to your plotscript file. For your convenience, I have here a complete file that you can use, or you can just copy the globals, constants, and scripts into your existing HSS file (check to make sure you aren't already using global variables 63 and 64 and string 1, and change the numbers if necessary--don't forget to update your text boxes to match). Make sure you use the real numbers of your text boxes for the constants rather than 81, 82, and 83 like I used here.
include, mygame.hsi	# change this to the actual name of your HSI file

# You can change the numbers on these two global variables
# if you want.  They aren't particularly important. You'll
# have to change your RPG file accordingly, though.

global variable (63, bank balance)		# variable to store your money
global variable (64, gold var)			# variable to display party money

# These are the text boxes mentioned above.
# You should change 81, 82, and 83 to the numbers
# of the corresponding text boxes in your game.
define constant (81, bank ask box)		#"Welcome to Geable National Bank!"
define constant (82, withdraw box)		#"Withdrawal from Savings"
define constant (83, deposit box)		#"Deposit into Savings"

# This is the maximum amount of money the bank is willing to hold at once.
# The highest amount you can set this to is $2147483647. We'll set it to
# $9,999,999 for the purpose of this example.
define constant (9999999, max savings)

# This is the maximum amount of digits that can be in the amount of
# money the player is depositing or withdrawing in a single transaction.
# If it's 1, the player can deposit up to $9 at once. If it's 2, the
# maximum deposit at once is $99. If you want it to be "unlimited" you
# should set this to the number of digits in max savings. For this example
# we're setting it to 5, so the player can make a single deposit of up
# to $99,999.
define constant (5, max digits)

# Finally, this is the ID for a string that will be used when the player
# enters the amount of money they want to withdraw or deposit. If you're
# already using string ID 1 for something else, you should change this.
define constant (1, bank string)

# Script to deposit money in the bank.
script, deposit, amount=0, begin
 # check to make sure this deposit won't exceed the maximum bank balance and the player
 # actually has the amount of money they're depositing
 if (((max savings -- bank balance) >= amount) && pay money (amount)) then, begin
  # pay money (amount) already removed the money from the player's cash on hand so
  # just add it to the bank balance
  bank balance := bank balance + amount
 end
end

# Script to withdraw money from the bank.
script, withdraw, amount=0, begin
 # check to make sure the requested money actually exists in the bank and that this
 # withdrawal won't pass OHR's built-in limit on the player's money.
 if (((2000000000 -- party money) >= amount) && bank balance >= amount) then, begin
  # remove money from bank balance and add it to the player's money
  bank balance := bank balance -- amount
  get money (amount)
 end
end

# Script to allow the player to use the bank functions.
plotscript, bank script, begin
 variable (which box)   	#which text box to show
 variable (transact)		#amount of money in player's transaction
 
 #get current amount of money
 gold var := party money

 show text box (bank ask box)	#ask the player what he wants to do
 wait for text box		#wait for the player to make a choice

 # figure out which text box to display.
 if (check tag(tag:Withdraw)) then (which box := withdraw box)
   else (which box := deposit box)

 # display the text box
 show text box (which box)
 suspend box advance
 
 # now, get text input from the player. there are several ways to
 # do this, but for this example we'll use the "input string"
 # function. we set "use current" to false so the input will start
 # out blank, "center" to false so that the numbers appear normally
 # as typed instead of spreading out from a central point. 217, 38
 # is right after "Enter (whichever) Amount:" in the example text
 # boxes; if you've written different text you'll want to adjust
 # those coordinates to match.
 
 input string (bank string, max digits, false, false, 217, 38)
 
 # clear out the text box from earlier
 advance text box
 resume box advance
 
 # now we have a string that hopefully contains a number. let's
 # convert that into an actual number. if the player entered
 # something other than a number for some cockamamie reason,
 # interpret that as 0.
 transact := number from string (bank string, 0)
 
 # now actually do the withdrawal/deposit. the withdraw and deposit
 # functions already have their own built-in checks to make sure the
 # amount is valid, and withdrawing or depositing 0 doesn't do
 # anything, so we don't need to do any further checking.
 if (check tag(tag:Withdraw)) then (withdraw(transact))
   else (deposit(transact))
end
  • Compile the script with HSPEAK, and import it into your RPG file in CUSTOM.
  • Make an NPC who call the "bank script" plotscript when activated.

This is a very simple and bare-bones interface. If you're feeling spicy, it would be relatively easy to expand it to, say, display error messages when the player tries to deposit or withdraw more money than they actually have.

If you're feeling extra spicy, you could also have other scripts that do various things to your money in the bank when you're not paying attention. Pokémon Gold, Silver, and Crystal versions had a feature where the player's mother acted as a "bank," but occasionally she would go out and buy things with your money. Conversely, you could have the player accumulate interest on their bank funds as the story progresses. You could even have an event where the bank gets robbed...

The really hard part: item storage[edit]

Making a bank that can store items is conceptually similar, but you'll need a much larger number of global variables (instead of "bank balance" you need a variable for every type of item that can be stored), and you'll need some way to let the player select a particular item. See How do I make a chest in which I can store items and get them back later? for more information on this.


See Also[edit]