O TEMA DO FÓRUM ESTÁ EM MANUTENÇÃO. FEEDBACKS AQUI: ACESSAR

RayRpg - Script de Banco

Iniciado por Raizen, 13/02/2013 às 18:48

SCRIPT DE BANCO
Feito por:RayRpg
Maker Utilizado: RMVX
|Versão: 1.0|


Descrição:
Esse script adiciona a opção de criar um banco para depositar e retirar dinheiro.



Funções:
.Depositar e retirar dinheiro...


Instruções:
Copie e cole o script acima do main. Para chamar crie um evento e digite o seguinte código na opção chamar scripts : $scene = Scene_Depository.new
ScreenShots







Script:
# --------------------------------------------------------------------------------------
# Script de Banco para RMVX hecho por RayRpg 
# tomando como base script de banco de KGC
# para RMXP
# para llamar script:$scene = Scene_Depository.new
#--------------------------------------------------------------------------------------
class Window_DepositoryCommand < Window_Selectable
# Nombre de los comandos
DEPOSITORY_COMMAND = [
   "Depositar",       # depósito ouro
   "Retirar",     # retirar ouro
]
# Defina los comandos
DEPOSITORY_HELP = [
   "Depositar ",   # Depositar oro
   "Retirar ",    # Retirarlo
]
end
class Window_DepositoryGold < Window_Base
# Numero de 0 maximos
GOLD_DIGITS = 7
end
class Scene_Depository
DEPOSIT_GOLD = "Insira a quantidade que será depositada"
WDEPOSIT_GOLD = "Insira a quantidade que será retirada"
end
#--------------------------------------------------------------------------
def call_depository
$game_player.straighten
$scene = Scene_Depository.new
end
#--------------------------------------------------------------------------------------
# Class Game_Party
#-------------------------------------------------------------------------------------
class Game_Party
alias initialize_Ray_Depository initialize
def initialize
   initialize_Ray_Depository
   @deposit_gold = 0
end
#--------------------------------------------------------------------------
# informacion de oro
#--------------------------------------------------------------------------
def deposit_gold
   @deposit_gold = 0 if @deposit_gold == nil
   return @deposit_gold
end
#--------------------------------------------------------------------------
# Recupere informacion del oro
#--------------------------------------------------------------------------
def gain_deposit_gold(number)
   @deposit_gold = 0 if @deposit_gold == nil
   @deposit_gold += number
end
def lose_deposit_gold(number)
   self.gain_deposit_gold(-number)
end
end
#---------------------------------------------------------------------------------
#  Window_DepositoryCommand
#---------------------------------------------------------------------------------
class Window_DepositoryCommand < Window_Selectable
def initialize
   super(0, 64, 545, 60)
   self.contents = Bitmap.new(width - 32, height - 32)
   @commands = DEPOSITORY_COMMAND
   @item_max = @commands.size
   @column_max = @commands.size
    @item_width = (width - 32) / @commands.size
   
     self.back_opacity = 160
   self.index = 0
   refresh
end
#--------------------------------------------------------------------------
# Actulizacion
#--------------------------------------------------------------------------
def refresh
   for i in 0...@commands.size
     rect = Rect.new(@item_width * i, 0, @item_width, 32)
     self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
     self.contents.font.color = system_color
     self.contents.draw_text(rect, @commands[i], 1)
   end
end
#-------------------------------------------------------------------------------- 
# Cursor
#---------------------------------------------------------------------------------
def update_cursor_rect
   if index != -1
     self.cursor_rect.set(@item_width * index, 0, @item_width, 32)
   end
end
def update_help
   @help_window.set_text(DEPOSITORY_HELP[self.index])
end
end
#--------------------------------------------------------------------------------
#  Window_DepositoryGold
#---------------------------------------------------------------------------------
class Window_DepositoryGold < Window_Base
def initialize
   super(0, 128, 545, 285)
   @digits_max = GOLD_DIGITS
   dummy_bitmap = Bitmap.new(32, 32)
   @cursor_width = dummy_bitmap.text_size("0").width + 8
   dummy_bitmap.dispose
   self.contents = Bitmap.new(width - 32, height - 32)
   self.back_opacity = 160
   self.active = false
   self.visible = false
   @cursor_position = 0
   @max = 0
   @price = 0
   @index = 0
end
def price
   return @price
end
def price=(np)
   @price = [[np, 0].max, @max].min
   redraw_price
end
def reset(type)
   @price = 0
   @index = @digits_max - 1
   refresh(type)
end
def refresh(type)
   self.contents.clear
   domination = $game_party.gold
   cx = contents.text_size(domination).width
   @cursor_position = 332 - cx - @cursor_width * @digits_max
   self.contents.font.color = system_color
   self.contents.draw_text(0, 0, 608, 32, "Dinheiro que possui:")
   self.contents.draw_text(0, 64, 608, 32, "Depósito:")
   if type == 0
     self.contents.draw_text(0, 128, 608, 32, "Quantidade:")
     @max = $game_party.gold
   else
     self.contents.draw_text(0, 128, 608, 32, "Retirada:")
     @max = [10 ** @digits_max - $game_party.gold - 1, $game_party.deposit_gold].min
   end
   self.contents.font.color = normal_color
   self.contents.draw_text(4, 32, 326 - cx, 32, $game_party.gold.to_s, 2)
   self.contents.font.color = system_color
   self.contents.draw_text(332 - cx, 32, cx, 32, domination, 2)
   self.contents.font.color = normal_color
   self.contents.draw_text(4, 96, 326 - cx, 32, $game_party.deposit_gold.to_s, 2)
   self.contents.font.color = system_color
   self.contents.draw_text(332 - cx, 96, cx, 32, domination, 2)
   redraw_price
end
def redraw_price
   domination = $game_party.gold
   cx = contents.text_size(domination).width
   self.contents.fill_rect(0, 160, 608, 32, Color.new(0, 0, 0, 0))
   self.contents.font.color = normal_color
   text = sprintf("%0#{@digits_max}d", self.price)
   for i in 0...text.length
     x = @cursor_position + (i - 1) * @cursor_width
     self.contents.draw_text(x, 160, 32, 32, text[i, 1], 2)
   end
   self.contents.font.color = system_color
   self.contents.draw_text(332 - cx, 160, cx, 32, domination, 2)
end
#--------------------------------------------------------------------------
# Actualizacion del cursor
#--------------------------------------------------------------------------
def update_cursor_rect
   x = @cursor_position + @index * @cursor_width
   self.cursor_rect.set(x, 160, @cursor_width, 32)
end
def update
   super
   return unless self.active
   if Input.repeat?(Input::UP) || Input.repeat?(Input::DOWN)
     Sound.play_decision
     place = 10 ** (@digits_max - 1 - @index)
     n = self.price / place % 10
     self.price -= n * place
     n = (n + 1) % 10 if Input.repeat?(Input::UP)
     n = (n + 9) % 10 if Input.repeat?(Input::DOWN)
     self.price += n * place
   end
   if Input.repeat?(Input::RIGHT)
     if @digits_max >= 2
       Sound.play_decision     
       @index = (@index + 1) % @digits_max
     end
   end
   if Input.repeat?(Input::LEFT)
     if @digits_max >= 2
       Sound.play_decision
       @index = (@index + @digits_max - 1) % @digits_max
     end
   end
   update_cursor_rect
end
end
def item
   return @data[self.index]
end
#--------------------------------------------------------------------------------
#  Window_DepositoryNumber
#-------------------------------------------------------------------------------
class Window_DepositoryNumber < Window_Base
def initialize
   @digits_max = 2
   @number = 0
   dummy_bitmap = Bitmap.new(32, 32)
   @cursor_width = dummy_bitmap.text_size("0").width + 8
   dummy_bitmap.dispose
   @default_size = @cursor_width * @digits_max + 32
   super(0, 0, @default_size, 128)
   self.contents = Bitmap.new(width - 32, height - 32)
   self.z = 1000
   self.back_opacity = 160
   self.active = false
   self.visible = false
   @index = 0
   @item = nil
   refresh
   update_cursor_rect
end
#-------------------------------------------------------------------------
# Actualizacion del cursor
#--------------------------------------------------------------------------
def update_cursor_rect
   self.cursor_rect.set(@index * @cursor_width, 32, @cursor_width, 32)
end
def refresh
   self.contents.fill_rect(0, 32, width - 32, 32, Color.new(0, 0, 0, 0))
   self.contents.font.color = normal_color
   s = sprintf("%0*d", @digits_max, @number)
   for i in 0...@digits_max
     self.contents.draw_text(i * @cursor_width + 4, 32, 32, 32, s[i,1])
   end
end
def set_text(string = " ")
   self.resize(self.contents.text_size(string).width + 40)
   self.contents.fill_rect(0, 0, width - 32, 32, Color.new(0, 0, 0, 0))
   self.contents.font.color = normal_color
   self.contents.draw_text(0, 0, width - 32, 32, string, 1)
   refresh
   centering
end
def resize(nw)
   self.width = nw
   buf = self.contents.dup
   self.contents.dispose
   self.contents = Bitmap.new(nw - 32, 96)
   self.contents.blt(0, 0, buf, buf.rect)
   buf.dispose
end
#-------------------------------------------------------------------------
# Movimiento central
#--------------------------------------------------------------------------
def centering
   self.x = 320 - self.width / 2
   self.y = 240 - self.height / 2
end
#-------------------------------------------------------------------------
# Actualizacion
#--------------------------------------------------------------------------
def update
   super
   return unless self.active
   if Input.repeat?(Input::UP) || Input.repeat?(Input::DOWN)
     $game_system.se_play($data_system.cursor_se)
     place = 10 ** (@digits_max - 1 - @index)
     n = self.number / place % 10
     self.number -= n * place
     n = (n + 1) % 10 if Input.repeat?(Input::UP)
     n = (n + 9) % 10 if Input.repeat?(Input::DOWN)
     self.number += n * place
     refresh
   end
   if Input.repeat?(Input::RIGHT)
     if @digits_max >= 2
       $game_system.se_play($data_system.cursor_se)
       @index = (@index + 1) % @digits_max
     end
   end
   if Input.repeat?(Input::LEFT)
     if @digits_max >= 2
        Sound.play_decision
       @index = (@index + @digits_max - 1) % @digits_max
     end
   end
   update_cursor_rect
end
end
#---------------------------------------------------------------------------------
#  Scene_Depository
#---------------------------------------------------------------------------------
class Scene_Depository
def main
   @spriteset = Spriteset_Map.new
   @dummy_window = Window_Base.new(0, 60, 545, 352)
   @help_window = Window_Help.new
   @dummy_window.back_opacity = 160
   @help_window.back_opacity = 160
   @command_window = Window_DepositoryCommand.new
   @gold_window = Window_DepositoryGold.new
   @number_window = Window_DepositoryNumber.new
   @command_window.help_window = @help_window
   Graphics.transition
   loop do
     Graphics.update
     Input.update
     update
     if $scene != self
       break
     end
   end
   Graphics.freeze
   @spriteset.dispose
   @dummy_window.dispose
   @help_window.dispose
   @command_window.dispose
   @gold_window.dispose
   @number_window.dispose
end
#------------------------------------------------------------------------
# Actualizacion
#--------------------------------------------------------------------------
def update
   @dummy_window.update
   @help_window.update
   @command_window.update
   @gold_window.update
   @number_window.update
   if @command_window.active
     update_command
     return
   end
   if @gold_window.active
     update_gold
     return
   end
  if @number_window.active
     update_number
     return
   end
end
def update_command
   if Input.trigger?(Input::B)
   Sound.play_decision
     $scene = Scene_Map.new
     return
   end
   if Input.trigger?(Input::C)
     Sound.play_decision
     case @command_window.index
     when 0
       @gold_window.active = true
       @gold_window.visible = true
       @gold_window.reset(0)
       @help_window.set_text(DEPOSIT_GOLD)
     when 1
       @gold_window.active = true
       @gold_window.visible = true
       @gold_window.reset(1)
       @help_window.set_text(WDEPOSIT_GOLD)
     when 2
       @item_window.active = true
       @item_window.visible = true
       @item_window.refresh(0)
     when 3
       @item_window.active = true
       @item_window.visible = true
       @item_window.refresh(1)
     end
     @command_window.active = false
     @dummy_window.visible = false
     return
   end
end
def update_gold
   if Input.trigger?(Input::B)
     Sound.play_decision
     @command_window.active = true
     @gold_window.active = false
     @gold_window.visible = false
     @dummy_window.visible = true
     return
   end
   if Input.trigger?(Input::C)
     price = @gold_window.price
     if price == 0
      Sound.play_decision
       @command_window.active = true
       @gold_window.active = false
       @gold_window.visible = false
       @dummy_window.visible = true
       return
     end
    Sound.play_decision
     case @command_window.index
     when 0
       $game_party.lose_gold(price)
       $game_party.gain_deposit_gold(price)
     when 1
       $game_party.gain_gold(price)
       $game_party.lose_deposit_gold(price)
     end
     @gold_window.reset(@command_window.index)
     return
   end
end
def update_number
   if Input.trigger?(Input::B)
   Sound.play_decision
     @number_window.active = false
     @number_window.visible = false
     return
   end
     @number_window.active = false
     @number_window.visible = false
     return
   end
end



Créditos

RayRpg tomando como base o script de banco de KGC para RMXP;
E a Yoshi (se quiserem), por criar a demo traduzir algumas partes e disponibilizar.