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

From OHRRPGCE-Wiki
Revise.png
This article does not meet the standard of quality we would like to have. Feel free to revise it and make it better by using the edit link at the top of the page. This tag should be removed when an editor feels it is of high quality.

The reason this article has been marked is: There are now easier ways to type in values and a command to get the amount of money the player has, and HamsterSpeak is now 32-bit and can store values greater than 32767 in a variable

Making a "bank" that stores extra money is easy enough. You just need to plotscript something along these lines:

global variable (63, bankbalance)

script, deposit, amount=0, begin
 if (pay money (amount)) then, begin
  bankbalance := bankbalance + amount
 end
end

script, withdraw, amount=0, begin
 if (bankbalance >= amount) then, begin
  bankbalance := bankbalance -- amount
  get money (amount)
 end
end

This simple system can store up to $32767 of your hard-earned cash. There's no direct way to store more than this (similar to the experience in plotscripting problem), though if you're willing to go through a lot of insanity you could probably figure out a workaround.

Now, actually using that bank system is tougher, as the player needs a way to access this bank, and OHR provides no built-in function for entering numbers. Here's what I (Andrusi) came up with:

  • You'll need to add two tags to your RPG. Call them BankInputNotDone and Withdraw.
  • Next, you'll need to make 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 needs to have ${V63} (your bank money) and ${V65} (the amount you want to withdraw) in it, and generally should have ${V64} (your current money) as well. For example:
Withdraw from Savings
 Current Balance: ${V63}
 Cash On Hand: ${V64}

 Withdraw Amount: ${V65}
  • The third and final text box is just the withdraw screen reworked to refer to deposits. This isn't strictly necessary--you can write a plotscript that'll let you use one box for both--but I decided to go ahead and do it this way.
Deposit into Savings
 Current Balance: ${V63}
 Cash On Hand: ${V64}

 Deposit Amount: ${V65}
  • 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-65 or script 82, 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 1, 2, and 3 like I used here.
# You can change the numbers on bank script and the three
# globals if you want.  They aren't particularly important.
# You'll have to change your RPG file accordingly, though.

global variable (63, bankbalance)
global variable (64, goldvar)
global variable (65, bankvar)

# These are the text boxes mentioned above.
# You should change 1, 2, and 3 to the numbers
# of the corresponding text boxes in your game.
defineconstant(1, BankAskBox)  #"Welcome to Geable National Bank!"
defineconstant(2, WithdrawBox) #"Withdrawal from Savings"
defineconstant(3, DepositBox)  #"Deposit into Savings"

script, deposit, amount=0, begin
 if (pay money (amount)) then, begin
  bankbalance := bankbalance + amount
 end
end

script, withdraw, amount=0, begin
 if (bankbalance >= amount) then, begin
  bankbalance := bankbalance -- amount
  get money (amount)
 end
end

plotscript, bank script, begin
 variable (whichbox)   #which text box to show
 variable (pressedkey) #simplify keystroke interpretation a bit
 variable (i)          #loop counter

 #get current amount of money
 #unfortunately this takes a long time if you have a lot of money
 #stops counting at 32767
 goldvar := 0
 while (goldvar <=32767,and,pay money(1)) do(goldvar += 1)
 get money (goldvar)

 bankvar := 0 #default deposit/withdrawal amount is zero

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

 if (check tag(tag:Withdraw)) then (whichbox := WithdrawBox)
  else (whichbox := DepositBox)
 #figure out which text box to use for all this

 #now, loop until we get the amount to withdraw/deposit.
 set tag(tag:BankInputNotDone, true)
 suspend box advance
 show text box (whichbox)
 while (check tag(tag:BankInputNotDone)) do, begin
  wait(1) #might need to mess with this value to avoid hypersensitivity
  #find out what key was pressed, if any
  #first, if the key was Enter, input is done
  if (key is pressed(key:ENTER)) then (set tag(tag:BankInputNotDone, false)) else, begin

   #next, if Backspace is pressed, erase the last digit
   if (key is pressed(key:BACKSPACE)) then, begin
    bankvar := bankvar/10
    advance text box         #clear the current text box...
    show text box (whichbox) #...and redisplay it, updated
   end

   #finally, otherwise, check for digits
   else, begin
    pressedkey := 0           #initially assume no key pressed
    for (i, 2, 11, 1) do (if (key is pressed(i)) then (pressedkey := i))  #top-row numbers
    for (i, 71, 82, 1) do (if (key is pressed(i)) then (pressedkey := i)) #numpad numbers

    if (pressedkey <> 0) then, begin
     #change value of bankvar appropriately
     bankvar := bankvar*10
     if ((pressedkey == key:1),or,(pressedkey == key:NUMPAD 1)) then (bankvar +=1)
     if ((pressedkey == key:2),or,(pressedkey == key:NUMPAD 2)) then (bankvar +=2)
     if ((pressedkey == key:3),or,(pressedkey == key:NUMPAD 3)) then (bankvar +=3)
     if ((pressedkey == key:4),or,(pressedkey == key:NUMPAD 4)) then (bankvar +=4)
     if ((pressedkey == key:5),or,(pressedkey == key:NUMPAD 5)) then (bankvar +=5)
     if ((pressedkey == key:6),or,(pressedkey == key:NUMPAD 6)) then (bankvar +=6)
     if ((pressedkey == key:7),or,(pressedkey == key:NUMPAD 7)) then (bankvar +=7)
     if ((pressedkey == key:8),or,(pressedkey == key:NUMPAD 8)) then (bankvar +=8)
     if ((pressedkey == key:9),or,(pressedkey == key:NUMPAD 9)) then (bankvar +=9)
     if (bankvar<<0) then (bankvar:=32767) #check for overflow
     advance text box         #clear the current text box...
     show text box (whichbox) #...and redisplay it, updated
    end
   end
  end
 end
 
 resume box advance
 if (check tag(tag:Withdraw)) then (withdraw(bankvar)) else (deposit(bankvar))
end
  • Compile the script with HSPEAK, and import it into your RPG file in CUSTOM.
  • Make an NPC who call "bank script" when activated.


Making a bank that can store items is conceptually similar. You need a bunch of global variables (bankbalance gets replaced with one variable for each item that can be stored), and you'll need some way to let the player select a particular item (the items menu won't work for this because it will only let you select items in your inventory, not in the "bank"). This task I shall leave to greater minds. I shall similarly ignore the question of how to have things happen to your money in the bank when you're not paying attention, like accumulating interest or the function in Pokémon Gold/Silver/Crystal where your mom cannot be trusted with money.

To launch the script on the game, give the bank script to an NPC and put the script argument to -1. Feel also free to add a text in which you explain that you have to key in directly the amont you want to deposit and valid the whole thing pressing enter.


See Also[edit]