Alchemy Pot

Alchemy Pot
Version: 1.3

Introduction
Have you ever desired to have in your game the alchemy pot like in Dragon Quest VIII?
What did you say? No??? Oh well close this topic....
For the one who don't know what is it the alchemy pot i can try to explain it;
The alchemy pot is a pot(really?) in which you can put items to combine it in a new one.

Features
You can create Recipe with 2 or more items and set the time required to complete it.
The maximum item that you can put in the pot is configurable.

Demo
Xp Demo
VX Demo

Screenshots
Image

Script
XP Spoiler
  1.  
  2. #==============================================================================
  3. # ** Alchemy Pot
  4. #------------------------------------------------------------------------------
  5. #   Autor: The Sleeping Leonhart
  6. #   Version: 1.3
  7. #   Release Date: 09/12/2008
  8. #------------------------------------------------------------------------------
  9. #   Descrption:
  10. #      This script make the alchemy pot like the Dragon Quest VIII one.
  11. #------------------------------------------------------------------------------
  12. #   Version:
  13. #      1.0 (06/12/2008): Base Version.
  14. #      1.1 (06/12/2008): Added the Failure Item option.
  15. #      1.2 (08/12/2008): Fixed a Bug in the item window.
  16. #                                 Now you can see the result of recipe immediatly.
  17. #      1.3 (09/12/2008): Added a time meter.
  18. #                                 Added a filter for the unusable item.
  19. #------------------------------------------------------------------------------
  20. #   Istruction:
  21. #      Call the Alchemy Pot with:
  22. #         $scene = Scene_AlchemyPot.new
  23. #      Press C to put the item inside the pot.
  24. #      Press B to remove the last item inserted.
  25. #      Press A to switch between item and confirm windows.
  26. #      To customize the script watch the Configuratio and Vocabulary section.
  27. #==============================================================================
  28.  
  29. #==============================================================================
  30. #   Configuration
  31. #=============================================================================
  32. module AlchemyPot
  33.   #=====DON'T TOUCH=========================================================
  34.   i = load_data("Data/Items.rxdata")
  35.   w = load_data("Data/Weapons.rxdata")
  36.   a = load_data("Data/Armors.rxdata")
  37.   #=========================================================================
  38.  
  39.   #=========================================================================
  40.   #   Formula: Set the items formula.
  41.   #-------------------------------------------------------------------------
  42.   #   Sintax:
  43.   #      Formula[[iId1, ...]] = [iId2, time]
  44.   #   Parameter:
  45.   #      iId1: id of the ingredients, use i[id] for item, w[id] for weapon,
  46.   #               a[id] for armor. id is the number of the item in the database.
  47.   #      iId2: id of the result item, use i[id] for item, w[id] for weapon,
  48.   #               a[id] for armor. id is the number of the item in the database.
  49.   #      time: number of requested minute to complete the recipe.
  50.   #=========================================================================
  51.   Formula = {}
  52.   Formula[[i[1], i[1]]] = [i[2], 0.02]
  53.   Formula[[i[1], w[1]]] = [w[2], 0]
  54.   Formula[[a[1], w[2]]] = [a[2], 4]
  55.   Formula[[i[1], i[1], i[1]]] = [i[3], 1]
  56.   Formula[[i[1], i[1], i[1], i[1], i[1]]] = [i[8], 1]
  57.   #=========================================================================
  58.   #   UnusableItem: Define the item that cannot be putted into the pot
  59.   #-------------------------------------------------------------------------
  60.   #   Sintax:
  61.   #      UnusableItem  = [iId, ...]
  62.   #   Parameter:
  63.   #      iId: id of the ingredients, use i[id] for item, w[id] for weapon,
  64.   #               a[id] for armor. id is the number of the item in the database.
  65.   #=========================================================================
  66.   UnusableItem = [i[3], w[5], a[4]]
  67.   #=========================================================================
  68.   #   MaxItem: Number of maximum item that you can put in the pot.
  69.   #-------------------------------------------------------------------------
  70.   #   Sintax:
  71.   #      MaxItem = n
  72.   #   Parameter:
  73.   #      n: Number of maximum item that you can put in the pot.
  74.   #=========================================================================
  75.   MaxItem = 5
  76.   #=========================================================================
  77.   #   FailureItem: Set the item givem if you do a wrong recipe
  78.   #-------------------------------------------------------------------------
  79.   #   Sintax:
  80.   #      FailureItem = [iId, ...]
  81.   #   Parameter:
  82.   #      iId: id of the result item, use i[id] for item, w[id] for weapon,
  83.   #               a[id] for armor. id is the number of the item in the database,
  84.   #               leave blank if you don't want the failure item.
  85.   #=========================================================================
  86.   FailureItem = [i[1], w[4], a[5]]
  87.   #=========================================================================
  88.   #   FailureTime: Set the time for making the wrong recipe
  89.   #-------------------------------------------------------------------------
  90.   #   Sintax:
  91.   #      FailureItem = time
  92.   #   Parameter:
  93.   #      time: number of requested minute to complete the recipe.
  94.   #=========================================================================
  95.   FailureTime = 1
  96.   #=========================================================================
  97.   #   MapBG: Set if the map is visible on the background
  98.   #-------------------------------------------------------------------------
  99.   #   Sintassi:
  100.   #      MapBG = b
  101.   #   Parametri:
  102.   #      b: true to show the map on the background, false the background is black
  103.   #=========================================================================
  104.   MapBG = true
  105.   #=========================================================================
  106.   #   TimeMeter: Set the time meter image
  107.   #-------------------------------------------------------------------------
  108.   #   Sintassi:
  109.   #      TimeMeter = [emptymeter, fullmeter] or nil
  110.   #   Parametri:
  111.   #      emptymeter = picture that represent the time meter empty
  112.   #      fullmeter = picture that represent the time meter full
  113.   #      nil = if you put nil the time meter is not used
  114.   #=========================================================================
  115.   TimeMeter = ["MeterEmpty", "MeterFull"]
  116. end
  117.  
  118. #==============================================================================
  119. #   Vocabulary
  120. #=============================================================================
  121. module Vocab
  122.   #Confirm Button
  123.   AlchemyPotGo = "Make"
  124.   #Exit Button
  125.   AlchemyPotExit = "Exit"
  126.   #Correct Formula
  127.   AlchemyPotRightFormula = "I think that this one can work!"
  128.   #Incorrect Formula
  129.   AlchemyPotWrongFormula = "I don't think that this one work!"
  130.   #Recipe Ready
  131.   AlchemyPotFormulaFinished = "The recipe is ready!"
  132.   #Recipe not ready
  133.   AlchemyPotFormulaNotFinished = "The recipe is not ready yet!"
  134.   #Item obtained
  135.   AlchemyPotObtained = "You have obtained:"
  136. end
  137.  
  138. class Game_Party
  139.   attr_accessor    :alchemy_pot
  140.   alias tslalchemypot_gameparty_initialize initialize 
  141.   def initialize
  142.      tslalchemypot_gameparty_initialize
  143.      @alchemy_pot = []
  144.   end
  145. end
  146.  
  147. class Window_Base
  148.   def draw_graphical_bar(x, y, barravuota, barrapiena, corrente, max)
  149.      barra_vuota = Bitmap.new("Graphics/Pictures/"+barravuota)
  150.      barra_piena = Bitmap.new("Graphics/Pictures/"+barrapiena)
  151.      taglio = corrente.to_f / max.to_f
  152.      cwp = barra_piena.width
  153.      cwv = barra_vuota.width
  154.      chp = barra_piena.height
  155.      chv = barra_vuota.height
  156.      taglio = taglio*cwp
  157.      src_rect = Rect.new(0, 0, taglio, chp)
  158.      self.contents.blt(32+x-cwp/4, 18+y-chp/2, barra_piena, src_rect)
  159.      src_rect = Rect.new(taglio, 0, cwv-taglio, chv)
  160.      self.contents.blt(32+x-cwv/4+taglio, 18+y-chv/2, barra_vuota, src_rect)
  161.   end
  162. end
  163.  
  164. class Window_AlchemyPotItem < Window_Selectable
  165.   def initialize
  166.      super(32, 96, 312, 312)
  167.      @column_max = 10
  168.      self.index = 0
  169.      refresh
  170.   end 
  171.   def item
  172.      return @data[self.index]
  173.   end    
  174.   def enable?(item)
  175.      return $game_party.item_can_use?(item)
  176.   end 
  177.   def refresh
  178.      if self.contents != nil
  179.         self.contents.dispose
  180.         self.contents = nil
  181.      end
  182.      @data = []
  183.      for item in $data_items
  184.         if $game_party.item_number(item.id) > 0 and item != nil
  185.            @data.push(item) if check(item)
  186.         end
  187.      end
  188.      for item in $data_weapons
  189.         if $game_party.weapon_number(item.id) > 0 and item != nil
  190.            @data.push(item) if check(item)
  191.         end
  192.      end
  193.      for item in $data_armors
  194.         if $game_party.armor_number(item.id) > 0 and item != nil
  195.            @data.push(item) if check(item)
  196.         end
  197.      end
  198.      @item_max = @data.size
  199.      @row_max = @data.size / 10
  200.      if @item_max > 0
  201.         self.contents = Bitmap.new(width - 32, row_max * 28)
  202.         for i in 0...@item_max
  203.            draw_item(i)
  204.         end
  205.      end
  206.   end 
  207.   def draw_item(index)
  208.      item = @data[index]
  209.      case item
  210.      when RPG::Item
  211.         number = $game_party.item_number(item.id)
  212.      when RPG::Weapon
  213.         number = $game_party.weapon_number(item.id)
  214.      when RPG::Armor
  215.         number = $game_party.armor_number(item.id)
  216.      end
  217.      x = index % @column_max * 28
  218.      y = index / @column_max * 28
  219.      rect = Rect.new(x, y, 32, 32)
  220.      self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
  221.      bitmap = RPG::Cache.icon(item.icon_name)
  222.      self.contents.blt(x, y, bitmap, Rect.new(0, 0, 24, 24))
  223.      self.contents.font.size = 12
  224.      self.contents.draw_text(12 + x, 8 + y, 24, 24, number.to_s)
  225.   end 
  226.   def update_help
  227.      @help_window.set_text(item == nil ? "" : item.name)
  228.   end 
  229.   def page_row_max
  230.      return (self.height - 32) / 28
  231.   end 
  232.   def top_row
  233.      return self.oy / 28
  234.   end 
  235.   def top_row=(row)
  236.      super
  237.      self.oy = row * 28
  238.   end 
  239.   def update_cursor_rect
  240.      super
  241.      x = @index % @column_max * 28
  242.      y = @index / @column_max * 28 - self.oy
  243.      self.cursor_rect.set(x, y, 24, 24)
  244.   end
  245.   def check(item)
  246.      for i in AlchemyPot::UnusableItem
  247.         if i.id == item.id and i.class == item.class
  248.            return false
  249.         end
  250.      end
  251.      return true
  252.   end
  253. end
  254.  
  255. class Window_AlchemyPotPot < Window_Base
  256.   def initialize
  257.      super(454, 96, 28 + 32, 28 * AlchemyPot::MaxItem + 32)
  258.      self.contents = Bitmap.new(width - 32, height - 32)
  259.      refresh
  260.   end 
  261.   def refresh(pot = [])     
  262.      self.contents.clear
  263.      @data = pot.clone
  264.      @data.push(nil) if @data == []
  265.      @item_max = @data.size    
  266.      for i in 0...@item_max
  267.         draw_item(i)
  268.      end
  269.   end 
  270.   def draw_item(index)
  271.      item = @data[index]
  272.      if item != nil
  273.         y = index * 28
  274.         bitmap = RPG::Cache.icon(item.icon_name)
  275.         self.contents.blt(0, y, bitmap, Rect.new(0, 0, 24, 24))
  276.      end
  277.   end 
  278. end
  279.  
  280. class Window_AlchemyPotResult < Window_Base
  281.   def initialize
  282.      super(0, 192, 320, 64)
  283.      self.contents = Bitmap.new(width - 32, height - 32)
  284.      self.width = [self.contents.text_size(Vocab::AlchemyPotObtained).width + 240, 640].min
  285.      self.contents = Bitmap.new(width - 32, height - 32)
  286.      self.x = 272 - self.width / 2
  287.      refresh
  288.   end 
  289.   def refresh(item = nil)
  290.      self.contents.clear
  291.      self.contents.font.color = normal_color
  292.      self.contents.draw_text(0, 4, self.width - 64, 24, Vocab::AlchemyPotObtained)
  293.      draw_item_name(item, self.contents.text_size(Vocab::AlchemyPotObtained).width + 2, 0)
  294.   end
  295. end
  296.  
  297. class Window_PotTimeMeter < Window_Base
  298.   def initialize(a = 0)
  299.      super(420, 400, 192, 64)
  300.      self.contents = Bitmap.new(width - 32, height - 32)
  301.      self.opacity = 0
  302.      refresh(a)
  303.   end
  304.   def refresh(a)
  305.      if AlchemyPot::TimeMeter != nil
  306.         self.contents.clear
  307.         a = 0 if a == nil
  308.         b = $game_party.alchemy_pot[2]
  309.         b = (Graphics.frame_count - a) * 100 if b == nil
  310.         draw_graphical_bar(0, 0, AlchemyPot::TimeMeter[0], AlchemyPot::TimeMeter[1], Graphics.frame_count-a, b)
  311.      end
  312.   end
  313. end
  314.  
  315. class Scene_AlchemyPot
  316.   def main
  317.      @map = Spriteset_Map.new if AlchemyPot::MapBG
  318.      create_command_window
  319.      @help_window = Window_Help.new
  320.      @item_window = Window_AlchemyPotItem.new
  321.      @item_window.help_window = @help_window
  322.      @pot_window = Window_AlchemyPotPot.new
  323.      @result_window = Window_AlchemyPotResult.new
  324.      @result_window.visible = false
  325.      @meter = Window_PotTimeMeter.new($game_party.alchemy_pot[1])
  326.      @ready = false
  327.      if $game_party.alchemy_pot != []
  328.         if $game_party.alchemy_pot[0][0] == "Wrong"
  329.            @ingredients = $game_party.alchemy_pot[0][1].clone
  330.            item = AlchemyPot::FailureItem[rand(AlchemyPot::FailureItem.size)]
  331.         else
  332.            @ingredients = $game_party.alchemy_pot[0].clone
  333.            item = AlchemyPot::Formula[$game_party.alchemy_pot[0]][0]
  334.         end
  335.         @pot_window.refresh(@ingredients)        
  336.         @item_window.active = false
  337.         if Graphics.frame_count - $game_party.alchemy_pot[1] >= $game_party.alchemy_pot[2]
  338.            @help_window.set_text(Vocab::AlchemyPotFormulaFinished)
  339.            case item
  340.            when RPG::Item
  341.               $game_party.gain_item(item.id, 1)
  342.            when RPG::Weapon
  343.               $game_party.gain_weapon(item.id, 1)
  344.            when RPG::Armor
  345.               $game_party.gain_armor(item.id, 1)
  346.            end
  347.            @result_window.refresh(item)
  348.            $game_party.alchemy_pot = []
  349.            @ready = true
  350.         else
  351.            @help_window.set_text(Vocab::AlchemyPotFormulaNotFinished)
  352.         end
  353.      else
  354.         @ingredients = []
  355.      end
  356.      Graphics.transition
  357.      loop do
  358.         Graphics.update
  359.         Input.update
  360.         update
  361.         if $scene != self
  362.            break
  363.         end
  364.      end
  365.      Graphics.freeze
  366.      @map.dispose if AlchemyPot::MapBG
  367.      @command_window.dispose
  368.      @help_window.dispose
  369.      @item_window.dispose
  370.      @pot_window.dispose
  371.      @result_window.dispose
  372.      @meter.dispose
  373.   end 
  374.   def update
  375.      @help_window.update
  376.      @command_window.update
  377.      @item_window.update
  378.      @pot_window.update
  379.      @result_window.update
  380.      @meter.update
  381.      if @command_window.active
  382.         update_command_selection
  383.      elsif @item_window.active
  384.         update_item_selection
  385.      elsif @ready and @result_window.visible == false
  386.         if Input.trigger?(Input::C)
  387.            $game_system.se_play($data_system.decision_se)
  388.            @result_window.visible = true
  389.            @result_window.z = 105
  390.            return
  391.         end
  392.      elsif @result_window.visible
  393.         if Input.trigger?(Input::C)           
  394.            $game_system.se_play($data_system.decision_se)
  395.            @ingredients = []
  396.            @ready = false
  397.            @result_window.visible = false
  398.            @item_window.active = true
  399.            @item_window.refresh
  400.            @pot_window.refresh
  401.            return
  402.         end
  403.      else
  404.         if Input.trigger?(Input::C)           
  405.            $game_system.se_play($data_system.decision_se)
  406.            $scene = Scene_Map.new
  407.         end
  408.      end
  409.      if $game_party.alchemy_pot[1] != nil
  410.         @meter.refresh($game_party.alchemy_pot[1])
  411.         if Graphics.frame_count - $game_party.alchemy_pot[1] >= $game_party.alchemy_pot[2]
  412.            $scene = Scene_AlchemyPot.new
  413.         end
  414.      end
  415.   end
  416.   def create_command_window
  417.      s1 = Vocab::AlchemyPotGo
  418.      s2 = Vocab::AlchemyPotExit
  419.      @command_window = Window_Command.new(96, [s1, s2])
  420.      @command_window.active = false
  421.      @command_window.x = 430
  422.      @command_window.y = 304
  423.   end
  424.   def update_item_selection
  425.      if Input.trigger?(Input::B)
  426.         $game_system.se_play($data_system.cancel_se)
  427.         if @ingredients == []
  428.            $scene = Scene_Map.new
  429.         else
  430.            pop = @ingredients.pop
  431.            case pop
  432.            when RPG::Item
  433.               $game_party.gain_item(pop.id, 1)
  434.            when RPG::Weapon
  435.               $game_party.gain_weapon(pop.id, 1)
  436.            when RPG::Armor
  437.               $game_party.gain_armor(pop.id, 1)
  438.            end
  439.            @item_window.refresh
  440.            @pot_window.refresh(@ingredients)
  441.         end
  442.      elsif Input.trigger?(Input::C)
  443.         if @ingredients.size < AlchemyPot::MaxItem and @item_window.item != nil
  444.            $game_system.se_play($data_system.decision_se)
  445.            item = @item_window.item
  446.            @ingredients.push(item)
  447.            case item
  448.            when RPG::Item
  449.               $game_party.gain_item(item.id, -1)
  450.            when RPG::Weapon
  451.               $game_party.gain_weapon(item.id, -1)
  452.            when RPG::Armor
  453.               $game_party.gain_armor(item.id, -1)
  454.            end
  455.            @item_window.refresh
  456.            @pot_window.refresh(@ingredients)
  457.         else
  458.            $game_system.se_play($data_system.buzzer_se)
  459.         end
  460.      elsif Input.trigger?(Input::A)
  461.         $game_system.se_play($data_system.decision_se)
  462.         @item_window.active = false
  463.         @command_window.active = true
  464.      end
  465.   end 
  466.   def update_command_selection
  467.      if Input.trigger?(Input::B)
  468.         $game_system.se_play($data_system.cancel_se)
  469.         exit
  470.      elsif Input.trigger?(Input::C)
  471.         case @command_window.index
  472.         when 0
  473.            if @ingredients.size > 1
  474.               $game_system.se_play($data_system.decision_se)
  475.               start_alchemy
  476.            else
  477.               $game_system.se_play($data_system.buzzer_se)
  478.            end
  479.         when 1
  480.            $game_system.se_play($data_system.decision_se)
  481.            exit
  482.         end
  483.      elsif Input.trigger?(Input::A)
  484.         $game_system.se_play($data_system.decision_se)
  485.         @item_window.active = true
  486.         @command_window.active = false
  487.      end
  488.   end 
  489.   def exit
  490.      for item in @ingredients       
  491.         case item
  492.         when RPG::Item
  493.            $game_party.gain_item(item.id, 1)
  494.         when RPG::Weapon
  495.            $game_party.gain_weapon(item.id, 1)
  496.         when RPG::Armor
  497.            $game_party.gain_armor(item.id, 1)
  498.         end
  499.      end
  500.      $scene = Scene_Map.new
  501.   end 
  502.   def start_alchemy
  503.      for i in AlchemyPot::Formula.keys
  504.         formula = item_sort(i)
  505.         ingredients = item_sort(@ingredients)
  506.         if formula == ingredients
  507.            @help_window.set_text(Vocab::AlchemyPotRightFormula)
  508.            $game_party.alchemy_pot[0] = i.clone
  509.            $game_party.alchemy_pot[1] = Graphics.frame_count
  510.            $game_party.alchemy_pot[2] =   AlchemyPot::Formula[i][1] * Graphics.frame_rate * 60
  511.            @command_window.active = false
  512.            return
  513.         end
  514.      end
  515.      @help_window.set_text(Vocab::AlchemyPotWrongFormula)
  516.      if AlchemyPot::FailureItem.size > 0
  517.         $game_party.alchemy_pot[0] = ["Wrong", ingredients.clone]
  518.         $game_party.alchemy_pot[1] = Graphics.frame_count
  519.         $game_party.alchemy_pot[2] = AlchemyPot::FailureTime * Graphics.frame_rate * 60
  520.         @command_window.active = false
  521.         return
  522.      else
  523.         for item in @ingredients
  524.            case item
  525.            when RPG::Item
  526.               $game_party.gain_item(item.id, 1)
  527.            when RPG::Weapon
  528.               $game_party.gain_weapon(item.id, 1)
  529.            when RPG::Armor
  530.               $game_party.gain_armor(item.id, 1)
  531.            end
  532.         end
  533.         @ingredients = []
  534.         @item_window.refresh
  535.         @pot_window.refresh(@ingredients)
  536.      end
  537.   end 
  538.   def item_sort(formula)
  539.      i = []; w = []; a = []
  540.      for item in 0...formula.size
  541.         case formula[item]
  542.         when RPG::Item
  543.            i.push(formula[item].id)
  544.            i.sort!
  545.         when RPG::Weapon
  546.            w.push(formula[item].id)
  547.            w.sort!
  548.         when RPG::Armor
  549.            a.push(formula[item].id)
  550.            a.sort!
  551.         end
  552.      end
  553.      formula = []
  554.      for item in i
  555.         formula.push($data_items[item])
  556.      end
  557.      for item in w
  558.         formula.push($data_weapons[item])
  559.      end
  560.      for item in a
  561.         formula.push($data_armors[item])
  562.      end
  563.      return formula
  564.   end
  565. end
  566.  
Expand to see the code.

VX Spoiler
  1.  
  2. #==============================================================================
  3. # ** Alchemy Pot
  4. #------------------------------------------------------------------------------
  5. #   Autor: The Sleeping Leonhart
  6. #   Version: 1.3
  7. #   Release Date: 09/12/2008
  8. #------------------------------------------------------------------------------
  9. #   Descrption:
  10. #      This script make the alchemy pot like the Dragon Quest VIII one.
  11. #------------------------------------------------------------------------------
  12. #   Version:
  13. #      1.0 (07/10/2008): Base Version.
  14. #      1.1 (06/12/2008): Added the Failure Item option.
  15. #      1.2 (08/12/2008): Now you can see the result of recipe immediatly.
  16. #      1.3 (09/12/2008): Added a time meter.
  17. #                                 Added a filter for the unusable item.
  18. #------------------------------------------------------------------------------
  19. #   Istruction:
  20. #      Call the Alchemy Pot with:
  21. #         $scene = Scene_AlchemyPot.new
  22. #      Press C to put the item inside the pot.
  23. #      Press B to remove the last item inserted.
  24. #      Press A to switch between item and confirm windows.
  25. #      To customize the script watch the Configuratio and Vocabulary section.
  26. #==============================================================================
  27.  
  28. #==============================================================================
  29. #   Configuration
  30. #=============================================================================
  31. module AlchemyPot
  32.   #=====DON'T TOUCH=========================================================
  33.   i = load_data("Data/Items.rvdata")
  34.   w = load_data("Data/Weapons.rvdata")
  35.   a = load_data("Data/Armors.rvdata")
  36.   #=========================================================================
  37.  
  38.   #=========================================================================
  39.   #   Formula: Set the items formula.
  40.   #-------------------------------------------------------------------------
  41.   #   Sintassi:
  42.   #      Formula[[iId1, ...]] = [iId2, time]
  43.   #   Parametri:
  44.   #      iId1: id of the ingredients, use i[id] for item, w[id] for weapon,
  45.   #               a[id] for armor. id is the number of the item in the database.
  46.   #      iId2: id of the result item, use i[id] for item, w[id] for weapon,
  47.   #               a[id] for armor. id is the number of the item in the database.
  48.   #      time: number of requested minute to complete the recipe.
  49.   #=========================================================================
  50.   Formula = {}
  51.   Formula[[i[1], i[1]]] = [i[2], 1]
  52.   Formula[[i[1], w[1]]] = [w[2], 2]
  53.   Formula[[a[1], w[2]]] = [a[2], 4]
  54.   Formula[[i[1], i[1], i[1]]] = [i[3], 1]
  55.   Formula[[i[1], i[1], i[1], i[1], i[1]]] = [i[8], 1]
  56.   #=========================================================================
  57.   #   UnusableItem: Define the item that cannot be putted into the pot
  58.   #-------------------------------------------------------------------------
  59.   #   Sintax:
  60.   #      UnusableItem  = [iId, ...]
  61.   #   Parameter:
  62.   #      iId: id of the ingredients, use i[id] for item, w[id] for weapon,
  63.   #               a[id] for armor. id is the number of the item in the database.
  64.   #=========================================================================
  65.   UnusableItem = [i[3], w[5], a[4]]
  66.   #=========================================================================
  67.   #   MaxItem: Number of maximum item that you can put in the pot.
  68.   #-------------------------------------------------------------------------
  69.   #   Sintassi:
  70.   #      MaxItem = n
  71.   #   Parametri:
  72.   #      n: Number of maximum item that you can put in the pot.
  73.   #=========================================================================
  74.   MaxItem = 5
  75.   #=========================================================================
  76.   #   FailureItem: Set the item givem if you do a wrong recipe
  77.   #-------------------------------------------------------------------------
  78.   #   Sintassi:
  79.   #      FailureItem = [iId, ...]
  80.   #   Parametri:
  81.   #      iId: id of the result item, use i[id] for item, w[id] for weapon,
  82.   #               a[id] for armor. id is the number of the item in the database,
  83.   #               leave blank if you don't want the failure item.
  84.   #=========================================================================
  85.   FailureItem = [i[1], w[4], a[5]]
  86.   #=========================================================================
  87.   #   FailureTime: Set the time for making the wrong recipe
  88.   #-------------------------------------------------------------------------
  89.   #   Sintassi:
  90.   #      FailureItem = time
  91.   #   Parametri:
  92.   #      time: number of requested minute to complete the recipe.
  93.   #=========================================================================
  94.   FailureTime = 1
  95.   #=========================================================================
  96.   #   TimeMeter: Set the time meter image
  97.   #-------------------------------------------------------------------------
  98.   #   Sintassi:
  99.   #      TimeMeter = [emptymeter, fullmeter] or nil
  100.   #   Parametri:
  101.   #      emptymeter = picture that represent the time meter empty
  102.   #      fullmeter = picture that represent the time meter full
  103.   #      nil = if you put nil the time meter is not used
  104.   #=========================================================================
  105.   TimeMeter = ["MeterEmpty", "MeterFull"]
  106. end
  107.  
  108. #==============================================================================
  109. #   Vocabulary
  110. #=============================================================================
  111. module Vocab
  112.   #Confirm Button
  113.   AlchemyPotGo = "Make"
  114.   #Exit Button
  115.   AlchemyPotExit = "Exit"
  116.   #Correct Formula
  117.   AlchemyPotRightFormula = "I think that this one can work!"
  118.   #Incorrect Formula
  119.   AlchemyPotWrongFormula = "I don't think that this one work!"
  120.   #Recipe Ready
  121.   AlchemyPotFormulaFinished = "The recipe is ready!"
  122.   #Recipe not ready
  123.   AlchemyPotFormulaNotFinished = "The recipe is not ready yet!"
  124.   #Item obtained
  125.   AlchemyPotObtained = "You have obtained:"
  126. end
  127.  
  128. class Game_Party
  129.   attr_accessor    :alchemy_pot
  130.   alias tslalchemypot_gameparty_initialize initialize 
  131.   def initialize
  132.      tslalchemypot_gameparty_initialize
  133.      @alchemy_pot = []
  134.   end
  135. end
  136.  
  137. class Window_Base
  138.   def draw_graphical_bar(x, y, barravuota, barrapiena, corrente, max)
  139.      barra_vuota = Bitmap.new("Graphics/Pictures/"+barravuota)
  140.      barra_piena = Bitmap.new("Graphics/Pictures/"+barrapiena)
  141.      taglio = corrente.to_f / max.to_f
  142.      cwp = barra_piena.width
  143.      cwv = barra_vuota.width
  144.      chp = barra_piena.height
  145.      chv = barra_vuota.height
  146.      taglio = taglio*cwp
  147.      src_rect = Rect.new(0, 0, taglio, chp)
  148.      self.contents.blt(32+x-cwp/4, 18+y-chp/2, barra_piena, src_rect)
  149.      src_rect = Rect.new(taglio, 0, cwv-taglio, chv)
  150.      self.contents.blt(32+x-cwv/4+taglio, 18+y-chv/2, barra_vuota, src_rect)
  151.   end
  152. end
  153.  
  154. class Window_AlchemyPotItem < Window_Selectable
  155.   def initialize
  156.      super(32, 80, 292, 292)
  157.      @column_max = 10
  158.      self.index = 0
  159.      refresh
  160.   end 
  161.   def item
  162.      return @data[self.index]
  163.   end
  164.   def include?(item)
  165.      return false if item == nil
  166.      if $game_temp.in_battle
  167.         return false unless item.is_a?(RPG::Item)
  168.      end
  169.      return true
  170.   end
  171.   def item_rect(index)
  172.      rect = Rect.new(0, 0, 0, 0)
  173.      rect.width = 24
  174.      rect.height = 24
  175.      rect.x = index % @column_max * 26
  176.      rect.y = index / @column_max * 26
  177.      return rect
  178.   end 
  179.   def enable?(item)
  180.      return $game_party.item_can_use?(item)
  181.   end
  182.   def refresh
  183.      @data = []
  184.      for item in $game_party.items
  185.         next unless include?(item)
  186.         @data.push(item) if check(item)
  187.      end
  188.      @data.push(nil) if include?(nil)
  189.      @item_max = @data.size
  190.      create_contents
  191.      for i in 0...@item_max
  192.         draw_item(i)
  193.      end
  194.   end 
  195.   def draw_item(index)
  196.      rect = item_rect(index)
  197.      self.contents.clear_rect(rect)
  198.      item = @data[index]
  199.      if item != nil
  200.         number = $game_party.item_number(item)
  201.         x = index % @column_max * 26
  202.         y = index / @column_max * 26
  203.         draw_icon(item.icon_index, x, y)
  204.         self.contents.font.size = 12
  205.         self.contents.draw_text(10 + x, 6 + y, 24, 24, number.to_s)
  206.      end
  207.   end 
  208.   def update_help
  209.      @help_window.set_text(item == nil ? "" : item.name)
  210.   end
  211.   def check(item)
  212.      for i in AlchemyPot::UnusableItem
  213.         if i.id == item.id and i.class == item.class
  214.            return false
  215.         end
  216.      end
  217.      return true
  218.   end
  219. end
  220.  
  221. class Window_AlchemyPotPot < Window_Base
  222.   def initialize
  223.      super(454, 80, 26 + 32, 26 * AlchemyPot::MaxItem + 32)
  224.      refresh
  225.   end 
  226.   def refresh(pot = [])     
  227.      self.contents.clear
  228.      @data = pot.clone
  229.      @data.push(nil) if @data == []
  230.      @item_max = @data.size
  231.      create_contents
  232.      for i in 0...@item_max
  233.         draw_item(i)
  234.      end
  235.   end 
  236.   def draw_item(index)
  237.      item = @data[index]
  238.      if item != nil
  239.         y = index * 26
  240.         draw_icon(item.icon_index, 0, y)
  241.      end
  242.   end 
  243. end
  244.  
  245. class Window_AlchemyPotResult < Window_Base
  246.   def initialize
  247.      super(0, 180, 272, WLH + 32)
  248.      self.width = [self.contents.text_size(Vocab::AlchemyPotObtained).width + 192, 544].min
  249.      self.x = 272 - self.width / 2
  250.      create_contents
  251.      refresh
  252.   end
  253.   def refresh(item = nil)
  254.      self.contents.clear
  255.      self.contents.font.color = normal_color
  256.      self.contents.draw_text(0, 0, self.width - 40, WLH, Vocab::AlchemyPotObtained)
  257.      draw_item_name(item, self.contents.text_size(Vocab::AlchemyPotObtained).width + 2, 0)
  258.   end
  259. end
  260.  
  261. class Window_PotTimeMeter < Window_Base
  262.   def initialize(a = 0)
  263.      super(180, 360, 192, 64)
  264.      self.contents = Bitmap.new(width - 32, height - 32)
  265.      self.opacity = 0
  266.      refresh(a)
  267.   end
  268.   def refresh(a)
  269.      if AlchemyPot::TimeMeter != nil
  270.         self.contents.clear
  271.         a = 0 if a == nil
  272.         b = $game_party.alchemy_pot[2]
  273.         b = (Graphics.frame_count - a) * 100 if b == nil
  274.         draw_graphical_bar(0, 0, AlchemyPot::TimeMeter[0], AlchemyPot::TimeMeter[1], Graphics.frame_count-a, b)
  275.      end
  276.   end
  277. end
  278.  
  279. class Scene_AlchemyPot < Scene_Base
  280.   def start
  281.      super
  282.      create_menu_background
  283.      create_command_window
  284.      @help_window = Window_Help.new
  285.      @item_window = Window_AlchemyPotItem.new
  286.      @item_window.help_window = @help_window
  287.      @pot_window = Window_AlchemyPotPot.new
  288.      @result_window = Window_AlchemyPotResult.new
  289.      @result_window.visible = false
  290.      @meter = Window_PotTimeMeter.new($game_party.alchemy_pot[1])
  291.      @ready = false
  292.      if $game_party.alchemy_pot != []
  293.         if $game_party.alchemy_pot[0][0] == "Wrong"
  294.            @ingredients = $game_party.alchemy_pot[0][1].clone
  295.            item = AlchemyPot::FailureItem[rand(AlchemyPot::FailureItem.size)]
  296.         else
  297.            @ingredients = $game_party.alchemy_pot[0].clone
  298.            item = AlchemyPot::Formula[$game_party.alchemy_pot[0]][0]
  299.         end
  300.         @pot_window.refresh(@ingredients)        
  301.         @item_window.active = false
  302.         if Graphics.frame_count - $game_party.alchemy_pot[1] >= $game_party.alchemy_pot[2]
  303.            @help_window.set_text(Vocab::AlchemyPotFormulaFinished)
  304.            $game_party.gain_item(item, 1)
  305.            @result_window.refresh(item)
  306.            $game_party.alchemy_pot = []
  307.            @ready = true
  308.         else
  309.            @help_window.set_text(Vocab::AlchemyPotFormulaNotFinished)
  310.         end
  311.      else
  312.         @ingredients = []
  313.      end
  314.   end
  315.   def terminate
  316.      super
  317.      dispose_menu_background
  318.      dispose_command_window
  319.      @help_window.dispose
  320.      @item_window.dispose
  321.      @pot_window.dispose
  322.      @meter.dispose
  323.   end
  324.   def update
  325.      super
  326.      update_menu_background
  327.      @help_window.update
  328.      @command_window.update
  329.      @item_window.update
  330.      @pot_window.update
  331.      @meter.update
  332.      if @command_window.active
  333.         update_command_selection
  334.      elsif @item_window.active
  335.         update_item_selection
  336.      elsif @ready and @result_window.visible == false
  337.         if Input.trigger?(Input::C)
  338.            Sound.play_decision
  339.            @result_window.visible = true
  340.            return
  341.         end
  342.      elsif @result_window.visible
  343.         if Input.trigger?(Input::C)           
  344.            Sound.play_decision
  345.            @ingredients = []
  346.            @ready = false
  347.            @result_window.visible = false
  348.            @item_window.active = true
  349.            @item_window.refresh
  350.            @pot_window.refresh
  351.            return
  352.         end
  353.      else
  354.         if Input.trigger?(Input::C)           
  355.            Sound.play_decision
  356.            $scene = Scene_Map.new
  357.         end
  358.      end
  359.      if $game_party.alchemy_pot[1] != nil
  360.         @meter.refresh($game_party.alchemy_pot[1])
  361.         if Graphics.frame_count - $game_party.alchemy_pot[1] >= $game_party.alchemy_pot[2]
  362.            $scene = Scene_AlchemyPot.new
  363.         end
  364.      end
  365.   end
  366.   def create_command_window
  367.      s1 = Vocab::AlchemyPotGo
  368.      s2 = Vocab::AlchemyPotExit
  369.      @command_window = Window_Command.new(96, [s1, s2])
  370.      @command_window.active = false
  371.      @command_window.x = 430
  372.      @command_window.y = 304
  373.   end
  374.   def dispose_command_window
  375.      @command_window.dispose
  376.   end 
  377.   def update_item_selection
  378.      if Input.trigger?(Input::B)
  379.         Sound.play_cancel
  380.         if @ingredients == []
  381.            $scene = Scene_Map.new
  382.         else
  383.            $game_party.gain_item(@ingredients.pop, 1)
  384.            @item_window.refresh
  385.            @pot_window.refresh(@ingredients)
  386.         end
  387.      elsif Input.trigger?(Input::C)
  388.         if @ingredients.size < AlchemyPot::MaxItem and @item_window.item != nil
  389.            Sound.play_decision
  390.            item = @item_window.item
  391.            @ingredients.push(item)
  392.            $game_party.gain_item(item, -1)
  393.            @item_window.refresh
  394.            @pot_window.refresh(@ingredients)
  395.         else
  396.            Sound.play_buzzer
  397.         end
  398.      elsif Input.trigger?(Input::A)
  399.         Sound.play_decision
  400.         @item_window.active = false
  401.         @command_window.active = true
  402.      end
  403.   end 
  404.   def update_command_selection
  405.      if Input.trigger?(Input::B)
  406.         Sound.play_cancel
  407.         exit
  408.      elsif Input.trigger?(Input::C)
  409.         case @command_window.index
  410.         when 0
  411.            if @ingredients.size > 1
  412.               Sound.play_decision
  413.               start_alchemy
  414.            else
  415.               Sound.play_buzzer
  416.            end
  417.         when 1
  418.            Sound.play_decision
  419.            exit
  420.         end
  421.      elsif Input.trigger?(Input::A)
  422.         Sound.play_decision
  423.         @item_window.active = true
  424.         @command_window.active = false
  425.      end
  426.   end 
  427.   def exit
  428.      for item in @ingredients
  429.         $game_party.gain_item(item, 1)
  430.      end
  431.      $scene = Scene_Map.new
  432.   end 
  433.   def start_alchemy
  434.      for i in AlchemyPot::Formula.keys
  435.         formula = item_sort(i)
  436.         ingredients = item_sort(@ingredients)
  437.         if formula == ingredients
  438.            @help_window.set_text(Vocab::AlchemyPotRightFormula)
  439.            $game_party.alchemy_pot[0] = i.clone
  440.            $game_party.alchemy_pot[1] = Graphics.frame_count
  441.            $game_party.alchemy_pot[2] =   AlchemyPot::Formula[i][1] * Graphics.frame_rate * 60
  442.            @command_window.active = false
  443.            return
  444.         end
  445.      end
  446.      @help_window.set_text(Vocab::AlchemyPotWrongFormula)
  447.      if AlchemyPot::FailureItem.size > 0
  448.         $game_party.alchemy_pot[0] = ["Wrong", ingredients.clone]
  449.         $game_party.alchemy_pot[1] = Graphics.frame_count
  450.         $game_party.alchemy_pot[2] = AlchemyPot::FailureTime * Graphics.frame_rate * 60
  451.         @command_window.active = false
  452.         return
  453.      else
  454.         for item in @ingredients
  455.            $game_party.gain_item(item, 1)
  456.         end
  457.         @ingredients = []
  458.         @item_window.refresh
  459.         @pot_window.refresh(@ingredients)
  460.      end
  461.   end
  462.   def item_sort(formula)
  463.      i = []; w = []; a = []
  464.      for item in 0...formula.size
  465.         case formula[item]
  466.         when RPG::Item
  467.            i.push(formula[item].id)
  468.            i.sort!
  469.         when RPG::Weapon
  470.            w.push(formula[item].id)
  471.            w.sort!
  472.         when RPG::Armor
  473.            a.push(formula[item].id)
  474.            a.sort!
  475.         end
  476.      end
  477.      formula = []
  478.      for item in i
  479.         formula.push($data_items[item])
  480.      end
  481.      for item in w
  482.         formula.push($data_weapons[item])
  483.      end
  484.      for item in a
  485.         formula.push($data_armors[item])
  486.      end
  487.      return formula
  488.   end
  489. end
  490.  
Expand to see the code.


Instructions
Put the script above main.
Press C to put the item inside the pot.
Press B to remove the last item inserted.
Press A to switch between item and confirm windows.
To customize the script watch the Configuratio and Vocabulary section

Compatibility
Don't Know, i've aliased everything, so it should be combatible with any script.

Credits and Thanks
Square Enix for making Dragon Quest VIII

Terms and Conditions
Free with credit for amatorial project, if you want use it in a commercial project PM me.

Sorry for the bad english.
Nice solid script Leonhart, good job.  Are those 50's on the icons supposed to represent minutes or item quantity?
The number represent the item quantity(50 minute... argh xD)
Yeah after looking at the script a little harder I figured that out, lol.  I thought maybe each ingredient had a certain time limit but I see that is defined in the configuration for the whole recipe.  Thanks for clarifying anyway.  No bugs found yet but I'm gonna keep messing with it. 
Only VX?  🙁  Can you possibly make one for XP?
Well, this is a great script. But I stand with Uupa99, It's possible to you to make this for XP also?

Thanks Anyway.
oh man, i was so salivating over this, until i saw the VX sign. I hope you end up translating this to XP, its the sex.
If he isn't willing to translate it, I should be able to. (So long as he gives permission) Honestly, there isn't all that much in the way of differences between RGSS and RGSS2. Just a few predefined things. It's not like they're two completely different languages.
Converted for XP!
Look the first post ;)
Thanks for the conversion..

I have a little problem, It's possible to make the Selectable item window to scroll?. because when i have too many items the window has a limit and I can't select the items. (In the XP version, because in the VX works perfect).

http://img243.imageshack.us/img243/5196/asasasfn9.png[/img]
http://img243.imageshack.us/img243/asasasfn9.png/1/w662.png[/img]


And it's possible to add a function, when you fail in the recipe you got a Failure Item.


Thanks in advance.
for item_sort use this:

module RPG
class Item
 def <=> (other)
  temp = self.class.name <=> other.class.name
  return temp unless temp == 0
  return self.id <=> other.id
 end
end
class Weapon
 def <=> (other)
  temp = self.class.name <=> other.class.name
  return temp unless temp == 0
  return self.id <=> other.id
 end
end
class Armor
 def <=> (other)
  temp = self.class.name <=> other.class.name
  return temp unless temp == 0
  return self.id <=> other.id
 end
end
end
Expand to see the code.


so you can sort the items in array with sort
@mephisto: sorry for that stupid bug, the fix will be included in the next release.
For the failure item... can you explain it better? You want that if you put an inexisistent Recipe you receive a predefined item?

Thanks for the sorting method hanmac
Well, about the failure item..for example.

You put 2 or more items in the pot. (and it's an inexistent recipe) you get a Failure item from a random list.
for example:
You put POTION + ELIXIR....you wait the time.. and you get A "BAD POTION"
Like the Harvest moon Cooking system...something like that.

MODULE Alchemypot
Failure_Items          = [2,56,66]
Failure_Recipe_Time = 1
end

My english is bad, asi que espero que haya sido entendido. :).
Made It, look the first post. I've added the Failure Item option in both version and i fixed the item window in the XP version.
How about a demo ~^^~
Made it! Look first post ^^
Great demo! thank you, The Sleeping Leonhart! :D
Great!!. Sorry to annoy again :). But I have a little problem in both versions, when you wait the full time in the Scene, you must exit and enter again to see the result, that isn't good I guess.

is that a bug or the system is correct?


PD: There still a problem with the selectable item window, when you have too many items, I think you must recreate the update_cursor_rect again to solve this.
mephisto wrote:
Great!!. Sorry to annoy again :). But I have a little problem in both versions, when you wait the full time in the Scene, you must exit and enter again to see the result, that isn't good I guess.

is that a bug or the system is correct?


PD: There still a problem with the selectable item window, when you have too many items, I think you must recreate the update_cursor_rect again to solve this.



I think it may have a reason: Isn't the player supposed to do something else while waits the transmutation/transformation/whatever like hunting more materials, level-uping or advancing on the game history.
Well, I think about it, but when the time of transmutation is 0 or you wait all the time in the scene looks ugly.
Maybe will work better with more time, but if the recipe requires less time, that's not work.
OK I fixed the item window bug( I hope ) and now you can see the result immediatly.
Don't put 0 as wait time or the scene change immediatly, try with 0.01 or 0.02 instead ;)
im NOT good at scripts, and im beginning.  How DO i exactly put in the whole script and call it? Screenies please?
@creator: Now works perfectly!!, maybe in the future (sorry for ask to much xD, a Time metter bar would be great or a little add to make some items cant be put in the pot, to avoid the players put key items and can't continue in the game. :)) Thanks for all.

@rmvx_noobie: see the instructions men, copy the script and put above the main, and in the vx where says materials, below. and see the script head to how call it, and more instructions.
There is a good screenshot at the spoiler :).
Added the time meter and the item filter ;)
1. you forget to change the item_sort
2. update the demo
if i update the demo, the meters are missing
Try adding those meters to the Pictures folder (RMXP) i don't know what folder in VX:

http://i272.photobucket.com/albums/jj19 ... rEmpty.png[/img]
"MeterEmpty"

http://i272.photobucket.com/albums/jj19 ... erFull.png[/img]
"MeterFull"
I prefer for the meter, the Trickster's Draw_Gradient_Bar, I change to It, and looks perfect.
WoW WoW Wow

OMG OMG !!!

I love you The Sleeping Leonhart!!! :thumb:
Wow, this looks great! Exactly what I needed for my project. Thanks!

I love the item window, BTW! Reminds me of Elder Scrolls inventory. If I had the scripting skills, I would make that kind of item menu for my CMS. I have something like that already, but unfortunately I haven't been able to get it working properly... :(

A suggestion:
Is it possible to make it so that the player could make a recipe and then continue to play while it cooks?
Hmm

Original thread: https://www.hbgames.org/forums/viewtopic.php?t=59323