Kain Nobel
Member
I will be using this topic to troubleshoot and ask questions on my Banking Script, which is a script still in progress. (I'm not sure if this belongs here, or submitted scripts, so I chose it to be here because its unfinished and still has a couple little errors to work out.)
You call this script simply by (either in another script or a call script command).
To date, it currently contains 3 classes: Game_Bank, Window_BankStatus and Scene_Bank (and also calls Window_Command and Window_Help). There will be more added later, don't expect this script to fully work because its not done.
You call this script simply by (either in another script or a call script command).
Code:
$scene = Scene_Bank.new
To date, it currently contains 3 classes: Game_Bank, Window_BankStatus and Scene_Bank (and also calls Window_Command and Window_Help). There will be more added later, don't expect this script to fully work because its not done.
Code:
#===============================================================================
# ** Game_Bank
#-------------------------------------------------------------------------------
# This class stores and handles all data related to banking.
#===============================================================================
class Game_Bank
#[Attributes]-----------------------------------------------------------------
attr_accessor :gold
attr_accessor :checking
attr_accessor :savings
attr_accessor :credit_score
#--------------------
# * Initialize Method
#--------------------
def initialize
@gold = $game_party.gold
@checking = checking
@savings = savings
@credit_score = credit_score
end
#--------------------
# * Checking Account
#--------------------
def checking
return @checking != nil ? self : 0
end
#--------------------
# * Gain Checking
#--------------------
def gain_checking(n)
@checking = [[checking + n, 0].max, 9999999].min
end
#--------------------
# * Lose Checking
#--------------------
def lose_checking(n)
checking(-n)
end
#--------------------
# * Checking Disabled
#--------------------
def checking_disabled
return @checking <= -1 ? true : false
end
#--------------------
# * Savings Account
#--------------------
def savings
return @savings != nil ? self : 0
end
#--------------------
# * Savings Disbaled
#--------------------
def savings_disabled
return @savings <= -1 ? true : false
end
#--------------------
# * Gain Savings
#--------------------
def gain_savings(n)
@savings = [[savings + n, 0].max, 9999999].min
end
#--------------------
# * Lose Savings
#--------------------
def lose_savings(n)
savings(-n)
end
#--------------------
# * Credit SCORE
#--------------------
def credit_score
return (@gold + @checking + @savings) / 3
end
#--------------------
# * Transfer To
#--------------------
def transfer_funds(account, money)
case @account
when 0 # Checking
lose_checking(money)
gain_savings(money)
when 1 # Savings
lose_savings(money)
gain_savings(money)
else
print("Error: That account doesn't exist")
end
end
end
################################################################################
#===============================================================================
# ** Window_BankStatus
#-------------------------------------------------------------------------------
# This class displays Banking information.
#===============================================================================
class Window_BankStatus < Window_Base
#------------------------
# * Initialization Method
#------------------------
def initialize
# Create Window Offset & Size
super(ox, oy, 260, 128)
self.contents = Bitmap.new(width - 32, height - 32)
# Initialize Banking Variables
@gold = @checking = @savings = @credit_score = 0
# Call Refresh method
self.opacity = 160
update
end
#-----------------
# * Refresh Method
#-----------------
def update
# Clear page for new data
self.contents.clear
# Define Banking variables
@gold = $game_party.gold
@checking = $game_bank.checking
@savings = $game_bank.savings
@credit_score = $game_bank.credit_score
# Set System Color
self.contents.font.color = system_color
# Draw Account names
self.contents.draw_text(0, 0, 96, 36, "Gold :")
self.contents.draw_text(0, 0, 96, 72, "Checking :")
self.contents.draw_text(0, 0, 96, 106, "Savings :")
self.contents.draw_text(0, 0, 192, 140, "CreditSCORE :")
# Set Normal Color
self.contents.font.color = normal_color
# Draw Account variables
self.contents.draw_text(128, 0, 96, 36, "$" + @gold.to_s, 2)
self.contents.draw_text(128, 0, 96, 72, "$" + @checking.to_s, 2)
self.contents.draw_text(128, 0, 96, 106, "$" + @savings.to_s, 2)
self.contents.draw_text(128, 0, 96, 140, "$" + @credit_score.to_s, 2)
end
end
################################################################################
#===============================================================================
# ** Scene_Bank
#-------------------------------------------------------------------------------
# This class handles the Bank Menu functionality.
#===============================================================================
class Scene_Bank
#--------------------
# * Initialize Method
#--------------------
def initialize
# Get Bank Class
bank = Game_Bank.new
s1 = "Checking Account"
s2 = "Savings Account"
# Disabled Commands
s3 = "Credit & Loans"
# If Checking Disabled
#if checking_disabled == true
# # Disable save
# @command_window.disable_item(1)
#end
# If Savings Disabled
#if $game_bank.savings_disabled == true
# # Disable save
# @command_window.disable_item(2)
#end
# Window_Command
@window_command = Window_Command.new(192, [s1, s2, s3])
@window_command.ox = 10
@window_command.oy = (240 - @window_command.height)
@window_command.index = @menu_index
@window_command.visible = true
@window_command.active = true
# Window Transaction
@window_trans = Window_InputNumber.new
@window_trans.digits_max = 6
@window_trans.visible = false
@window_trans.active = false
# Window_BankStatus
@window_bankstat = Window_BankStatus.new
@window_bankstat.ox = (640 - @window_bankstat.x)
@window_bankstat.oy = (480 - @window_bankstat.y)
# Window_Help
@window_help = Window_Help.new
# Execute transition
Graphics.transition
# Main loop
loop do
# Update game screen
Graphics.update
# Update input information
Input.update
# Frame update
update
# Abort loop if screen is changed
if $scene != self
break
end
end
# Prepare for transition
Graphics.freeze
# Dispose of windows
@window_command.dispose
@window_trans.dispose
@window_bankstat.dispose
@window_help.dispose
end
#----------------
# * Update Method
#----------------
def update
# Update BankStatus
@window_bankstat.update
# Update Help
@window_help.update
# Update Command
if @window_command.active == true
update_command
return
end
# Update Transaction
if @window_trans.active == true
update_transaction
return
end
end
#-----------------
# * Update Command
#-----------------
def update_command
# If B button was pressed
if Input.trigger?(Input::B)
# Play Cancel SE
$game_system.se_play($data_system.cancel_se)
# Switch to map screen
$scene = Scene_Map.new
return
end
if Input.trigger?(Input::C)
# Branch by command window cursor position
case @window_command.index
when 0 # Checking Account
$game_system.se_play($data_system.decision_se)
# Switch to Checking Menu
@command_index = 0
@window_trans.active = true
@window_command.active = false
when 1 # Savings Account
$game_system.se_play($data_system.decision_se)
# Switch to Savings Menu
@command_index = 1
@window_trans.active = true
@window_command.active = false
when 2 # Credit and Loans
$game_system.se_play($data_system.decision_se)
# Switch to Credit and Loans Menu
@command_index = 2
@window_trans.active = true
@window_command.active = false
end
end
end
#---------------------
# * Update Transaction
#---------------------
def update_transaction
# If B button was pressed
if Input.trigger?(Input::B)
# Play Cancel SE
@window_command.index = @command_index
@window_command.active = true
@window_trans.active = false
$game_bank.transfer(-1, 0)
end
# If C button was pressed
if Input.trigger?(Input::C)
case @window_select.index
when 0
@select_index = 0
@window_trans.active = false
@window_command.active = false
end
end
end
end