Help with Alchemy Script

Started by elmangakac, August 12, 2009, 10:46:20 am

Previous topic - Next topic

elmangakac

 :^_^': Hello guys.... here is the deal...

 #-------------------------------------------------------------------------
# Script de alquimia
#-------------------------------------------------------------------------
#  - Versión: 1.1
#  - Autor: Alnain (no son necesarios créditos)
#  - Creado: 11 - 9 - 08 (dd - mm - aa)
#  - Instrucciones:
#     · Pegar encima de main.
#     · Para ir a la pantalla de alquimia usa lo siguiente en un llamar
#     script: $scene = Scene_Alquimia.new.
#     · Selecciona el atributo ingrediente para los objetos que quieras que
#     combinables
#     · Edita la parte editabe a tu gusto.

class Scene_Alquimia # no editar esta línea
  #-------------------------------------------------------------------------
  #----EDITABLE DESDE AQUI -------------------------------------------------
  #-------------------------------------------------------------------------
  def initialize
   
  # Id del atributo "Ingrediente" (editable)
  $atr_ingrediente = 17
 
  #---Combinaciones-----
  @combinaciones = { # no editar esta línea
 
  # Las comabinaciones se definen así:
  #
  # [ingrediente, ingrediente, ingrediente] => [resultado, resultado],
  #
  # La última combinación no debe llevar la coma al final.
  # Ingrediente y resultado son IDs de objetos en la base de datos.
  # Puedes crear tantas combinaciones como quieras.
  # Puedes añadir tantos ingredientes como quieras a cada combinación.
  # Puedes añadir tantos resultados como quieras a cada combinación.
 
  [33, 34] => [11, 11],
  [35, 37] => [15, 22],
  [34, 38, 39] => [12],
  [35, 37, 40] => [13]
 
  } # no editar esta línea
 
  #-------------------------------------------------------------------------
  #----EDITABLE HASTA AQUI -------------------------------------------------
  #-------------------------------------------------------------------------
end
  def main
   @items_window = Window_Items.new
   @items_window.y = 64
   @mezcla_window = Window_Mezcla.new
   @mezcla_window.x = 320
   @mezcla_window.y = 64
   @mezcla_window.active = false
   @command_window = Window_Inst.new
   @command_window.x = 320
   @command_window.y = 384
   @info_window = Window_Info.new
   @info_window.x = 320 - @info_window.width / 2
   @info_window.y = 240 - @info_window.height / 2
   @info_window.z = 9999
   @info_window.visible = false
   @info_window.set_info
   @description_window = Window_Help.new
   if not @items_window.item.nil?
     @description_window.set_text (@items_window.item.description)
   end

   Graphics.transition
   loop do
     Graphics.update
     Input.update
     update
     if $scene != self
      break
     end
   end
   Graphics.freeze
   #disposes
   @items_window.dispose
   @mezcla_window.dispose
   @command_window.dispose
   @description_window.dispose
  end
 
  def update
   @items_window.update
   @mezcla_window.update
   
     if @items_window.active
      if not @items_window.item.nil?
        @description_window.set_text (@items_window.item.description)
      else
        @description_window.set_text ("")
      end
     else
      if not @mezcla_window.item.nil?
        item = $data_items[@mezcla_window.item]
        @description_window.set_text (item.description)
      else
        @description_window.set_text ("")
      end
     end

   if Input.trigger? (Input::LEFT)
     if @mezcla_window.active
      @mezcla_window.active = false
      @items_window.active = true
     end
   elsif Input.trigger? (Input::RIGHT)
     if @items_window.active
      @mezcla_window.active = true
      @items_window.active = false
     end
   end
   
   if Input.trigger? (Input::C)
     if @items_window.active and not @items_window.item.nil?
      @mezcla_window.añadir_ingrediente (@items_window.item.id)
      @mezcla_window.refresh
      $game_party.lose_item (@items_window.item.id, 1)
      @items_window.index = [0, @items_window.index - 1].max
      @items_window.refresh
     elsif @mezcla_window.active and not @mezcla_window.item.nil?
      $game_party.gain_item (@mezcla_window.item, 1)
      @items_window.refresh
      @mezcla_window.quitar_ingrediente
      @mezcla_window.index = [0, @mezcla_window.index - 1].max
      @mezcla_window.refresh
     else
      @items_window.active = true
      @info_window.visible = false
     end
   end
   
   if Input.trigger? (Input::X)
     vaciar (true)
   elsif Input.trigger? (Input::A)
     mezclar
   end
   
   if Input.trigger? (Input::B)
     vaciar (true)
     $scene = Scene_Map.new
   end
   
  end
 
  def vaciar (devolver)
   items = @mezcla_window.items
   for item in items
     $game_party.gain_item (item, 1) if devolver
     @mezcla_window.quitar_ingrediente
   end
   @mezcla_window.refresh
   @items_window.refresh
  end
 
  def mezclar
   existe = false
   for combinacion in @combinaciones.keys
     if @mezcla_window.items == combinacion.sort
      existe = true
     end
   end
   if existe
     resultado = @combinaciones[@mezcla_window.items]
     for item in resultado
      $game_party.gain_item (item, 1)
     end
   else
     resultado = []
   end
   vaciar (false)
   @items_window.active = false
   @mezcla_window.active = false
   @info_window.visible = true
   @info_window.set_info (resultado)
  end
 
end


class Window_Info < Window_Base
 
  def initialize
   super (0, 0, 320, 128)
   self.contents = Bitmap.new (width - 32, height - 32)
   self.contents.font.size = 20
  end
  #--------------------------------------------------------------------------
  def set_info (info = [])
   self.contents.clear
#   self.contents.fill_rect (0, 0, self.width, self.height, Color.new (0, 0, 0, 0))
   if info.empty?
     txt = "Combinación equivocada"
     self.contents.draw_text (0, 0, self.width - 32, 32, txt, 1)
     txt = "Has perdido los ingredientes"
     self.contents.draw_text (0, 48, self.width - 32, 32, txt, 1)
     return
   end
   resultados = {}
   for item in info
     if resultados.has_key? (item)
      resultados[item] += 1
     else
      resultados[item] = 1
     end
   end
   self.height = resultados.keys.size * 32 + 32 + 32 + 16
   self.contents = Bitmap.new (width - 32, height - 32)
   txt = "Has obtenido:"
   self.contents.draw_text (0, 0, self.width - 32, 32, txt, 1)
   for i in 0...resultados.keys.size
     item_id = resultados.keys[i]
     item = $data_items[item_id]
     number = resultados[item_id]
     x = 0
     y = 32 + 16 + 32 * i
     bitmap = RPG::Cache.icon(item.icon_name)
     self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24))
     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
  #--------------------------------------------------------------------------
  def draw_item(data, pos)
  end
  #--------------------------------------------------------------------------
end


class Window_Inst < Window_Base
 
  def initialize
   super (0, 0, 320, 96)
   self.contents = Bitmap.new (width - 32, height - 32)
   refresh
  end
 
  def refresh
   self.contents.clear
   self.contents.draw_text (0, 0, self.width - 32, 32, "A: Vaciar")
   self.contents.draw_text (0, 32, self.width - 32, 32, "Z: Mezclar")
  end
 
end

#==============================================================================
# ââ€"  Window_Item
#------------------------------------------------------------------------------

class Window_Mezcla < Window_Selectable
  #--------------------------------------------------------------------------
  def initialize
   super(0, 0, 320, 320)
   self.contents = Bitmap.new(width - 32, height - 32)
   self.contents.font.name = $fontface
   self.contents.font.size = $fontsize
   @items = {}
   @column_max = 1
   refresh
   self.index = 0
  end
  #--------------------------------------------------------------------------
  def añadir_ingrediente (item)
   if @items[item].nil?
     @items[item] = 1
   else
     @items[item] += 1
   end
  end
  #--------------------------------------------------------------------------
  def quitar_ingrediente
   @items[item] -= 1
   if @items[item] == 0
     @items.delete (item)
   end
  end
  #--------------------------------------------------------------------------
  def refresh
   self.contents.clear
   @item_max = @items.keys.size
     for i in 0...@items.keys.size
      if not @items.keys[i].nil?
        draw_item(@items.keys[i], i)
      end
     end
  end
  #--------------------------------------------------------------------------
  def draw_item(data, pos)
   item = $data_items[data]
   number = @items[item.id]
   x = 0
   y = 32 * pos
   bitmap = RPG::Cache.icon(item.icon_name)
   self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24))
   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
  #--------------------------------------------------------------------------
  def items
   items = []
   for item in @items.keys
     for g in 1..@items[item]
      items.push (item)
     end
   end
   return items
  end
  #--------------------------------------------------------------------------
  def item
   return @items.keys[self.index]
  end
  #--------------------------------------------------------------------------
end

#==============================================================================
# ââ€"  Window_Item
#------------------------------------------------------------------------------

class Window_Items < Window_Selectable
  #--------------------------------------------------------------------------
  def initialize
   super(0, 0, 320, 416)
   self.contents = Bitmap.new(width - 32, height - 32)
   self.contents.font.name = $fontface
   self.contents.font.size = $fontsize
   @column_max = 1
   refresh
   self.index = 0
  end
  #--------------------------------------------------------------------------
  def refresh
   self.contents.clear
   @data = []
   for i in 1...$data_items.size
     if $game_party.item_number(i) > 0 and
      $data_items[i].element_set.include? ($atr_ingrediente)
      @data.push($data_items[i])
     end
   end
   @item_max = @data.size
   if @item_max > 0
     for i in 0...@data.size
      draw_item(@data[i], i) if not @data[i].nil?
     end
   end
  end
  #--------------------------------------------------------------------------
  def draw_item(data, pos)
   item = data
   number = $game_party.item_number(item.id)
   x = 0
   y = 32 * pos
   bitmap = RPG::Cache.icon(item.icon_name)
   self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24))
   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
  #--------------------------------------------------------------------------
  def item
   return @data[self.index]
  end
  #--------------------------------------------------------------------------
end   


Here is an ALCHEMY script that can create a new item using 2 old items as a ingredientes.... Well i want you ask a little little modification....

How can i do to change the Z button (for the mix) for other one....... like the F Button??? o_o in that way the script makes compatible with BLIZZ ABS ^_^


Aqua

Just look for all the Input::KEY and put in your own stuff.