FANDOM


Bank System
This tutorial was written by Black Eternity. Please give credit.
Click here for more tutorials!


In this tutorial I am going to show you how to add a Bank System for players to store more money than they can carry.

Basics

Okay first, we are going to add a couple of functions to make our lives easier, also add some new functions for easier scripting.

First in script section Settings add the following anywhere:

MAXBANK      = 999999999
MINDEPOSIT   = 500

Next go to PokemonMessages and search for "pbDisplayCoinsWindow". After this function, place this code:

def pbDisplayBankWindow(msgwindow,goldwindow)
  bankString=$game_variables[016]
  bankwindow=Window_AdvancedTextPokemon.new(_INTL("Bank:\n${1}",bankString))
  bankwindow.setSkin("Graphics/Windowskins/goldskin")
  bankwindow.resizeToFit(bankwindow.text,Graphics.width)
  bankwindow.width=160 if bankwindow.width<=160
  if msgwindow.y==0
    bankwindow.y=(goldwindow) ? goldwindow.y-bankwindow.height : Graphics.height-bankwindow.height
  else
    bankwindow.y=(goldwindow) ? goldwindow.height : 0
  end
  bankwindow.viewport=msgwindow.viewport
  bankwindow.z=msgwindow.z
  return bankwindow
end

Now search for "coinwindow=nil" after it add "bankwindow=nil". Around line #1498 you should find:

elsif control=="cn" # Display coins window
          coinwindow.dispose if coinwindow
          coinwindow=pbDisplayCoinsWindow(msgwindow,goldwindow)

Add this code after it:

elsif control=="xv" #Display bank window
          bankwindow.dispose if bankwindow
          bankwindow=pbDisplayBankWindow(msgwindow,goldwindow)

The "xv" is the message code that will be used to open the window, you can change it to whatever you want but must be unique!

Find "\\([Gg]|[Cc][Nn]|[Ww][Dd]|[Ww][Mm]|" and change to

\\([Gg]|[Cc][Nn]|[Xx][Vv]|[Ww][Dd]|[Ww][Mm]|

or whatever letter combination you have chosen, you can use one letter by simply typing [Xx]| but dont forget to change the above code to match it.

Go to the bottom of PokemonMessages, and around line #1584 you should see "coinwindow.dispose if coinwindow". Put "bankwindow.dispose if bankwindow" underneath that.

Also the last part for PokemonMessages add these two functions after "pbSet":

# Adds to the value of a variable.
def pbAdd(id,value)
  if id && id>=0
    $game_variables[id]=$game_variables[id]+value if $game_variables
    $game_map.need_refresh = true if $game_map
  end
end

# Subtracts from the value of a variable.
def pbSub(id,value)
  if id && id>=0
    $game_variables[id]=$game_variables[id]-value if $game_variables
    $game_map.need_refresh = true if $game_map
  end
end

Bank Script

I had you do all that stuff first, so when testing your new bank script everything would work as planned.

#These are the two scripts for depositing and withdrawing from a bank.

def pbDepositBank
  params=ChooseNumberParams.new
  params.setMaxDigits(9)
  params.setRange(MINDEPOSIT,$Trainer.money)
  params.setInitialValue($Trainer.money)
  params.setCancelValue(0)
  if $Trainer.money<MINDEPOSIT
    Kernel.pbMessage(
      _INTL("\\G\\XVSorry you must have at least ${1} to deposit.",MINDEPOSIT))
  elsif pbGet(14)==MAXBANK
    Kernel.pbMessage(
      _INTL("\\G\\XVYour Bank Account is full, you can not deposit any more money."))
  elsif $Trainer.money>=MINDEPOSIT
    qty=Kernel.pbMessageChooseNumber(
      _INTL("\\G\\XVHow much would you like to deposit?"),params)
    maxqty=MAXBANK-pbGet(14)
      if qty>maxqty
        newqty=MAXBANK-pbGet(14)
        Kernel.pbMessage(
          _INTL("\\G\\XVYou are only allowed to deposit ${1}.",newqty))
        pbAdd(14,newqty)
        $Trainer.money=$Trainer.money-newqty
      else
        pbAdd(14,qty)
        $Trainer.money=$Trainer.money-qty
      end
  end
end

def pbWithdrawBank
  params=ChooseNumberParams.new
  params.setMaxDigits(9)
  params.setRange(1,pbGet(14))
  params.setInitialValue(pbGet(14))
  params.setCancelValue(0)
  maxqty=MAXMONEY-$Trainer.money
  if pbGet(14)==0
      Kernel.pbMessage(
        _INTL("\\G\\XVYou do not have any money to withdraw."))
  elsif pbGet(14)>0
    qty=Kernel.pbMessageChooseNumber(
      _INTL("\\G\\XVHow much would you like to withdraw?"),params)
      if qty>maxqty
        newqty=MAXMONEY-$Trainer.money
        Kernel.pbMessage(
          _INTL("\\G\\XVWe were only allowed to give you ${1}",newqty))
        pbSub(14,newqty)
        $Trainer.money=$Trainer.money+newqty
      else
        pbSub(14,qty)
        $Trainer.money=$Trainer.money+qty
      end
  end
end

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.