PDA

View Full Version : [Essentials script] Bank Script


Black Eternity
April 9th, 2013, 01:07 AM
Okay here I am going to show you how to make a banking system for players to store more money than they can carry. :P

First create a new script section, let's call this PokemonBank for organizing purposes.
Add this script:
#This script is for storing the players money in a bank.

def pbDepositBank
params=ChooseNumberParams.new
params.setMaxDigits(9)
params.setRange(MINDEPOSIT,$Trainer.money) #sets min/max deposit from MINDEPOSIT to what the player has on hand
params.setInitialValue($Trainer.money) #sets the value to what the player has on hand
params.setCancelValue(0)
if $Trainer.money<MINDEPOSIT #checks if the player has less money than MINDEPOSIT
Kernel.pbMessage(
_INTL("\\G\\XVSorry you must have at least ${1} to deposit.",MINDEPOSIT)) #not enough to deposit
elsif pbGet(14)==MAXBANK#checks if the bank amount is full
Kernel.pbMessage(
_INTL("\\G\\XVYour Bank Account is full, you can not deposit any more money.")) #\\XV shows the bankwindow when picking amount
elsif $Trainer.money>=MINDEPOSIT#checks if player has more money than MINDEPOSIT
qty=Kernel.pbMessageChooseNumber(
_INTL("\\G\\XVHow much would you like to deposit?"),params) #choose deposit amount
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) #adds money to bank
$Trainer.money=$Trainer.money-qty #subtracts money from player
end
end
end

def pbWithdrawBank
params=ChooseNumberParams.new
params.setMaxDigits(9)
params.setRange(1,pbGet(14)) #sets range from 1 to how much the player has in the bank
params.setInitialValue(pbGet(14)) #sets value to how much the player has in the bank
params.setCancelValue(0)
maxqty=MAXMONEY-$Trainer.money
if pbGet(14)==0 #checks if you have no money in the bank
Kernel.pbMessage(
_INTL("\\G\\XVYou do not have any money to withdraw.")) #no money in bank
elsif pbGet(14)>0#checks if you have money in the bank
qty=Kernel.pbMessageChooseNumber(
_INTL("\\G\\XVHow much would you like to withdraw?"),params) #\\XV shows the bankwindow when picking amount
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) #subtracts money from bank
$Trainer.money=$Trainer.money+qty #adds money to player
end
end
end

Next go to Settings
And define these somewhere:

MAXBANK = 999999999
MINDEPOSIT = 500


Next go to PokemonMessages
Around line 1267 is pbDisplayCoinsWindow, after this function, place this code:

def pbDisplayBankWindow(msgwindow,goldwindow)
bankString=$game_variables[016]
bankwindow=Window_AdvancedTextPokemon.new(_INTL("Bank:\n<ar>${1}</ar>",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 go to line #1329 (coinswindow=nil)
after it add bankwindow=nil

Go to line #1498 (should look like)

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

Add this code after it:
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!

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


Go to line #1384
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 line #1584 and after it add bankwindow.dispose if bankwindow

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

That should be it.
To use these functions in an event simply call pbDepositBank and pbWithdrawBank
View the attached screenshot to see how my event is setup.

Some things to change for debug purposes (If you allow MAXBANK to be 999999999)
Change to this code in PokemonDebug:

def pbDebugSetVariable(id,diff)
pbPlayCursorSE()
$game_variables[id]=0 if $game_variables[id]==nil
if $game_variables[id].is_a?(Numeric)
$game_variables[id]=[$game_variables[id]+diff,999999999].min
$game_variables[id]=[$game_variables[id],-999999999].max
end
end

def pbDebugVariableScreen(id)
value=0
if $game_variables[id].is_a?(Numeric)
value=$game_variables[id]
end
params=ChooseNumberParams.new
params.setDefaultValue(value)
params.setMaxDigits(9)
params.setNegativesAllowed(true)
value=Kernel.pbMessageChooseNumber(_INTL("Set variable {1}.",id),params)
$game_variables[id]=[value,999999999].min
$game_variables[id]=[$game_variables[id],-999999999].max
end


Also thanks to Maruno for some help completing the script.

Elaitenstile
April 9th, 2013, 01:30 AM
Very neat tutorial, and easy to follow (even for new learners like me).

Along with the attachment, I've understood how to implement this (though I haven't tested it yet).

I think this will really help me out in implementing more uses of money, since the regular Pokémon games don't have that great uses of money.

Thanks for the script!

Black Eternity
April 11th, 2013, 04:14 PM
Very neat tutorial, and easy to follow (even for new learners like me).

Along with the attachment, I've understood how to implement this (though I haven't tested it yet).

I think this will really help me out in implementing more uses of money, since the regular Pokémon games don't have that great uses of money.

Thanks for the script!

Thank you for the feedback.... if you have any issues please let me know and I will try to resolve them as best as I can.

Rango
April 11th, 2013, 04:21 PM
Yes! This is just what I've been looking for!
Thank you for this awesome script, it was so easy to implement.

Black Eternity
April 14th, 2013, 12:22 PM
I have updated the PokemonBank with a version that has more checks.

Features added:
Checks if the player deposits more than MAXBANK, if they do, subtracts the difference.
Checks if the player withdraws more than MAXMONEY, if they do, subtracts the difference.

For example: (in my case both MAXMONEY and MAXBANK are 999999999)
Player has $999997999 in the bank, and $3000 on hand. if they try to deposit all $3000, only $2000 will be allowed, and leaves $1000 on hand.
Same for withdrawing.

EDIT 4/22/13: Updated the script a little, changed a couple things around, and used new method for variables. (pbAdd and pbSub functions)