PDA

View Full Version : [Script] PokéUnion Bank System Script


thor348
August 23rd, 2013, 04:11 AM
Hello everyone, I have spent the past few hours developing this bank system script for my new project. I was contemplating releasing it or not because of the depth of possible detail based upon the developer discretion. When you examine the script, there are a few things I could have done to shorten it and still have it's level of functionality, but I script different than most and i'm fine with that.

*Credit Required if Used/Changed

Version 1.0


=begin
###############################################################################
***PokéUnionBank System By Thor348K***
Features Include:
Withdraw, Deposit, View Account Balance,
Interest Gain, Check Total Interest Gain
Created on 8/22/13
Future Features Will Iclude:
View Total In-Game Days With An Account
View Total In-Game Days With A Specific Account

Variables Used:
21 = Interest Gained Total
19 = Account Balance
18 = $Trainer.money
17 = Steps Taken (Defined in Game_Player_ Script)
Switches Used:
47 = \PN has Starter Account
48 = \PN has Trainer Account
49 = \PN has Master Account
50 = \PN has Legendary Account
>>>Credit Required if Used/Changed

###############################################################################
=end


###################################
# BASIC FUNCTIONS #
###################################

#Function for Withdrawing Money from your Account
def pbWithdrawMoney
params=ChooseNumberParams.new
params.setRange(0,$game_variables[19])
params.setInitialValue($game_variables[19])
params.setCancelValue(0)
qty=Kernel.pbMessageChooseNumber(
_INTL("\\bHow much do you want to withdraw?"),params
)
if qty>0
$Trainer.money+=qty
$game_variables[19]-=qty
Kernel.pbMessage(_INTL("\\b${1} was withdrawn.",qty))
Kernel.pbMessage(_INTL("\\bYou now have ${1} in your account.",$game_variables[19]))
else
Kernel.pbMessage(_INTL("\\bNo money was withdrawn."))
end
end

#Function for Depositing Money into Account
def pbDepositMoney
params=ChooseNumberParams.new
$game_variables[18]=$Trainer.money
params.setRange(0,$game_variables[18])
params.setInitialValue(0)
params.setCancelValue(0)
qty=Kernel.pbMessageChooseNumber(
_INTL("\\bHow much do you want to deposit?"),params
)
if qty>0
$Trainer.money-=qty
$game_variables[19]+=qty
Kernel.pbMessage(_INTL("\\b${1} was deposited.",qty))
Kernel.pbMessage(_INTL("\\bYou now have ${1} in your account.",$game_variables[19]))
else
Kernel.pbMessage(_INTL("\\bNothing was deposited."))
end
end

#Tells you how much you have in your Account
def pbViewMoney
Kernel.pbMessage(_INTL("\\bYou currently have ${1} in your account.",$game_variables[19]))
end

###################################
# INTEREST #
###################################

#Sets Steps that Player has taken to Zero
def pbSetupInterest
$game_variables[17]=0
steps=$game_variables[17]
end

#Tells you how many steps you have taken
def pbCheckInterest
steps=$game_variables[17]
Kernel.pbMessage(_INTL("\\bYou have taken {1} steps.",steps))
end

#Tells you how much you've made off interest
def pbInterestGain
total=$game_variables[21]
Kernel.pbMessage(_INTL("\\bYou've made ${1} from your interest rate!",total))
end

#Calculates and Adds Interest into Account
def pbCalcInterest
steps=$game_variables[17]
account=$game_variables[19]
if $game_switches[47]==true #Has Starter Account
$game_variables[17]=0
end
if account>=500 #500
if steps<=499 #499
$game_variables[19]+=0 if $game_switches[47]==true #Has Starter Account
$game_variables[19]+=0 if $game_switches[48]==true #Has Trainer Account
$game_variables[19]+=0 if $game_switches[49]==true #Has Master Account
$game_variables[19]+=0 if $game_switches[50]==true #Has Legendary Account
end
begin
if steps>=500 #500
$game_variables[19]+=0 if $game_switches[47]==true #Has Starter Account
$game_variables[19]+=5 if $game_switches[48]==true #Has Trainer Account
$game_variables[19]+=15 if $game_switches[49]==true #Has Master Account
$game_variables[19]+=50 if $game_switches[50]==true #Has Legendary Account
$game_variables[21]+=0 if $game_switches[47]==true #Has Starter Account
$game_variables[21]+=5 if $game_switches[48]==true #Has Trainer Account
$game_variables[21]+=15 if $game_switches[49]==true #Has Master Account
$game_variables[21]+=50 if $game_switches[50]==true #Has Legendary Account
$game_variables[17]-=500 #500
end
end until $game_variables[17]<=499 #499
else
account+=0
end
end

###################################
# DAYS WITH ACCOUNT #
###################################
#pbDayCountAccount = counts how many days you've had that specific account
#pbDayCountTotal = counts how many days you've had an account



Version1.1
Modified by Laureolus with help from Maruno
To be more "Plug and Play"

=begin
###############################################################################
***PokéUnionBank System By Thor348K.
Edited by Laureolus, with help from Maruno***
>>>Credit Thor348K if Used/Changed
Features Include:
Withdraw, Deposit, View Account Balance,
Interest Gain, Check Total Interest Gain
Created on 8/22/13

>>>Credit Thor348K if Used/Changed

###############################################################################
=end
class PokemonGlobalMetadata
attr_accessor :bankInterestTimer
attr_accessor :bankInterestTotal
attr_accessor :bankAccountType
attr_accessor :bankAccountBalance

def bankInterestTimer
@bankInterestTimer=0 if !@bankInterestTimer
return @bankInterestTimer
end

def bankAccountType
@bankAccountType=0 if !@bankAccountType
return @bankAccountType
end

def bankInterestTotal
@bankAccountBalance=0 if !@bankAccountBalance
return @bankAccountBalance
end

def bankAccountBalance
@bankAccountBalance=0 if !@bankAccountBalance
return @bankAccountBalance
end
end

Events.onStepTaken+=proc{
$PokemonGlobal.bankInterestTimer += 1
}
###################################
# BASIC FUNCTIONS #
###################################

#Function for Withdrawing Money from your Account
def pbWithdrawMoney
params=ChooseNumberParams.new
params.setRange(0, $PokemonGlobal.bankAccountBalance)
params.setInitialValue( $PokemonGlobal.bankAccountBalance)
params.setCancelValue(0)
qty=Kernel.pbMessageChooseNumber(
_INTL("\\bHow much do you want to withdraw?"),params
)
if qty>0
$Trainer.money+=qty
$PokemonGlobal.bankAccountBalance-=qty
Kernel.pbMessage(_INTL("\\b${1} was withdrawn.",qty))
Kernel.pbMessage(_INTL("\\bYou now have ${1} in your account.", $PokemonGlobal.bankAccountBalance))
else
Kernel.pbMessage(_INTL("\\bNo money was withdrawn."))
end
end

#Function for Depositing Money into Account
def pbDepositMoney
params=ChooseNumberParams.new
params.setRange(0,$Trainer.money)
params.setInitialValue(0)
params.setCancelValue(0)
qty=Kernel.pbMessageChooseNumber(
_INTL("\\bHow much do you want to deposit?"),params
)
if qty>0
$Trainer.money-=qty
$PokemonGlobal.bankAccountBalance+=qty
Kernel.pbMessage(_INTL("\\b${1} was deposited.",qty))
Kernel.pbMessage(_INTL("\\bYou now have ${1} in your account.", $PokemonGlobal.bankAccountBalance))
else
Kernel.pbMessage(_INTL("\\bNothing was deposited."))
end
end

#Tells you how much you have in your Account
def pbViewMoney
Kernel.pbMessage(_INTL("\\bYou currently have ${1} in your account.", $PokemonGlobal.bankAccountBalance))
end

###################################
# INTEREST #
###################################

#Sets Steps that Player has taken to Zero
def pbSetupAccount
$PokemonGlobal.bankInterestTimer=0
$PokemonGlobal.bankAccountBalance=0
$PokemonGlobal.bankAccountType=1
$PokemonGlobal.bankInterestTotal=0
end

#Tells you how many steps you have taken
def pbCheckInterestTimer
steps = $PokemonGlobal.bankInterestTimer
Kernel.pbMessage(_INTL("\\bYou have taken {1} steps.",steps))
end

#Tells you how much you've made off interest
def pbInterestEarned
total= $PokemonGlobal.bankInterestTotal
Kernel.pbMessage(_INTL("\\bYou've made ${1} from your interest rate!",total))
end

#Calculates and Adds Interest into Account
def pbCalcInterest
if $PokemonGlobal.bankAccountType == 1
a = $PokemonGlobal.bankInterestTimer/500
$PokemonGlobal.bankInterestTimer -= a*500
a = a * 5
$PokemonGlobal.bankAccountBalance+=a
elsif $PokemonGlobal.bankAccountType == 2
a = $PokemonGlobal.bankInterestTimer/500
$PokemonGlobal.bankInterestTimer -= a*500
a = a * 15
$PokemonGlobal.bankAccountBalance+=a
elsif$PokemonGlobal.bankAccountType == 3
a = $PokemonGlobal.bankInterestTimer/500
$PokemonGlobal.bankInterestTimer -= a*500
a = a *30
$PokemonGlobal.bankAccountBalance+=a
else
a = $PokemonGlobal.bankInterestTimer/500
$PokemonGlobal.bankInterestTimer -= a*500
a= a *50
$PokemonGlobal.bankAccountBalance+=a
end

end

###################################
# DAYS WITH ACCOUNT #
###################################
#pbDayCountAccount = counts how many days you've had that specific account
#pbDayCountTotal = counts how many days you've had an account

lauerolus
August 23rd, 2013, 05:23 AM
Are you sure your interest methods work? I had to rework the step counter myself. Otherwise thank you for sharing this, I'm going to use it myself!

I also removed the reliance on switches.

Bank script

=begin
###############################################################################
***PokéUnionBank System By Thor348K*** >>>Credit Required if Used/Changed
Features Include:
Withdraw, Deposit, View Account Balance,
Interest Gain, Check Total Interest Gain
Created on 8/22/13
Future Features Will Iclude:
View Total In-Game Days With An Account
View Total In-Game Days With A Specific Account
>>>Credit Required if Used/Changed
Variables Used:
30 = Interest Gained Total
29 = Account Balance
18 = $Trainer.money
31 = Steps Taken (Defined in Game_Player_ Script)
28 = account type
Switches Used:
22 = 1 is \PN has Starter Account
22 = 2 is has Trainer Account
22 = 3 is \PN has Master Account
22 = 4 \PN has Legendary Account


###############################################################################
=end


###################################
# BASIC FUNCTIONS #
###################################

#Function for Withdrawing Money from your Account
def pbWithdrawMoney
params=ChooseNumberParams.new
params.setRange(0,$game_variables[29])
params.setInitialValue($game_variables[29])
params.setCancelValue(0)
qty=Kernel.pbMessageChooseNumber(
_INTL("\\bHow much do you want to withdraw?"),params
)
if qty>0
$Trainer.money+=qty
$game_variables[29]-=qty
Kernel.pbMessage(_INTL("\\b${1} was withdrawn.",qty))
Kernel.pbMessage(_INTL("\\bYou now have ${1} in your account.",$game_variables[29]))
else
Kernel.pbMessage(_INTL("\\bNo money was withdrawn."))
end
end

#Function for Depositing Money into Account
def pbDepositMoney
params=ChooseNumberParams.new
$game_variables[18]=$Trainer.money
params.setRange(0,$game_variables[18])
params.setInitialValue(0)
params.setCancelValue(0)
qty=Kernel.pbMessageChooseNumber(
_INTL("\\bHow much do you want to deposit?"),params
)
if qty>0
$Trainer.money-=qty
$game_variables[29]+=qty
Kernel.pbMessage(_INTL("\\b${1} was deposited.",qty))
Kernel.pbMessage(_INTL("\\bYou now have ${1} in your account.",$game_variables[29]))
else
Kernel.pbMessage(_INTL("\\bNothing was deposited."))
end
end

#Tells you how much you have in your Account
def pbViewMoney
Kernel.pbMessage(_INTL("\\bYou currently have ${1} in your account.",$game_variables[29]))
end

###################################
# INTEREST #
###################################

#Sets Steps that Player has taken to Zero
def pbSetupInterest
$game_variables[31]=0
end

#Tells you how many steps you have taken
def pbCheckInterest
steps = $game_variables[31]
Kernel.pbMessage(_INTL("\\bYou have taken {1} steps.",steps))
end

#Tells you how much you've made off interest
def pbInterestGain
total=$game_variables[30]
Kernel.pbMessage(_INTL("\\bYou've made ${1} from your interest rate!",total))
end

#Calculates and Adds Interest into Account
def pbCalcInterest
if $game_variables[28]==1 #Has Starter Account
$game_variables[31]=0
end
if $game_variables[29]>=500 #500
if $game_variables[31]<=499 #499
$game_variables[29]+=0 if $game_variables[28]==1 #Has Starter Account
$game_variables[29]+=0 if $game_variables[28]==2 #Has Trainer Account
$game_variables[29]+=0 if $game_variables[28]==3 #Has Master Account
$game_variables[29]+=0 if $game_variables[28]==4 #Has Legendary Account
end
begin
if $game_variables[31]>=500 #500
$game_variables[29]+=0 if $game_variables[28]==1 #Has Starter Account
$game_variables[29]+=5 if $game_variables[28]==2 #Has Trainer Account
$game_variables[29]+=15 if $game_variables[28]==3 #Has Master Account
$game_variables[29]+=50 if $game_variables[28]==4 #Has Legendary Account
$game_variables[30]+=0 if $game_variables[28]==1 #Has Starter Account
$game_variables[30]+=5 if $game_variables[28]==2 #Has Trainer Account
$game_variables[30]+=15 if $game_variables[28]==3 #Has Master Account
$game_variables[30]+=50 if $game_variables[28]==4 #Has Legendary Account
$game_variables[31]-=500 #500
end
end until $game_variables[31]<=499 #499
else
account+=0
end
end

###################################
# DAYS WITH ACCOUNT #
###################################
#pbDayCountAccount = counts how many days you've had that specific account
#pbDayCountTotal = counts how many days you've had an account

Game_Player
def move_down(turn_enabled = true)
if turn_enabled
turn_down
end
if passable?(@x, @y, 2)
return if pbLedge(0,1)
return if pbEndSurf(0,1)
turn_down
@y += 1
$PokemonTemp.dependentEvents.pbMoveDependentEvents
increase_steps
$game_variables[31]+=1
else
if !check_event_trigger_touch(@x, @y+1)
if !@bump_se || @bump_se<=0
pbSEPlay("bump"); @bump_se=10
end
end
end
end

def move_left(turn_enabled = true)
if turn_enabled
turn_left
end
if passable?(@x, @y, 4)
return if pbLedge(-1,0)
return if pbEndSurf(-1,0)
turn_left
@x -= 1
$PokemonTemp.dependentEvents.pbMoveDependentEvents
increase_steps
$game_variables[31]+=1
else
if !check_event_trigger_touch(@x-1, @y)
if !@bump_se || @bump_se<=0
pbSEPlay("bump"); @bump_se=10
end
end
end
end

def move_right(turn_enabled = true)
if turn_enabled
turn_right
end
if passable?(@x, @y, 6)
return if pbLedge(1,0)
return if pbEndSurf(1,0)
turn_right
@x += 1
$PokemonTemp.dependentEvents.pbMoveDependentEvents
increase_steps
$game_variables[31]+=1
else
if !check_event_trigger_touch(@x+1, @y)
if !@bump_se || @bump_se<=0
pbSEPlay("bump"); @bump_se=10
end
end
end
end

def move_up(turn_enabled = true)
if turn_enabled
turn_up
end
if passable?(@x, @y, 8)
return if pbLedge(0,-1)
return if pbEndSurf(0,-1)
turn_up
@y -= 1
$PokemonTemp.dependentEvents.pbMoveDependentEvents
increase_steps
$game_variables[31]+=1
else
if !check_event_trigger_touch(@x, @y-1)
if !@bump_se || @bump_se<=0
pbSEPlay("bump"); @bump_se=10
end
end
end
end

Nickalooose
August 23rd, 2013, 07:19 AM
Interesting.

Nice script, better with Lauerolus' edits.

I'm not totally sure what this script does differently to using CommonEvents... Less work, less Variables...

But nevertheless, nice Interest script and using steps too, nice touch.

Maruno
August 23rd, 2013, 09:51 AM
There's no need to fiddle with the Game_Player scripts. You can add an event procedure instead (where the "event" is "player takes a step"), which both counts steps until the next interest addition and actually adds that interest (i.e. what pbCalcInterest does, which incidentally isn't actually called anywhere so it doesn't work). Here's an existing step procedure which makes Pokémon happier that you can copy:

Events.onStepTaken+=proc{
$PokemonGlobal.happinessSteps=0 if !$PokemonGlobal.happinessSteps
$PokemonGlobal.happinessSteps+=1
if $PokemonGlobal.happinessSteps==256
for pkmn in $Trainer.party
if pkmn.hp>0 && !pkmn.egg?
pkmn.changeHappiness("walking")
end
end
$PokemonGlobal.happinessSteps=0
end
}You can include a class snippet extending PokemonGlobalMetadata so that some extra variables are included, like so:

class PokemonGlobalMetadata
attr_accessor :bankInterestTimer
attr_accessor :bankAccountType
attr_accessor :bankAccountBalance

def bankInterestTimer
@bankInterestTimer=0 if !@bankInterestTimer
return @bankInterestTimer
end

def bankAccountType
@bankAccountType=0 if !@bankAccountType
return @bankAccountType
end

def bankAccountBalance
@bankAccountBalance=0 if !@bankAccountBalance
return @bankAccountBalance
end
endAnd so on. This approach is better because it creates new variables to use, rather than rely on existing variables which the user could already be doing something else with, and is therefore more plug 'n' play.

thor348
August 23rd, 2013, 10:42 AM
Are you sure your interest methods work? I had to rework the step counter myself. Otherwise thank you for sharing this, I'm going to use it myself!


I've tested it through and through in my game so I know it fully works. I added the += in Game_Player where you did as well.


There's no need to fiddle with the Game_Player scripts. You can add an event procedure instead (where the "event" is "player takes a step"), which both counts steps until the next interest addition and actually adds that interest (i.e. what pbCalcInterest does, which incidentally isn't actually called anywhere so it doesn't work). Here's an existing step procedure which makes Pokémon happier that you can copy:

Code:
Events.onStepTaken+=proc{
$PokemonGlobal.happinessSteps=0 if !$PokemonGlobal.happinessSteps
$PokemonGlobal.happinessSteps+=1
if $PokemonGlobal.happinessSteps==256
for pkmn in $Trainer.party
if pkmn.hp>0 && !pkmn.egg?
pkmn.changeHappiness("walking")
end
end
$PokemonGlobal.happinessSteps=0
end
}
You can include a class snippet extending PokemonGlobalMetadata so that some extra variables are included, like so:

Code:
class PokemonGlobalMetadata
attr_accessor :bankInterestTimer
attr_accessor :bankAccountType
attr_accessor :bankAccountBalance

def bankInterestTimer
@bankInterestTimer=0 if !@bankInterestTimer
return @bankInterestTimer
end

def bankAccountType
@bankAccountType=0 if !@bankAccountType
return @bankAccountType
end

def bankAccountBalance
@bankAccountBalance=0 if !@bankAccountBalance
return @bankAccountBalance
end
end
And so on. This approach is better because it creates new variables to use, rather than rely on existing variables which the user could already be doing something else with, and is therefore more plug 'n' play.


I thought of doing the step counter that way, but also wanted a way to have a Global count if I ever needed another one so I decided to do it through Game_Player. And yes, I hadn't thought of creating new variables due to I wasn't going to make this script for others, but just my game relying on my preset variables/switches.
And pbCalcInterest does work. Whenever you access your account through the bank teller, there's a script which calls it from within the event. It's not done within the script but rather the event itself.

Maruno
August 23rd, 2013, 11:10 AM
I thought of doing the step counter that way, but also wanted a way to have a Global count if I ever needed another one so I decided to do it through Game_Player.
Um, what? At the end of every step the player takes, def Kernel.pbOnStepTaken is called, which in turn calls the Events.onStepTaken procedure.

If you want separate interest timers for each account (for some odd reason, given that happiness gain and poisoning all uses single timers), then you can make bankInterestTimer and the other variables be arrays rather than single numbers. This requires no changes to existing scripts, which is better.

And pbCalcInterest does work. Whenever you access your account through the bank teller, there's a script which calls it from within the event. It's not done within the script but rather the event itself.
Ah, so you just didn't tell us how to use your scripts. Pretty big omission there.

lauerolus
August 23rd, 2013, 12:06 PM
That's awesome Maruno. I should have thought of happiness/egg hatching counter.

thor348
August 23rd, 2013, 12:43 PM
Ah, so you just didn't tell us how to use your scripts. Pretty big omission there.

My sincerest apologies. Considering you can call anything basically from an event, I wouldn't have thought that pbCalcInterest would've been excluded from that category.

Maruno
August 23rd, 2013, 12:55 PM
True, we know we can call (almost) any script through events. There just aren't any indications that we're supposed to, or when to do so. A screenshot of a bank teller event would help people use your scripts.

thor348
August 23rd, 2013, 01:10 PM
True, we know we can call (almost) any script through events. There just aren't any indications that we're supposed to, or when to do so. A screenshot of a bank teller event would help people use your scripts.

I only posted half of the bank script. The other half has a concept that I haven't ever seen before in a fan game or franchise game. My Teller events include these "original" functions and I don't want them to be known until I release my new project.
But if anyone has any question on how to set this up to work properly, I'd be more than happy to help.

lauerolus
August 23rd, 2013, 01:22 PM
All in one banking class. I've taken Maruno's advice and ran with it and also learned how to use Global variables in the process. Win/win!

Thank you again thor348 for posting this.
=begin
###############################################################################
***PokéUnionBank System By Thor348K.
Edited by Laureolus, with help from Maruno***
>>>Credit Thor348K if Used/Changed
Features Include:
Withdraw, Deposit, View Account Balance,
Interest Gain, Check Total Interest Gain
Created on 8/22/13

>>>Credit Thor348K if Used/Changed

###############################################################################
=end
class PokemonGlobalMetadata
attr_accessor :bankInterestTimer
attr_accessor :bankInterestTotal
attr_accessor :bankAccountType
attr_accessor :bankAccountBalance

def bankInterestTimer
@bankInterestTimer=0 if !@bankInterestTimer
return @bankInterestTimer
end

def bankAccountType
@bankAccountType=0 if !@bankAccountType
return @bankAccountType
end

  def bankInterestTotal
    @bankAccountBalance=0 if !@bankAccountBalance
    return @bankAccountBalance
  end

def bankAccountBalance
@bankAccountBalance=0 if !@bankAccountBalance
return @bankAccountBalance
end
end

Events.onStepTaken+=proc{
$PokemonGlobal.bankInterestTimer += 1
}
###################################
# BASIC FUNCTIONS #
###################################

#Function for Withdrawing Money from your Account
def pbWithdrawMoney
params=ChooseNumberParams.new
params.setRange(0, $PokemonGlobal.bankAccountBalance)
params.setInitialValue( $PokemonGlobal.bankAccountBalance)
params.setCancelValue(0)
qty=Kernel.pbMessageChooseNumber(
_INTL("\\bHow much do you want to withdraw?"),params
)
if qty>0
$Trainer.money+=qty
$PokemonGlobal.bankAccountBalance-=qty
Kernel.pbMessage(_INTL("\\b${1} was withdrawn.",qty))
Kernel.pbMessage(_INTL("\\bYou now have ${1} in your account.", $PokemonGlobal.bankAccountBalance))
else
Kernel.pbMessage(_INTL("\\bNo money was withdrawn."))
end
end

#Function for Depositing Money into Account
def pbDepositMoney
params=ChooseNumberParams.new
params.setRange(0,$Trainer.money)
params.setInitialValue(0)
params.setCancelValue(0)
qty=Kernel.pbMessageChooseNumber(
_INTL("\\bHow much do you want to deposit?"),params
)
if qty>0
$Trainer.money-=qty
$PokemonGlobal.bankAccountBalance+=qty
Kernel.pbMessage(_INTL("\\b${1} was deposited.",qty))
Kernel.pbMessage(_INTL("\\bYou now have ${1} in your account.", $PokemonGlobal.bankAccountBalance))
else
Kernel.pbMessage(_INTL("\\bNothing was deposited."))
end
end

#Tells you how much you have in your Account
def pbViewMoney
Kernel.pbMessage(_INTL("\\bYou currently have ${1} in your account.", $PokemonGlobal.bankAccountBalance))
end

###################################
# INTEREST #
###################################

#Sets Steps that Player has taken to Zero
def pbSetupAccount
$PokemonGlobal.bankInterestTimer=0
$PokemonGlobal.bankAccountBalance=0
$PokemonGlobal.bankAccountType=1
$PokemonGlobal.bankInterestTotal=0
end

#Tells you how many steps you have taken
def pbCheckInterestTimer
steps = $PokemonGlobal.bankInterestTimer
Kernel.pbMessage(_INTL("\\bYou have taken {1} steps.",steps))
end

#Tells you how much you've made off interest
def pbInterestEarned
total= $PokemonGlobal.bankInterestTotal
Kernel.pbMessage(_INTL("\\bYou've made ${1} from your interest rate!",total))
end

#Calculates and Adds Interest into Account
def pbCalcInterest
if $PokemonGlobal.bankAccountType == 1
a = $PokemonGlobal.bankInterestTimer/500
$PokemonGlobal.bankInterestTimer -= a*500
a = a * 5
$PokemonGlobal.bankAccountBalance+=a
elsif $PokemonGlobal.bankAccountType == 2
a = $PokemonGlobal.bankInterestTimer/500
$PokemonGlobal.bankInterestTimer -= a*500
a = a * 15
$PokemonGlobal.bankAccountBalance+=a
elsif$PokemonGlobal.bankAccountType == 3
a = $PokemonGlobal.bankInterestTimer/500
$PokemonGlobal.bankInterestTimer -= a*500
a = a *30
$PokemonGlobal.bankAccountBalance+=a
else
a = $PokemonGlobal.bankInterestTimer/500
$PokemonGlobal.bankInterestTimer -= a*500
a= a *50
$PokemonGlobal.bankAccountBalance+=a
end

end

###################################
# DAYS WITH ACCOUNT #
###################################
#pbDayCountAccount = counts how many days you've had that specific account
#pbDayCountTotal = counts how many days you've had an account

thor348
August 23rd, 2013, 02:25 PM
All in one banking class. I've taken Maruno's advice and ran with it and also learned how to use Global variables in the process. Win/win!

Thank you again thor348 for posting this.
=begin
###############################################################################
***PokéUnionBank System By Thor348K.
Edited by Laureolus, with help from Maruno***
>>>Credit Thor348K if Used/Changed
Features Include:
Withdraw, Deposit, View Account Balance,
Interest Gain, Check Total Interest Gain
Created on 8/22/13

>>>Credit Thor348K if Used/Changed

###############################################################################
=end
class PokemonGlobalMetadata
attr_accessor :bankInterestTimer
attr_accessor :bankInterestTotal
attr_accessor :bankAccountType
attr_accessor :bankAccountBalance

def bankInterestTimer
@bankInterestTimer=0 if !@bankInterestTimer
return @bankInterestTimer
end

def bankAccountType
@bankAccountType=0 if !@bankAccountType
return @bankAccountType
end

  def bankInterestTotal
    @bankAccountBalance=0 if !@bankAccountBalance
    return @bankAccountBalance
  end

def bankAccountBalance
@bankAccountBalance=0 if !@bankAccountBalance
return @bankAccountBalance
end
end

Events.onStepTaken+=proc{
$PokemonGlobal.bankInterestTimer += 1
}
###################################
# BASIC FUNCTIONS #
###################################

#Function for Withdrawing Money from your Account
def pbWithdrawMoney
params=ChooseNumberParams.new
params.setRange(0, $PokemonGlobal.bankAccountBalance)
params.setInitialValue( $PokemonGlobal.bankAccountBalance)
params.setCancelValue(0)
qty=Kernel.pbMessageChooseNumber(
_INTL("\\bHow much do you want to withdraw?"),params
)
if qty>0
$Trainer.money+=qty
$PokemonGlobal.bankAccountBalance-=qty
Kernel.pbMessage(_INTL("\\b${1} was withdrawn.",qty))
Kernel.pbMessage(_INTL("\\bYou now have ${1} in your account.", $PokemonGlobal.bankAccountBalance))
else
Kernel.pbMessage(_INTL("\\bNo money was withdrawn."))
end
end

#Function for Depositing Money into Account
def pbDepositMoney
params=ChooseNumberParams.new
params.setRange(0,$Trainer.money)
params.setInitialValue(0)
params.setCancelValue(0)
qty=Kernel.pbMessageChooseNumber(
_INTL("\\bHow much do you want to deposit?"),params
)
if qty>0
$Trainer.money-=qty
$PokemonGlobal.bankAccountBalance+=qty
Kernel.pbMessage(_INTL("\\b${1} was deposited.",qty))
Kernel.pbMessage(_INTL("\\bYou now have ${1} in your account.", $PokemonGlobal.bankAccountBalance))
else
Kernel.pbMessage(_INTL("\\bNothing was deposited."))
end
end

#Tells you how much you have in your Account
def pbViewMoney
Kernel.pbMessage(_INTL("\\bYou currently have ${1} in your account.", $PokemonGlobal.bankAccountBalance))
end

###################################
# INTEREST #
###################################

#Sets Steps that Player has taken to Zero
def pbSetupAccount
$PokemonGlobal.bankInterestTimer=0
$PokemonGlobal.bankAccountBalance=0
$PokemonGlobal.bankAccountType=1
$PokemonGlobal.bankInterestTotal=0
end

#Tells you how many steps you have taken
def pbCheckInterestTimer
steps = $PokemonGlobal.bankInterestTimer
Kernel.pbMessage(_INTL("\\bYou have taken {1} steps.",steps))
end

#Tells you how much you've made off interest
def pbInterestEarned
total= $PokemonGlobal.bankInterestTotal
Kernel.pbMessage(_INTL("\\bYou've made ${1} from your interest rate!",total))
end

#Calculates and Adds Interest into Account
def pbCalcInterest
if $PokemonGlobal.bankAccountType == 1
a = $PokemonGlobal.bankInterestTimer/500
$PokemonGlobal.bankInterestTimer -= a*500
a = a * 5
$PokemonGlobal.bankAccountBalance+=a
elsif $PokemonGlobal.bankAccountType == 2
a = $PokemonGlobal.bankInterestTimer/500
$PokemonGlobal.bankInterestTimer -= a*500
a = a * 15
$PokemonGlobal.bankAccountBalance+=a
elsif$PokemonGlobal.bankAccountType == 3
a = $PokemonGlobal.bankInterestTimer/500
$PokemonGlobal.bankInterestTimer -= a*500
a = a *30
$PokemonGlobal.bankAccountBalance+=a
else
a = $PokemonGlobal.bankInterestTimer/500
$PokemonGlobal.bankInterestTimer -= a*500
a= a *50
$PokemonGlobal.bankAccountBalance+=a
end

end

###################################
# DAYS WITH ACCOUNT #
###################################
#pbDayCountAccount = counts how many days you've had that specific account
#pbDayCountTotal = counts how many days you've had an account

Very nice. Would you like me to edit the thread post so it shows this version one at the top?

lauerolus
August 23rd, 2013, 02:30 PM
That'd be no problem at all.

Maruno
August 23rd, 2013, 05:06 PM
There's no reason to not also put the contents of def pbCalcInterest into the onStepTaken procedure (and delete def pbCalcInterest). Like so:

Events.onStepTaken += proc{
if $PokemonGlobal.bankInterestTimer
$PokemonGlobal.bankInterestTimer += 1
if $PokemonGlobal.bankInterestTimer >= 500
a = [5, 15, 30, 50][$PokemonGlobal.bankAccountType - 1]
$PokemonGlobal.bankAccountBalance += a
$PokemonGlobal.bankInterestTotal += a
$PokemonGlobal.bankInterestTimer -= 500
end
end
}Way more compact, automatic addition of interest when it's earned, and a little easier to read and fiddle the numbers of.

Your code in def bankInterestTotal is wrong, by the way.

lauerolus
August 23rd, 2013, 06:09 PM
Haha, I copypasta'd bankAccountBalance when I noticed I didn't have it defined while posting it and forgot to change it, sorry sorry. At least pbSetupAccount is right! But that array magic is nice !

AS for when the interest is acquired, does it matter? I'd rather do it at the teller and have a nice message then by autostep.

Maruno
August 24th, 2013, 06:20 AM
Technically there wouldn't be a difference between adding the interest when it's earned and adding it in bulk just before accessing your account. However, having the code in the procedure means it's one less method to manually call in the teller event, thus making it more convenient to use and more plug 'n' play. It also makes much more sense to see that interest is gained in "real time" rather than in bulk when required.

Actually, if you change account types in the middle of a stretch of walking, then having the code in the procedure means the new interest rate applies immediately and only applies after the account type is changed. Otherwise you could run the risk of having the player walk a whole lot, then upgrade their account type and check their balance, which would cause pbCalcInterest to apply the higher interest rate to all that walking undeservedly. That's if you don't structure the bank teller's event correctly, which someone could do because there aren't any instructions.

lauerolus
August 24th, 2013, 07:24 AM
Stop being right all the time Maruno. I'll make an example bank teller(s) and move the code over later.