The PokéCommunity Forums  

Go Back   The PokéCommunity Forums > Creative Discussions > Game Development > Scripts & Tutorials
Sign Up Rules/FAQ Live Battle Blogs Mark Forums Read

Notices

Scripts & Tutorials This forum is for scripts and code, as well as all kinds of tutorials, software, tools and so forth. Remember to give credit!
The thread revival limit does not apply here.


Advertise here

Reply
 
Thread Tools
  #1    
Old April 9th, 2013, 01:07 AM
Black Eternity's Avatar
Black Eternity
Lord of Eternity
 
Join Date: Sep 2012
Age: 21
Gender: Male

Advertise here
Okay here I am going to show you how to make a banking system for players to store more money than they can carry.

First create a new script section, let's call this PokemonBank for organizing purposes.
Add this script:
Code:
#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:
Code:
MAXBANK      = 999999999
MINDEPOSIT   = 500
Next go to PokemonMessages
Around line 1267 is pbDisplayCoinsWindow, after this function, place this code:
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)
Code:
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!
Code:
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
Code:
# 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:
Code:
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.
Attached Thumbnails
BankEvent.jpg‎  

Last edited by Black Eternity; April 21st, 2013 at 09:03 PM.
Reply With Quote
  #2    
Old April 9th, 2013, 01:30 AM
Hoenn's Avatar
Hoenn
➜is not the last B E A C O N
 
Join Date: Feb 2013
Send a message via Skype™ to Hoenn
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!
__________________
➜deviantART

Previously known as Elaitenstile 
Reply With Quote
  #3    
Old April 11th, 2013, 04:14 PM
Black Eternity's Avatar
Black Eternity
Lord of Eternity
 
Join Date: Sep 2012
Age: 21
Gender: Male
Quote:
Originally Posted by ★Hoenn★ View Post
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.
Reply With Quote
  #4    
Old April 11th, 2013, 04:21 PM
Rango's Avatar
Rango
Show Me The Money Wide Load!
 
Join Date: Apr 2013
Location: Australia
Age: 19
Gender: Male
Nature: Naive
Yes! This is just what I've been looking for!
Thank you for this awesome script, it was so easy to implement.
__________________
Reply With Quote
  #5    
Old April 14th, 2013, 12:22 PM
Black Eternity's Avatar
Black Eternity
Lord of Eternity
 
Join Date: Sep 2012
Age: 21
Gender: Male
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)
Attached Thumbnails
BankScreenies.jpg‎  

Last edited by Black Eternity; April 22nd, 2013 at 01:10 PM.
Reply With Quote
Reply
Quick Reply

Sponsored Links


Advertise here
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Minimum Characters Per Post: 25



All times are UTC -8. The time now is 01:04 PM.


Style by Nymphadora, artwork by Sa-Dui.
Like our Facebook Page Follow us on Twitter © 2002 - 2014 The PokéCommunity™, pokecommunity.com.
Pokémon characters and images belong to The Pokémon Company International and Nintendo. This website is in no way affiliated with or endorsed by Nintendo, Creatures, GAMEFREAK, The Pokémon Company or The Pokémon Company International. We just love Pokémon.
All forum styles, their images (unless noted otherwise) and site designs are © 2002 - 2014 The PokéCommunity / PokéCommunity.com.
PokéCommunity™ is a trademark of The PokéCommunity. All rights reserved. Sponsor advertisements do not imply our endorsement of that product or service. User generated content remains the property of its creator.