The RPG Maker Resource Kit

RMRK RPG Maker Creation => RPG Maker General => General Scripting => Topic started by: Syrathor2 on May 23, 2005, 10:36:27 PM

Title: Banking Script
Post by: Syrathor2 on May 23, 2005, 10:36:27 PM
I found this script on the web earlier but don't know how to use it. Can anyone help?


# Keep_Items
#
#

module Keep_Items_Module
class Keep_Items
 class Keep_Item
   def initialize(name)
     @name = name
     @items = {}
     @weapons = {}
     @armors = {}
     @gold = 0
   end
   def add_item(item)
     @items[item.id] = [] if @items[item.id].nil?
     @items[item.id].push item
   end
   def add_weapon(item)
     @weapons[item.id] = [] if @weapons[item.id].nil?
     @weapons[item.id].push item
   end
   def add_armor(item)
     @armors[item.id] = [] if @armors[item.id].nil?
     @armors[item.id].push item
   end
   def add(item)
     case item
     when RPG::Item
       add_item item
     when RPG::Weapon
       add_weapon item
     when RPG::Armor
       add_armor item
     end
   end
   def remove_item(item)
     return if @items[item.id].nil?
     @items[item.id].pop
   end
   def remove_weapon(item)
     return if @weapons[item.id].nil?
     @weapons[item.id].pop
   end
   def remove_armor(item)
     return if @armors[item.id].nil?
     @armors[item.id].pop
   end
   def remove(item)
     case item
     when RPG::Item
       remove_item item
     when RPG::Weapon
       remove_weapon item
     when RPG::Armor
       remove_armor item
     end
   end
   def item_number(id)
     return @items[id].nil? ? 0 : @items[id].size
   end
   def weapon_number(id)
     return @weapons[id].nil? ? 0 : @weapons[id].size
   end
   def armor_number(id)
     return @armors[id].nil? ? 0 : @armors[id].size
   end
   def gold
     return @gold
   end
   def gain_item(id,num)
     (0...num).each {add_item $data_items[id]}
   end
   def gain_weapon(id,num)
     (0...num).each {add_weapon $data_weapons[id]}
   end
   def gain_armor(id,num)
     (0...num).each {add_armor $data_armors[id]}
   end
   def gain_gold(gold)
     @gold += gold
   end
   def lose_item(id,num)
     (0...num).each {remove_item $data_items[id]}
   end
   def lose_weapon(id,num)
     (0...num).each {remove_weapon $data_weapons[id]}
   end
   def lose_armor(id,num)
     (0...num).each {remove_armor $data_armors[id]}
   end
   def lose_gold(gold)
     @gold -= gold
   end
 end

 def initialize
   @keep_items = {}
 end
 def [](name)
   if @keep_items[name].nil?
     @keep_items[name] = Keep_Item.new name
   end
   return @keep_items[name]
 end
end

module Game_Party
 def keep_items
   if @keep_items.nil?
     @keep_items = Keep_Items.new
   end
   return @keep_items
 end
 def swap_keep_item(name1,name2)
   Keep_Items_Module.swap_keep_item(self,self.keep_items[name1])
   Keep_Items_Module.swap_keep_item(self.keep_items[name2],self)
 end
end

 def swap_keep_item(keep_item_a,keep_item_b)
   # アイテムを追加
   for i in 1...$data_items.size
     num = keep_item_a.item_number(i)
     if num > 0
       keep_item_b.gain_item(i,num)
       keep_item_a.lose_item(i,num)
     end
   end
   for i in 1...$data_weapons.size
     num = keep_item_a.weapon_number(i)
     if num > 0
       keep_item_b.gain_weapon(i,num)
       keep_item_a.lose_weapon(i,num)
     end
   end
   for i in 1...$data_armors.size
     num = keep_item_a.armor_number(i)
     if num > 0
       keep_item_b.gain_armor(i,num)
       keep_item_a.lose_armor(i,num)
     end
   end
   gold = keep_item_a.gold
   keep_item_b.gain_gold(gold)
   keep_item_a.lose_gold(gold)
 end
 module_function :swap_keep_item
end # module Keep_Items_Module


class Game_Party
 include Keep_Items_Module::Game_Party
end

# Keep_Items

# Scene_Framework
#
#
#

if true

#==============================================================================
# ■シーンフレームワーク
#==============================================================================
module Scene_Framework

 module Window_Menu
   NAME = 'name'
   HELP = 'help'
   PROC = 'proc'
   def add_menu(name,menu_item)
     @menu_list = [] if @menu_list.nil?
     menu_item[NAME] = name
     @menu_list.push menu_item
   end
   def menu_names
     names = []
     @menu_list.each {|menu| names.push menu[NAME]}
     return names
   end
   def menu_call(index)
     @menu_list[index][PROC].call if not @menu_list[index][PROC].nil?
   end
   def menu_help(index)
     return @menu_list[index][HELP].nil? ? '' : @menu_list[index][HELP]
   end
   def input_c
     menu_call(@index)
   end
   def start_active_window
     self.index = 0
   end
   def help_text
     return menu_help(@index)
   end
   def update_help
     @help_window.set_text help_text
   end
 end

 module Window_Module
   def buzzer_se
     # ブザー SE を演奏
     $game_system.se_play($data_system.buzzer_se)
   end
   def decision_se
     # 決定 SE を演奏
     $game_system.se_play($data_system.decision_se)
   end
   def cancel_se
     # キャンセル SE を演奏
     $game_system.se_play($data_system.cancel_se)
   end
   def cursor_se
     # カーソル SE を演奏
     $game_system.se_play($data_system.cursor_se)
   end
   def shop_se
     # ショップ SE を演奏
     $game_system.se_play($data_system.shop_se)
   end
   
   def center
     self.x = 640 / 2 - self.width / 2
     self.y = 480 / 2 - self.height / 2
   end

   def cancel?
     # B ボタンが押された場合
     if Input.trigger?(Input::B)
       cancel_se
       return true
     end
     return false
   end

   def select?
     # C ボタンが押された場合
     return Input.trigger?(Input::C)
   end

   attr_reader :input_hander

   def setup_default_input_hander
     return if not @input_hander.nil?
     @input_hander = {}
     handers = {
       Input::A => 'input_a',
       Input::B => 'input_b',
       Input::C => 'input_c',
       Input::X => 'input_x',
       Input::Y => 'input_y',
       Input::Z => 'input_z',
       Input::LEFT  => 'input_left',
       Input::RIGHT => 'input_right',
       Input::UP    => 'input_up',
       Input::DOWN  => 'input_down',
     }
     handers.each do |code,method_name|
       if not self.methods.index(method_name).nil?
         @input_hander[code] = self.method(method_name)
       end
     end
   end

   def input_b
     cancel_se
     $scene.back_window
   end

   def update_active_window
     if @input_hander.nil?
       setup_default_input_hander
     end
     input_hander.each do |code,method_name|
       if Input.repeat?(code)
         method_name.call
       end
     end
   end
 end

 class Window_YesNo < Window_Command
   include Scene_Framework::Window_Module

   attr_accessor :select_proc
   attr_accessor :cancel_proc

   def initialize
     super(100,['Select','Cancel'])
     @select_proc = nil
     @cancel_proc = nil
     center
   end
   def yes?
     return @index == 0
   end
   def no?
     return @index == 1
   end
   def update_active_window
     if cancel?
       @cancel_proc.call if not cancel_proc.nil?
       $scene.back_window
       return
     end
     if select? and no?
       @cancel_proc.call if not cancel_proc.nil?
       cancel_se
       $scene.back_window
       return
     end
     if select? and yes?
       @select_proc.call if not @select_proc.nil?
       return
     end
   end
 end

 attr_reader :windows

 #--------------------------------------------------------------------------
 # 初期化
 #--------------------------------------------------------------------------
 def initialize
   @windows = {}
   @active_windows = []
   @visible_windows = []
 end
 #--------------------------------------------------------------------------
 # ウィンドウの追加
 #--------------------------------------------------------------------------
 def add_window(name, window, visible = false)
   @windows[name] = window
   if visible
     @visible_windows.push window
   end
   update_visibility
   return window
 end
 #--------------------------------------------------------------------------
 # 次のウィンドウ
 #--------------------------------------------------------------------------
 def next_window(name)
   active_window = windows[name]
   @active_windows.push active_window
   update_activity_window_z
   if not active_window.methods.index('start_active_window').nil?
     active_window.start_active_window
   end
   update_visibility
   update_activity
 end
 #--------------------------------------------------------------------------
 # 戻る
 #--------------------------------------------------------------------------
 def back_window
   active_window = @active_windows[@active_windows.size - 1]
   if not active_window.methods.index('end_active_window').nil?
     active_window.end_active_window
   end
   @active_windows.pop
   update_visibility
   update_activity
 end
 #--------------------------------------------------------------------------
 # 表示固定ウィンドウの設定
 #--------------------------------------------------------------------------
 def set_visible_window(name,visible=true)
   if visible
     if @visible_windows.index(windows[name]).nil?
       @visible_windows.push windows[name]
     end
   else
     @visible_windows.delete windows[name]
   end
   update_visibility
 end
 #--------------------------------------------------------------------------
 # z index æ›´æ–°
 #--------------------------------------------------------------------------
 def update_activity_window_z
   z = 100
   @active_windows.each do |window|
     window.z = z
     z += 10
   end
 end
 #--------------------------------------------------------------------------
 # 表示状態更新
 #--------------------------------------------------------------------------
 def update_visibility
   windows.each_value do |window|
     window.visible = false
   end
   @visible_windows.each do |window|
     window.visible = true
   end
   @active_windows.each do |window|
     window.visible = true
   end
 end
 #--------------------------------------------------------------------------
 # アクティブ状態更新
 #--------------------------------------------------------------------------
 def update_activity
   windows.each_value do |window|
     window.active = false
   end
   active_window = @active_windows[@active_windows.size - 1]
   active_window.active = true if not active_window.nil?
 end
 #--------------------------------------------------------------------------
 # メイン初期処理
 #--------------------------------------------------------------------------
 def main_start
 end
 #--------------------------------------------------------------------------
 # メイン後処理
 #--------------------------------------------------------------------------
 def main_end
   windows.each_value do |window|
     window.dispose
   end
 end
 #--------------------------------------------------------------------------
 # ウィンドウ更新
 #--------------------------------------------------------------------------
 def update_window
   windows.each_value do |window|
     window.update if window.visible
   end
 end
 #--------------------------------------------------------------------------
 # アクティブウィンドウ処理
 #--------------------------------------------------------------------------
 def update_active_window
   if @active_windows.empty?
     $scene = Scene_Map.new
     return
   end
   active_window = @active_windows[@active_windows.size - 1]
   active_window.update_active_window
 end
 #--------------------------------------------------------------------------
 # メイン処理
 #--------------------------------------------------------------------------
 def main
   # メインスタート
   main_start
   # トランジション実行
   Graphics.transition
   # メインループ
   loop do
     # ゲーム画面を更新
     Graphics.update
     # 入力情報を更新
     Input.update
     # フレーム更新
     update
     # 画面が切り替わったらループを中断
     if $scene != self
       break
     end
   end
   # トランジション準備
   Graphics.freeze
   # メインエンド
   main_end
 end
 #--------------------------------------------------------------------------
 # フレーム更新
 #--------------------------------------------------------------------------
 def update
   # ウィンドウを更新
   update_window
   # アクティブウィンドウ処理
   update_active_window
 end
end

end

# Scene_Framework
# Scene_Keep_Item
#
#

class Scene_Keep_Item
 include Scene_Framework

 class Main_Menu < Window_Command
   include Scene_Framework::Window_Module
   def initialize
     super(160,['Storage','Remove','Cancel'])
     @menu_hander = []
     @menu_hander[0] = proc {decision_se; $scene.next_window :Item_Kind_Menu}
     @menu_hander[1] = proc {decision_se; $scene.next_window :Item_Kind_Menu}
     @menu_hander[2] = proc {cancel_se; $scene.back_window}
     center
     @help_window = $scene.windows[:Window_Help]
   end
   def start_active_window
     @index = 0
   end
   def input_c
     @menu_hander[@index].call
   end
   def push?
     return @index == 0
   end
   def pop?
     return @index == 1
   end
   def help_text
     return "" if @index == 2
     return @commands[@index]
   end
   def update_help
     @help_window.set_text(help_text)
   end
 end

 class Item_Kind_Menu < Window_Command
   include Scene_Framework::Window_Module
   def initialize
     super(160,[
       $data_system.words.item,
       $data_system.words.weapon,
       'Armor',
       'Money',
       'Cancel'
     ])
     @menu_hander = []
     @menu_hander[0] = proc {decision_se; $scene.next_window :Item_Select}
     @menu_hander[1] = proc {decision_se; $scene.next_window :Item_Select}
     @menu_hander[2] = proc {decision_se; $scene.next_window :Item_Select}
     @menu_hander[3] = proc {decision_se; $scene.next_window :Gold_Number}
     @menu_hander[4] = proc {cancel_se; $scene.back_window}
     center
     @help_window = $scene.windows[:Window_Help]
   end
   def start_active_window
     @index = 0
   end
   def input_c
     @menu_hander[@index].call
   end
   def item?
     return @index == 0
   end
   def weapon?
     return @index == 1
   end
   def armor?
     return @index == 2
   end
   def help_text
     return "" if @index == 4
     return "#{@commands[@index]}ã‚’#{$scene.windows[:Main_Menu].help_text}"
   end
   def update_help
     @help_window.set_text(help_text)
   end
 end

 #--------------------------------------------------------------------------
 # ● アイテム選択ウィンドウ
 #--------------------------------------------------------------------------
 class Item_Select < Window_Item
   include Scene_Framework::Window_Module
   def initialize
     super
     @keep_item = nil
     @help_window = $scene.windows[:Window_Help]
   end
   def input_c
     if not item.nil?
       $scene.next_window :Item_Number
     end
   end
   def item_number
     return $scene.item_number(@keep_item,item)
   end
   def start_active_window
     @index = 0
     if $scene.windows[:Main_Menu].push?
       @keep_item  = $game_party
     end
     if $scene.windows[:Main_Menu].pop?
       @keep_item  = $scene.keep_item
     end
     refresh
   end
   #--------------------------------------------------------------------------
   # ● アイテムリフレッシュ
   #--------------------------------------------------------------------------
   def refresh_items
     return if @keep_item.nil?
     # アイテムを追加
     for i in 1...$data_items.size
       if @keep_item.item_number(i) > 0
         @data.push($data_items)
       end
     end
   end
   #--------------------------------------------------------------------------
   # ● 武器リフレッシュ
   #--------------------------------------------------------------------------
   def refresh_weapons
     return if @keep_item.nil?
     for i in 1...$data_weapons.size
       if @keep_item.weapon_number(i) > 0
         @data.push($data_weapons)
       end
     end
   end
   #--------------------------------------------------------------------------
   # ● 防具リフレッシュ
   #--------------------------------------------------------------------------
   def refresh_armors
     return if @keep_item.nil?
     for i in 1...$data_armors.size
       if @keep_item.armor_number(i) > 0
         @data.push($data_armors)
       end
     end
   end
   #--------------------------------------------------------------------------
   # ● 全てリフレッシュ
   #--------------------------------------------------------------------------
   def refresh_all
     refresh_items
     refresh_weapons
     refresh_armors
   end
   #--------------------------------------------------------------------------
   # ● コンテンツリフレッシュ
   #--------------------------------------------------------------------------
   def refresh_contents
     if self.contents != nil
       self.contents.dispose
       self.contents = nil
     end
     @item_max = @data.size
     if @item_max > 0
       self.contents = Bitmap.new(width - 32, row_max * 32)
     end
   end
   #--------------------------------------------------------------------------
   # ● リフレッシュ
   #--------------------------------------------------------------------------
   def refresh
     @data = []
     item_kind_menu = $scene.windows[:Item_Kind_Menu]
     if item_kind_menu.item?
       refresh_items
     end
     if item_kind_menu.weapon?
       refresh_weapons
     end
     if item_kind_menu.armor?
       refresh_armors
     end
     refresh_contents
     draw_all
   end
   #--------------------------------------------------------------------------
   # ● 描画
   #--------------------------------------------------------------------------
   def draw_all
     # 項目数が 0 でなければビットマップを作成し、全項目を描画
     if @item_max > 0
       for i in 0...@item_max
         draw_item(i)
       end
     end
   end
   #--------------------------------------------------------------------------
   # ● 項目の描画
   #     index : 項目番号
   #--------------------------------------------------------------------------
   def draw_item(index)
     item = @data[index]
     case item
     when RPG::Item
       number = @keep_item.item_number(item.id)
     when RPG::Weapon
       number = @keep_item.weapon_number(item.id)
     when RPG::Armor
       number = @keep_item.armor_number(item.id)
     end
     self.contents.font.color = normal_color
     x = 4 + index % 2 * (288 + 32)
     y = index / 2 * 32
     rect = Rect.new(x, y, self.width / @column_max - 32, 32)
     self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
     bitmap = RPG::Cache.icon(item.icon_name)
     opacity = self.contents.font.color == normal_color ? 255 : 128
     self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24), opacity)
self.contents.font.name = $fontface
   self.contents.font.size = $fontsize
     self.contents.draw_text(x + 28, y, 212, 32, item.name, 0)
     self.contents.draw_text(x + 240, y, 16, 32, ":", 1)
     self.contents.draw_text(x + 256, y, 24, 32, number.to_s, 2)
   end
 end

 class Gold_Number < Window_InputNumber
   include Scene_Framework::Window_Module
   def initialize
     super(9)
     self.opacity = 255
     center
     @help_window = $scene.windows[:Window_Help]
   end
   def help_text
     return "#{$scene.windows[:Item_Kind_Menu].help_text}"+
       " (#{$scene.pop_keep_item.gold}#{$data_system.words.gold})"
   end
   def update
     super
     @help_window.set_text(help_text)
   end
   def input_c
     if $scene.pop_keep_item.gold < number
       buzzer_se
       return
     end
     $scene.push_keep_item.gain_gold number
     $scene.pop_keep_item.lose_gold number
     decision_se
     $scene.back_window
   end
 end
 
 class Item_Number < Window_InputNumber
   include Scene_Framework::Window_Module
   def initialize
     super(2)
     self.opacity = 255
     center
     @help_window = $scene.windows[:Window_Help]
   end
   def help_text
     item_select = $scene.windows[:Item_Select]
     item = item_select.item
     return "#{item.name} #{item_select.item_number}個"
   end
   def update
     super
     @help_window.set_text(help_text)
   end
   def input_c
     item_select = $scene.windows[:Item_Select]

     if item_select.item_number < number
       buzzer_se
       return
     end
     item = item_select.item
     if ($scene.item_number($scene.push_keep_item,item) + number) > 99
       buzzer_se
       return
     end

     item_kind_menu = $scene.windows[:Item_Kind_Menu]
     if item_kind_menu.item?
       kind_name = 'item'
     elsif item_kind_menu.weapon?
       kind_name = 'weapon'
     elsif item_kind_menu.armor?
       kind_name = 'armor'
     end

     $scene.push_keep_item.method("gain_#{kind_name}").call(item.id,number)
     $scene.pop_keep_item.method("lose_#{kind_name}").call(item.id,number)

     item_select.refresh

     decision_se
     $scene.back_window
   end
 end

 attr_reader :keep_item
 
 def initialize(name)
   super()
   @keep_item = $game_party.keep_items[name]
 end
 def main_start
   super
   window = add_window(:Window_Help,Window_Help.new,true)
   window = add_window(:Main_Menu,Main_Menu.new)
   window = add_window(:Item_Kind_Menu,Item_Kind_Menu.new)
   window = add_window(:Item_Select,Item_Select.new)
   window = add_window(:Gold_Number,Gold_Number.new)
   window = add_window(:Item_Number,Item_Number.new)
   next_window(:Main_Menu)
 end
 def push_keep_item
   main_menu = $scene.windows[:Main_Menu]
   if main_menu.push?
     return $scene.keep_item
   end
   if main_menu.pop?
     return $game_party
   end
   return nil
 end
 def pop_keep_item
   main_menu = $scene.windows[:Main_Menu]
   if main_menu.push?
     return $game_party
   end
   if main_menu.pop?
     return $scene.keep_item
   end
   return nil
 end
 def item_number(keep_item,item)
   case item
   when RPG::Item
     return keep_item.item_number(item.id)
   when RPG::Weapon
     return keep_item.weapon_number(item.id)
   when RPG::Armor
     return keep_item.armor_number(item.id)
   end
   return 0
 end

 module Event_Script
   def check_room(name)
     $scene = Scene_Keep_Item.new(name)
   end
     def check_room_run(name)
     $scene = Scene_Keep_Item.new(name)
     $scene.main
   end
 end
end

class Interpreter
 include Scene_Keep_Item::Event_Script
end

# Scene_Keep_Item

Also, do you make your own scripts?
Title: Banking Script
Post by: Tsunokiette on June 23, 2005, 12:13:16 AM
well, there needs to be a window script for it, this one says what the window does, however a window needs to exist.

you use a call script event.

Code: [Select]
def menu_call(index)
@menu_list[index][PROC].call if not
@menu_list[index][PROC].nil?
end


as of now, but it does nothing, because the window does not exist
Title: Banking Script
Post by: Da Master Alchemist on June 23, 2005, 01:36:06 AM
he's right why didn't the maker make a window....
Title: Banking Script
Post by: Plystire on June 23, 2005, 02:25:40 AM
Perhaps the script is not supposed to make a window.

Maybe if you told us what it was supposed to do, then we'd have a better understanding of what might be wrong.
Title: Banking Script
Post by: Leeroy_Jenkins on June 23, 2005, 11:03:31 AM
I'm assuming it makes a bank... considering it's called banking script...
Title: Banking Script
Post by: Plystire on June 23, 2005, 06:26:33 PM
Banks don't have to open windows. :roll:
Title: Banking Script
Post by: Tsunokiette on June 23, 2005, 07:41:43 PM
ya, but for some reason the ting does nothing, perhaps if Syrathor2 posts where he found the script, we could find how to use it

of course that's what he was doing when he made this topic... we could always ask the author of the script however. :?
Title: Banking Script
Post by: Tsunokiette on July 24, 2005, 06:10:36 PM
doi  :lol: this person created a scene, and the windows. but I'm not familiar of how to call a module scene... also, the script is not in the correct order, and he's mixing scenes with widows and such, including bad syntax...
Title: post reply
Post by: astrobrat on July 24, 2005, 07:33:42 PM
I have been looking for a banking script. Can anyone put this in order?
Title: Re: Banking Script
Post by: Abyssos on September 24, 2006, 12:30:02 PM
You don't need to use a script for a bank i've made a call event that works flawlessly. If you would like I can paste the Event image of the bank on here and you can go from there.
Title: Re: Banking Script
Post by: robot797 on September 25, 2006, 04:55:04 AM

here is a banking script only for money

if you want to call it you must make a event with a script in it that says
$scene = Scene_Bank.new
Title: Re: Banking Script
Post by: Blizzard on September 25, 2006, 10:08:43 AM
Why don´t you just make it with events? It´s a lot more simple.
Title: Re: Banking Script
Post by: robot797 on September 25, 2006, 03:03:22 PM
dis one has rent and that sort of stuf
Title: Re: Banking Script
Post by: Blizzard on September 25, 2006, 03:36:56 PM
I´d say, it´s a LITTLE bit exaggarated to make an entire script for a banking system that could have been completely done with only one common event and one variable in less than half an hour. Sorry, but that´s my opinion. And you could have added tons of other additional functions with maybe only a few more variables.
Title: Re: Banking Script
Post by: Irgna on January 13, 2007, 07:16:19 PM
This script rocks!
Title: Re: Banking Script
Post by: Irock on January 13, 2007, 08:53:41 PM
Next time put it in a code box by hitting the code box number symbol thingy... ;D