The RPG Maker Resource Kit

RMRK RPG Maker Creation => XP => XP Scripts Database => Topic started by: Mr_Wiggles on May 09, 2010, 10:34:42 PM

Title: Mr Wiggles Alchemy Script
Post by: Mr_Wiggles on May 09, 2010, 10:34:42 PM
Mr Wiggles Alchemy
Version: 2.4
Author: Mr Wiggles
Date: March 20, 2010

Version History



Planned Future Versions


Description


This script allows the player to combine up to four items in a simple to use script that will allow them to create items.

Features


Screenshots

Alchemy Screen
(http://screensnapr.com/u/6hxxmq.png)

Recipe Window
(http://screensnapr.com/u/w59tu0.png)

Instructions

Paste in the scripts database above main and then follow the instructions in the script header.

Script


Alchemy Script:
Code: [Select]
#===============================================================================
#                    Mr Wiggles Alchemy Script
#===============================================================================
# By Mr Wiggles
# Version 2.4
# 3-20-11
#-------------------------------------------------------------------------------
# Instructions:
#    Fill out the constants, And then call this script by using...
#    $scene = Alchemy.new
#===============================================================================

#-------------------------------------------------------------------------------
module ALCHEMY#/////////           *** EDIT AREA  ***                 /////////#
#-------------------------------------------------------------------------------
# Item IDs that can be used in Alchemy.
ALCHEMY_ITEMS   = [1,2,3,4]
#-------------------------------------------------------------------------------
# Item IDs that are not consumed when combined.
NON_CONSUME_ITEMS = [1,3]
#-------------------------------------------------------------------------------
# Weapon IDs that can be used in Alchemy.
ALCHEMY_WEAPONS = [1,2,3,4]
#-------------------------------------------------------------------------------
# Weapon IDs that are not consumed when combined.
NON_CONSUME_WEAPONS = [2,4]
#-------------------------------------------------------------------------------
# Armor IDs that can be used in Alchemy.
ALCHEMY_ARMORS  = [1,2,3,4]
#-------------------------------------------------------------------------------
# Armor IDs that are not consumed when combined.
NON_CONSUME_ARMORS = [2,3]
#-------------------------------------------------------------------------------
# Can combine more then the same type of item together, or just one of each.
COMBINE_DUPS = true
#-------------------------------------------------------------------------------
# Button that is used to check if the items being combined make anything.
CHECK_RECIPE_BUTTON = Keys::SHIFT
#-------------------------------------------------------------------------------
# Sound to play if the recipe was successful. leave blank if none.
RIGHT_SE = "055-Right01"
#-------------------------------------------------------------------------------
# Sound to play if the recipe failed. leave blank if none.
WRONG_SE = "057-Wrong01"
#-------------------------------------------------------------------------------
# recipes to make items. Example of a recipe:
# [[A,B], [A,B], [A,B], [A,B]]
# A = Type of Item in the recipe, (0 = Item, 1 = Weapon, 2 = Armor)
# B = ID if Item
# if slot is not being used in recipe, use 0.
ALCHEMY_RECIPES = [
[[0,2], [0,5], [0,6],   0  ], # 0 = 9 mm Rounds + Machine Gun Round + Bobby Pin
[[0,1], [1,1], [0,1], [0,1]], # 1 = 3 Arrows + Recurve Bow
[[0,2], [0,2],   0  ,   0  ], # 2 = 9 mm Rounds x2
[[1,2], [0,2], [2,3], [0,3]],
[[1,2], [2,6], [0,4],   0  ],
[[1,2], [2,5], [0,5],   0  ],
[[1,2], [2,4], [0,6],   0  ],
[[2,2], [0,2], [1,7],   0  ]
]# needs to be here
#-------------------------------------------------------------------------------
# Out comes of the above recipes:
# [A, B]
# A = Type of Creation (0 = Item, 1 = Weapon, 2 = Armor)
# B = ID of Item
ALCHEMY_OUTCOMES = [
[0, 10], # 0 Makes Flame Fuel
[1, 1],  # 1 Makes Recurve Bow
[2, 5],  # 2 Makes Leather Boots
[1, 2],
[1, 3],
[1, 4],
[1, 5],
[0, 3]
]# needs to be here
#-------------------------------------------------------------------------------
# Blue prints: the basic idea behind this is that the player can not create any
# items that they do not know how to create it. This can be done by using a
# script call command in an event that says:
# $game_system.add_blue_prints(Blue Print ID)
# the Blue print id refers to the location of the recipe in the
# ALCHEMY_RECIPES array, also remember that it starts counting at 0, this
# means that 1=0, 2=1, and so on.
#
# Bellow is the blue prints that the player already knows at the start of the
# game. [BP, BP, BP]  BP = Blue Print ID
BLUE_PRINTS = [1,2,4]
#-------------------------------------------------------------------------------
# Remove the items being combined if the recipe is wrong.
PENALIZE = false
#-------------------------------------------------------------------------------
# Give the player a junk item if the mix was wrong. PENALIZE must be true for
# this. If you don't want to use this set the ID to 0.
JUNK_ITEM_ID = 0
#-------------------------------------------------------------------------------
end#/////////              *** END EDIT AREA  ***                     /////////#
#-------------------------------------------------------------------------------


#===============================================================================
# ** Alchemy
#===============================================================================
class Alchemy
  #----------------------------------------------------------------
  # * Main
  #----------------------------------------------------------------
  def main
    # Create Windows
    @alchemy_window = Window_Alchemy.new
    @item_selection_window = Item_Selection_Window.new
    @help_window = Alchemy_Help.new
    @map_back    = Spriteset_Map.new
    @combination_window   = Combination_List_Window.new
    @finished_item_window = Finished_Item_Window.new
    # change Z
    @alchemy_window.z = 210
    @item_selection_window.z = 210
    @finished_item_window.z = 210
    @combination_window.z = 210
    @help_window.z = 210
    # Make variables
    @items_being_combined = []
    @recipes = ALCHEMY::ALCHEMY_RECIPES
    @out_comes = ALCHEMY::ALCHEMY_OUTCOMES
    @creation = []
    @combination = ""
    @showing_text_wait = 0
    # Execute transition
    Graphics.transition
    # Main loop
    loop do
      # Update game screen
      Graphics.update
      # Update input information
      Input.update
      # Frame update
      update
      # Abort loop if screen is changed
      if $scene != self
        break
      end
    end
    # Prepare for transition
    Graphics.freeze
    # Dispose of windows
    @alchemy_window.dispose
    @item_selection_window.dispose
    @help_window.dispose
    @map_back.dispose
    @combination_window.dispose
    @finished_item_window.dispose
  end
  #----------------------------------------------------------------
  # * Update
  #----------------------------------------------------------------
  def update
    # Show the names of items being added
    @showing_text_wait -= 1 if @showing_text_wait != 0
    if @showing_text_wait == 0
      item_names = []
      for item in @items_being_combined
        return if item == nil
        item_names << item.name.to_s
      end
      @combination = item_names.join(" + ")
      @finished_item_window.update
    end
    # Update Windows
    @alchemy_window.refresh(@items_being_combined)
    @item_selection_window.update
    @combination_window.update(@combination)
    # update mains
    update_help
    update_commands
  end
  #----------------------------------------------------------------
  # * Update Help
  #----------------------------------------------------------------
  def update_help
    if @item_selection_window.item != nil
      @help_window.set_text(@item_selection_window.item.description)
    end
  end
  #----------------------------------------------------------------
  # * Update Commands
  #----------------------------------------------------------------
  def update_commands
    #--------------------------
    # If B button was pressed
    #--------------------------
    if Input.trigger?(Input::B)
      @showing_text_wait = 0
      if @items_being_combined.size > 0
        item = @items_being_combined[@items_being_combined.size - 1]
        case item
        when RPG::Item
          $game_party.gain_item(item.id, 1) if
            !ALCHEMY::NON_CONSUME_ITEMS.include?(item.id)
        when RPG::Weapon
          $game_party.gain_weapon(item.id, 1) if
            !ALCHEMY::NON_CONSUME_WEAPONS.include?(item.id)
        when RPG::Armor
          $game_party.gain_armor(item.id, 1) if
            !ALCHEMY::NON_CONSUME_ARMORS.include?(item.id)
        end
        $game_system.se_play($data_system.cancel_se)
        @items_being_combined.delete_at(@items_being_combined.size - 1)
      else
        # Return to map
        $game_system.se_play($data_system.cancel_se)
        $scene = Scene_Map.new
      end
      # Update item selection window
      @item_selection_window.refresh
      return
    end
    #--------------------------
    # If C button was pressed
    #--------------------------
    if Input.trigger?(Input::C)
      @showing_text_wait = 0
      item = @item_selection_window.item
      return if item == nil
      if @items_being_combined.size < 4
        if !@items_being_combined.include?(item) and
            ALCHEMY::COMBINE_DUPS == false
          $game_system.se_play($data_system.decision_se)
          @items_being_combined << item
          case item
          when RPG::Item
            $game_party.gain_item(item.id, -1) if
              !ALCHEMY::NON_CONSUME_ITEMS.include?(item.id)
          when RPG::Weapon
            $game_party.gain_weapon(item.id, -1) if
              !ALCHEMY::NON_CONSUME_WEAPONS.include?(item.id)
          when RPG::Armor
            $game_party.gain_armor(item.id, -1) if
              !ALCHEMY::NON_CONSUME_ARMORS.include?(item.id)
          end
        elsif ALCHEMY::COMBINE_DUPS == true
          $game_system.se_play($data_system.decision_se)
          @items_being_combined << item
          case item
          when RPG::Item
            $game_party.gain_item(item.id, -1) if
              !ALCHEMY::NON_CONSUME_ITEMS.include?(item.id)
          when RPG::Weapon
            $game_party.gain_weapon(item.id, -1) if
              !ALCHEMY::NON_CONSUME_WEAPONS.include?(item.id)
          when RPG::Armor
            $game_party.gain_armor(item.id, -1) if
              !ALCHEMY::NON_CONSUME_ARMORS.include?(item.id)
          end
        else
          $game_system.se_play($data_system.buzzer_se)
        end
      else
        $game_system.se_play($data_system.buzzer_se)
      end
      # Update item selection window
      @item_selection_window.refresh
      return
    end
    #--------------------------
    # If Check button was pressed
    #--------------------------
    if Input.trigger?(ALCHEMY::CHECK_RECIPE_BUTTON)
      # check if the player was able to make anything
      @creation = []
      if @items_being_combined.size > 1
        for id in 0..@recipes.size - 1
          recipe = @recipes[id]
          new_recipe = recipe.flatten
          new_recipe.sort!
          # if player does not know recipe
          next unless $game_system.blue_prints.include?(id)
          # get created item
          @creation = @out_comes[id]
          # kill game to prevent syntax error
          if @creation == nil
            print ("There is no out come for the recipie, please add one.")
            $scene = nil
            return
          end
          # get items to be combine
          items_combined = []
          for i in 0..@items_being_combined.size - 1
            item = @items_being_combined[i]
            case item
            when RPG::Item
              type = 0
            when RPG::Weapon
              type = 1
            when RPG::Armor
              type = 2
            end
            item_array = [type, item.id]
            items_combined.push(item_array)
          end
          # fill empty slots with 0
          empty_slots = 4 - items_combined.size
          for i in 0..empty_slots
            items_combined << 0 if items_combined.size < 4
          end
          items_combined.flatten!
          items_combined.sort!
          # see if the combination matches any recipes then
          # returns the item that was created
          break if items_combined == new_recipe
          @creation = []
        end
        # show result
        if @creation != []
          Audio.se_play("Audio/SE/"+ALCHEMY::RIGHT_SE, 90, 100) rescue nil
          # Add Item
          case @creation[0]
          when 0
            $game_party.gain_item(@creation[1], 1)
            item = $data_items[@creation[1]]
          when 1
            $game_party.gain_weapon(@creation[1], 1)
            item = $data_weapons[@creation[1]]
          when 2
            $game_party.gain_armor(@creation[1], 1)
            item = $data_armors[@creation[1]]
          end
          # Clear Varaibles
          @items_being_combined = []
          @showing_text_wait = 120
          # Show text
          @combination = "Success! Looks like you made a(n) #{item.name}."
          @finished_item_window.update(item)
        else
          Audio.se_play("Audio/SE/"+ALCHEMY::WRONG_SE, 90, 100) rescue nil
          # Clear items being combined
          if ALCHEMY::PENALIZE
            @items_being_combined = []
            junk_id = ALCHEMY::JUNK_ITEM_ID
            $game_party.gain_item(junk_id, 1) if junk_id > 0
          end
          @showing_text_wait = 120
          # Show text
          @combination = "I don't think those go well together."
        end
      end
      # Update item selection window
      @item_selection_window.refresh
      return
    end
  end
end

#===============================================================================
# ** Game_System
#===============================================================================
class Game_System
  attr_accessor :blue_prints
 
alias alchemy_init initialize
  def initialize
    alchemy_init
    @blue_prints = ALCHEMY::BLUE_PRINTS
    @recipes = ALCHEMY::ALCHEMY_RECIPES
  end
 
  def add_blue_prints(prints)
    if !@blue_prints.include?(prints) and prints < @recipes.size - 1
      @blue_prints << prints
    end
  end
end

#===============================================================================
# ** Alchemy Window
#===============================================================================
class Window_Alchemy < Window_Base
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize
    super(176, 32, 288, 80)   
    self.opacity = 160
    self.contents = Bitmap.new(width - 32, height - 32)
    refresh([])
  end
  #--------------------------------------------------------------------------
  # * Refresh
  #--------------------------------------------------------------------------
  def refresh(items)
    @item_place = 0
    self.contents.clear
    for item in items
      draw_item(item, @item_place)
      @item_place += 1
    end
  end
  #--------------------------------------------------------------------------
  # * Refresh
  #--------------------------------------------------------------------------
  def draw_item(item, place)
    return if item == nil
    x = 0 + (place * 64)
    y = 0
    bitmap = RPG::Cache.icon(item.icon_name)
    w = bitmap.width
    h = bitmap.height
    src_rect  = Rect.new(0, 0, w, h)
    dest_rect = Rect.new(x, y, w*2, h*2)
    self.contents.stretch_blt(dest_rect, bitmap, src_rect)
  end
end

#===============================================================================
# ** Item Selection Window
#===============================================================================
class Item_Selection_Window < Window_Selectable
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
  def initialize
    super(0, 168, 640, 250)   
    self.opacity = 160
    @column_max = 3
    refresh
    self.index = 0
  end
#--------------------------------------------------------------------------
# * Refresh
#--------------------------------------------------------------------------
  def refresh
    if self.contents != nil
      self.contents.dispose
      self.contents = nil
    end
    @data = []
    # Add Items that can be combined
    for i in 1...$data_items.size
      if $game_party.item_number(i) > 0 and ALCHEMY::ALCHEMY_ITEMS.include?(i)
        @data.push($data_items[i])
      end
    end
    # Add Weapons that can be combined
    for i in 1...$data_weapons.size
      if $game_party.weapon_number(i) > 0 and ALCHEMY::ALCHEMY_WEAPONS.include?(i)
        @data.push($data_weapons[i])
      end
    end
    # Add Armors that can be combined
    for i in 1...$data_armors.size
      if $game_party.armor_number(i) > 0 and ALCHEMY::ALCHEMY_ARMORS.include?(i)
        @data.push($data_armors[i])
      end
    end
    # Make selection Window
    @item_max = @data.size
    if @item_max > 0
      self.contents = Bitmap.new(width - 32, row_max * 32)
      for i in 0...@item_max
        draw_item(i)
      end
    end
  end
#--------------------------------------------------------------------------
# * Item
#--------------------------------------------------------------------------
  def item
    return @data[self.index]
  end
#--------------------------------------------------------------------------
# * Item by index
#--------------------------------------------------------------------------
  def return_item(index)
    return @data[index]
  end
#--------------------------------------------------------------------------
# * Draw Item
#--------------------------------------------------------------------------
  def draw_item(index)
    # Load Item Data
    item = @data[index]
    case item
    when RPG::Item
      number = $game_party.item_number(item.id)
    when RPG::Weapon
      number = $game_party.weapon_number(item.id)
    when RPG::Armor
      number = $game_party.armor_number(item.id)
    end
    self.contents.font.color = normal_color
    # Creat Selector
    x = 4 + index % 3 * ((self.width - 30) / 3)
    if index == 1
      y = 0
    else
      y = index / 3 * 32
    end
    rect = Rect.new(x, y, self.width / @column_max, 32)
    self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
    # Create Item Icon
    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.size = 16
    if number > 1
      self.contents.draw_text(x, y + 8, 24, 32, number.to_s, 1)
    end
    # Draw Item name next to Icon
    self.contents.font.size = 16
    self.contents.draw_text(x+32, y, 130, 32, item.name)
  end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
  def update
    # If cursor is movable
    if self.active and @item_max > 0 and @index >= 0
      # Move cursor down
      if Input.repeat?(Input::DOWN)
        if @index < @item_max - @column_max
          $game_system.se_play($data_system.cursor_se)
          @index = (@index + @column_max) % @item_max
        end
      end
      # Move cursor up
      if Input.repeat?(Input::UP)
        if @index >= @column_max
          $game_system.se_play($data_system.cursor_se)
          @index = (@index - @column_max + @item_max) % @item_max
        end
      end
      # Move cursor right
      if Input.repeat?(Input::RIGHT)
        if (@index % 3 < 2)
          if @index != @item_max - 1
            @index += 1
            $game_system.se_play($data_system.cursor_se)
          end
        end
      end
      # Move cursor left
      if Input.repeat?(Input::LEFT)
        if (@index % 3 > 0)
          @index -= 1
          $game_system.se_play($data_system.cursor_se)
        end
      end
    end
    # Update cursor rectangle
    update_cursor_rect
  end
#--------------------------------------------------------------------------
# * Update Cursor Rectangle
#--------------------------------------------------------------------------
  def update_cursor_rect
    # If cursor position is less than 0
    if @index < 0
      self.cursor_rect.empty
      return
    end
    # Get current row
    row = @index / @column_max
    # If current row is before top row
    if row < self.top_row
      # Scroll so that current row becomes top row
      self.top_row = row
    end
    # If current row is more to back than back row
    if row > self.top_row + (self.page_row_max - 1)
      # Scroll so that current row becomes back row
      self.top_row = row - (self.page_row_max - 1)
    end
    # Calculate cursor width
    cursor_width = self.width / @column_max - 16
    # Calculate cursor coordinates
    x = @index % @column_max * (cursor_width + 4)
    y = @index / @column_max * 32 - self.oy
    # Update cursor rectangle
    self.cursor_rect.set(x, y, cursor_width, 32)
  end
end

#==============================================================================
# ** Alchemy_Help
#==============================================================================
class Alchemy_Help < Window_Base
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize
    super(0, 416, 640, 64)
    self.opacity = 160
    self.contents = Bitmap.new(width - 32, height - 32)
  end
  #--------------------------------------------------------------------------
  # * Set Text
  #--------------------------------------------------------------------------
  def set_text(text, align = 0)
    if text != @text or align != @align
      self.contents.clear
      self.contents.font.color = normal_color
      self.contents.draw_text(4, 0, self.width - 40, 32, text, align)
      @text = text
      @align = align
      @actor = nil
    end
    self.visible = true
  end
end

#==============================================================================
# ** Combination_List_Window
#==============================================================================
class Combination_List_Window < Window_Base
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize
    super(0, 120, 640, 48)
    self.opacity = 190
    self.contents = Bitmap.new(width - 32, height - 32)
    update
  end
  #--------------------------------------------------------------------------
  # * Update
  #--------------------------------------------------------------------------
  def update(text="")
    self.contents.clear
    self.contents.font.size = 17
    self.contents.draw_text(0, -6, 640, 32, text)
  end
end

#==============================================================================
# ** Finished_Item_Window
#==============================================================================
class Finished_Item_Window < Window_Base
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize
    super(276, 32, 96, 96)
    self.opacity = 0
    self.contents = Bitmap.new(width - 32, height - 32)
    update
  end
  #--------------------------------------------------------------------------
  # * Update
  #--------------------------------------------------------------------------
  def update(item=nil)
    self.contents.clear
    if item != nil
      bitmap = RPG::Cache.icon(item.icon_name)
      w = bitmap.width
      h = bitmap.height
      src_rect  = Rect.new(0, 0, w, h)
      dest_rect = Rect.new(0, 0, w*2, h*2)
      self.contents.stretch_blt(dest_rect, bitmap, src_rect)
    end
  end
end

Recipe Window:
Code: [Select]
#===============================================================================
#                         Alchemy Recipes
#===============================================================================
# By Mr Wiggles
# Version 1.4
# 3-20-11
#===============================================================================
#  Description:
#    This is a Window Class that when called will show the recipies that the
#    player knows to help remind them how to make something.  This requires
#    Mr Wiggles Alchemy Script V2.0 or higher script to work.
#-------------------------------------------------------------------------------
# Instructions:
#   Call this script with a script command in an event that says:
#   $scene = Recipes_List.new
#===============================================================================
class Recipes_List
  #----------------------------------------------------------------
  # * Main
  #----------------------------------------------------------------
  def main
    # Create Windows
    @recipe_window = Recipe_Window.new
    @recipe_header = Recipe_Header.new
    @recipe_header.set_text("Blue Prints for Creating Items.")
    # Execute transition
    Graphics.transition
    # Main loop
    loop do
      # Update game screen
      Graphics.update
      # Update input information
      Input.update
      # Frame update
      update
      # Abort loop if screen is changed
      if $scene != self
        break
      end
    end
    # Prepare for transition
    Graphics.freeze
    # Dispose of windows
    @recipe_window.dispose
    @recipe_header.dispose
  end
 
  #----------------------------------------------------------------
  # * Update
  #----------------------------------------------------------------
  def update
    @recipe_window.update
    #--------------------------
    # If B button was pressed
    #--------------------------
    if Input.trigger?(Input::B)
      # Return to map
      $game_system.se_play($data_system.cancel_se)
      $scene = Scene_Map.new
      return
    end
  end
end

#===============================================================================
# ** Recipe Window
#===============================================================================
class Recipe_Window < Window_Selectable
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize
    super(0, 64, 640, 416)
    @column_max = 1
    @index = 0
    @loop = true
    @out_comes = ALCHEMY::ALCHEMY_OUTCOMES
    @recipes = ALCHEMY::ALCHEMY_RECIPES
    refresh
  end
  #--------------------------------------------------------------------------
  # * Refresh
  #--------------------------------------------------------------------------
  def refresh
    if self.contents != nil
      self.contents.dispose
      self.contents = nil
    end
    # Add recipies into data
    @data = []
    for i in 0..@recipes.size - 1
      @data.push([@recipes[i], @out_comes[i]])
    end
    # Make selection Window
    @item_max = @data.size
    if @item_max > 0
      self.contents = Bitmap.new(width - 32, row_max * 64)
      for i in 0...@item_max
        draw_item(i)
      end
    end
  end
  #--------------------------------------------------------------------------
  # * Draw Item
  #--------------------------------------------------------------------------
  def draw_item(index)
    # Get recipe item datas
    recipe = @data[index][0]
    @recipe_data = []
    for i in 0..3
      next if recipe[i] == 0
      case recipe[i][0]
      when 0
        @recipe_data.push($data_items[recipe[i][1]])
      when 1
        @recipe_data.push($data_weapons[recipe[i][1]])
      when 2
        @recipe_data.push($data_armors[recipe[i][1]])
      end
    end
    # Get out come data
    out_come = @data[index][1]
    case out_come[0]
    when 0
      out_come_data = $data_items[out_come[1]]
    when 1
      out_come_data = $data_weapons[out_come[1]]
    when 2
      out_come_data = $data_armors[out_come[1]]
    end
    # Create Selector
    x = 4
    y = 64 * index
    rect = Rect.new(x, y, self.width / @column_max, 64)
    self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
    # Draw recipe text and icons
    @text_lengths = []
    self.contents.font.size = 15
    if $game_system.blue_prints.include?(index)
      item_names = []
      for item in @recipe_data
        item_names.push(item.name.to_s)
      end
      recipe_text = item_names.join(" + ")
    else
      recipe_text = "???????????????????????????????????????????"
    end
    self.contents.draw_text(x+78, y+15, 640, 64, recipe_text)
    # Draw out come text and icon
    self.contents.font.size = 22
    if $game_system.blue_prints.include?(index)
      out_come_text = out_come_data.name.to_s
      create_double_icon(out_come_data, x+24, y+6)
    else
      out_come_text = "???????????"
      self.contents.font.size = 50
      self.contents.draw_text(x+38, y, 640, 64, "?")
    end
    self.contents.font.size = 22
    self.contents.draw_text(x+88, y-15, 640, 64, out_come_text)
    # Draw recipe number
    number = (index + 1).to_s + "."
    self.contents.draw_text(x, y, 64, 32, number)
  end
  #--------------------------------------------------------------------------
  # * Create Double Sized Icon
  #--------------------------------------------------------------------------
  def create_double_icon(item, x, y)
    if item != nil
      bitmap = RPG::Cache.icon(item.icon_name)
      w = bitmap.width
      h = bitmap.height
      src_rect  = Rect.new(0, 0, w, h)
      dest_rect = Rect.new(x, y, w*2, h*2)
      self.contents.stretch_blt(dest_rect, bitmap, src_rect)
    end
  end
  #--------------------------------------------------------------------------
  # * Create Normal Sized Icon
  #--------------------------------------------------------------------------
  def create_normal_icon(item, x, y)
    if item != nil
      bitmap = RPG::Cache.icon(item.icon_name)
      self.contents.blt(x, y, bitmap, Rect.new(0, 0, 24, 24))
    end
  end
  #--------------------------------------------------------------------------
  # * Update Cursor Rectangle
  #--------------------------------------------------------------------------
  def update_cursor_rect
    if @index < 0
      self.cursor_rect.empty
      return
    end
    self.top_row = @index if @index < self.top_row
    if @index > self.top_row + (self.page_row_max - 1)
      self.top_row = @index - (self.page_row_max - 1)
    end
    y = @index * 64 - self.oy
    self.cursor_rect.set(4, y, self.width - 28, 64)
  end
  #--------------------------------------------------------------------------
  # * Get Top Row
  #--------------------------------------------------------------------------
  def top_row
    return self.oy / 64
  end
  #--------------------------------------------------------------------------
  # * Set Top Row
  #--------------------------------------------------------------------------
  def top_row=(row)
    row = 0 if row < 0
    row = row_max - 1 if row > row_max - 1
    self.oy = row * 64
  end
  #--------------------------------------------------------------------------
  # * Get Number of Rows Displayable on 1 Page
  #--------------------------------------------------------------------------
  def page_row_max
    return (self.height - 32) / 64
  end
end

#==============================================================================
# ** Recipe Header
#==============================================================================
class Recipe_Header < Window_Base
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize
    super(0, 0, 640, 64)
    self.opacity = 255
    self.contents = Bitmap.new(width - 32, height - 32)
  end
  #--------------------------------------------------------------------------
  # * Set Text
  #--------------------------------------------------------------------------
  def set_text(text, align = 0)
    if text != @text or align != @align
      self.contents.clear
      self.contents.font.color = normal_color
      self.contents.font.size = 24
      self.contents.draw_text(4, 0, self.width - 40, 32, text, align)
      @text = text
      @align = align
      @actor = nil
    end
    self.visible = true
  end
end

Support


If you find any errors or would like to suggest an idea for a future version post them in here.

Known Compatibility Issues

None that I know of.

Restrictions

Don't post this on any other forums without my permission, and you are free to edit the script in anyway but you must still give me credit some where.
Title: Re: Mr Wiggles Alchemy Script
Post by: cozziekuns on May 09, 2010, 10:54:15 PM
I can definately see how this could be useful.

Kudos to you, Mr. Wiggles.
Title: Re: Mr Wiggles Alchemy Script
Post by: modern algebra on May 09, 2010, 11:52:21 PM
I like the design of this - very unique for creation scripts.
Title: Re: Mr Wiggles Alchemy Script
Post by: Mr_Wiggles on May 09, 2010, 11:54:59 PM
Thanks guys. :D
Title: Re: Mr Wiggles Alchemy Script
Post by: Grafikal on May 09, 2010, 11:59:04 PM
I wish my real-life alchemy level was high enough to make something out of arrows, machine gun ammo and shotgun shells besides just an arrow with some metal and plastic taped to the end.
Title: Re: Mr Wiggles Alchemy Script
Post by: Mr_Wiggles on May 10, 2010, 12:04:48 AM
I wish my real-life alchemy level was high enough to make something out of arrows, machine gun ammo and shotgun shells besides just an arrow with some metal and plastic taped to the end.
rofl..
Title: Re: Mr Wiggles Alchemy Script
Post by: recon2009 on May 18, 2010, 10:41:39 AM
I can't get the script to work. I copied the script above main, then I called $scene = Alchemy.new through an event on map (with the default constants) and when I try to activate it, it says: Script 'Craft_Script' line 122: NoMethodError occurred. undefined method `description' for nil:NilClass
Then I have changed the constants like this:

13 ALCHEMY_ITEMS = [1,2,3]
16 COMBINE_DUPS = false
19 CHECK_RECIPE_BUTTON = Input::A
31 ALCHEMY_RECIPES = [
32 [1,2,0,0,3]
33 ]
45 BLUE_PRINTS =
48 PENALIZE = true

Then... the same error... after that I tried to add a blueprint through call script feature: $game_system.add_blue_prints(0) and when I try to take the blueprint: Script 'Craft_Script' line 250: NoMethodError occurred. undefined method `include' for

I'm pretty new to RMXP so you'l have to excuse me if I talk gibberish or/and don't understand a word...
Title: Re: Mr Wiggles Alchemy Script
Post by: Mr_Wiggles on May 18, 2010, 05:17:51 PM
its fine, i know what it is that is going wrong i was gonna update this script, but the forum crashed. When i get on my computer i will upload the new version.

[Updated]
Title: Re: Mr Wiggles Alchemy Script
Post by: recon2009 on May 19, 2010, 04:46:51 AM
Still not working :P Sorry if I annoy anyone... (I have made some testing:)

So... with the default values, I open the Alchemy scene without having any item in my inventory. The Alchemy window it's empty and when I press Enter or C or Space on an empty space, I got the following error: Script 'Alchemy_Script' line 132: NoMethodError occurred. undefined method `name' for nil:NilClass. The X or ESC keys work if I want to get out of the Alchemy window or I want to remove an item.

Problem 2: If I have more than 2 or more items (for example: 2 High Potions) I got the following: Script 'Alchemy_Script' line 464: NoMethodError occurred. undefined method `draw_hemming_text' for #<Bitmap:0x134fb50>. Do I need some extra pictures in the Graphic directory?

Problem 3: I wanted to create an Bronze Helm ALCHEMY_OUTCOMES = [ [0, 10],... (line 50) and I need 1 High Potion and 1 Full Potion: ALCHEMY_RECIPES = [...[[0,2], [0,3], 0, 0], ] (line 42). Then I enter the game, I take one of each potion, I select them in the Alchemy window, and when I press the Z key to craft the item: Script 'Alchemy_Script' line 464: NoMethodError occurred. undefined method `draw_hemming_text' for #<Bitmap:0x130a478>

The Blueprints window work, I can see all the blueprints and if I modify the item requirements for an item that needs to be crafted in the script, it shows the ingredients properly in the Blueprints window. I haven't tested yet how to learn a blueprint because I saw that there was one with a lot of ????????'s 

I really hope that I will get the script to work because it remembers me of the crafting system in Anarchy Online and that's a good one with lot of potential in RMXP games :D
Title: Re: Mr Wiggles Alchemy Script
Post by: Mr_Wiggles on May 19, 2010, 06:55:46 AM
the  ? ? ? marks are just a filler for the recipes, for just the ones that are unknown.

also i have updated the script.  and your not annoying anyone. (well least not me)

thanks for helping me fix my mistakes, it will help me become a better scripter.
Title: Re: Mr Wiggles Alchemy Script
Post by: recon2009 on May 19, 2010, 10:17:52 AM
YAY! It's finally working   ^-^  Cheers Mr_Wiggles! and keep the good work coming :D It was a pleasure to criticize you (erm.. helping you :D)
Title: Re: Mr Wiggles Alchemy Script
Post by: Mr_Wiggles on May 19, 2010, 10:37:24 AM
:) thanks, good luck with your game.
Title: Re: Mr Wiggles Alchemy Script
Post by: recon2009 on May 20, 2010, 08:26:21 PM
Here is an quick update suggestion:

1.) Make somehow that some items can be made only if you are near or staying on an event. For example you can brew potions only if you are standing near an alchemist's bench, you can cook only near a fire source, etc...

2.) Make that some items don't disappear from inventory after you used them in a craft. For example knife + book = slashed pages, the book will disappear from inventory as default but the knife not. Or you can add multiple results from crafting, for example knife + book = slashed pages and knife.

I don't know if the suggestion NR.2 is already included in the script, I didn't had the time to experiment to much with it, and if it is, tell me please how to make it work :D , I don't have to much free time atm...
Title: Re: Mr Wiggles Alchemy Script
Post by: firerain on May 20, 2010, 08:49:16 PM
since when is alchemy crafting?
Title: Re: Mr Wiggles Alchemy Script
Post by: Mr_Wiggles on May 21, 2010, 12:28:43 AM
@ Firerain - idk

@  recon2009 - nice suggestions when i get the time i can try to implement them into a new version.
Title: Re: Mr Wiggles Alchemy Script
Post by: apoclaydon on May 21, 2010, 06:09:24 AM
I got the script working but i have 2 problems
1) potions no longer appear in my invetory (but appear in the alchemy list wen picking ingrediants)
2)game crashes after battle giving this error


????????NameError?????????
unitialized constant Interpriator::Scene_plan_alch

I'm currently using
Blizzards Tons of Addons, Final Fantasty 7 Menu and Blizzard Chaos Limit Rage Scripts and they work fine together
Title: Re: Mr Wiggles Alchemy Script
Post by: recon2009 on May 21, 2010, 07:40:36 AM
@ Firerain - As long as you can combine two or more items of your wish, that's crafting :P the possibilities are unlimited...
Title: Re: Mr Wiggles Alchemy Script
Post by: Mr_Wiggles on May 21, 2010, 08:50:30 AM
I got the script working but i have 2 problems
1) potions no longer appear in my invetory (but appear in the alchemy list wen picking ingrediants)
2)game crashes after battle giving this error


????????NameError?????????
unitialized constant Interpriator::Scene_plan_alch

I'm currently using
Blizzards Tons of Addons, Final Fantasty 7 Menu and Blizzard Chaos Limit Rage Scripts and they work fine together

What script in blizzards Addons are you using?

i looked at the scripts that you where talking about and i didn't find anything that would make them not work together.  Where in the scripts data base did you put this? (above main bellow the defaults, is it above or bellow these other scripts or not, that kinda stuff)
Title: Re: Mr Wiggles Alchemy Script
Post by: apoclaydon on May 21, 2010, 08:23:38 PM
I placed the 2 scripts directly above the main script and underneth the rest of the custom scripts i'm using

(http://i278.photobucket.com/albums/kk85/apoclaydon/th_rgpxperror.jpg) (http://i278.photobucket.com/albums/kk85/apoclaydon/rgpxperror.jpg)


Fixed the crashing i think i just forgot to remove a previous alchemy a call script but the pottions still dnt show in the item menus but they do show in the alchemy windows
Title: Re: Mr Wiggles Alchemy Script
Post by: Mr_Wiggles on May 22, 2010, 01:06:52 AM
what ff7 script are you using i looked one up but i there might be more then one version what i think is happening is that the windows used in both scripts to show the items are sharing the same name.
Title: Re: Mr Wiggles Alchemy Script
Post by: apoclaydon on May 22, 2010, 01:47:09 AM
yh the scriot is
http://www.rpgrevolution.com/forums/index.php?showtopic=18488
Title: Re: Mr Wiggles Alchemy Script
Post by: Mr_Wiggles on May 22, 2010, 01:53:29 AM
Try to place the alchemy script above all of your add on ones.
Title: Re: Mr Wiggles Alchemy Script
Post by: apoclaydon on May 22, 2010, 10:04:30 AM
still dsnt show potions in inventory (snt matter gonna redo the database anyway so i'll leave slot on blank)
Title: Re: Mr Wiggles Alchemy Script
Post by: Amurant on May 27, 2010, 11:51:50 PM
wow! this is awesome! thanks for posting it. I will defenitly use it in my game.
All I need to learn now is how to add and change some recipes. felt a bit wierd that a High Potion + High Potion will create a erm Bronze Helm?
And that an Iron Shield + High Potion +  Steel Spear will create a Full potion.
Ah well I hope that I will be able to undearstand how to create my own recipes.
Still new to scripting have only made games without extra scripts befour so well I am a noob a guess.
If I am to stupid to understand how to fix recipes I will come back and ask. And thank you again for making this awesome script.
Title: Re: Mr Wiggles Alchemy Script
Post by: Amurant on May 28, 2010, 12:17:40 AM
Oh NO! got a problem..

Made a test char with a list of event commands that looks like this
@>Show Choices: Show Recipe list, Time for Alchemy
 : When [Show Recipe list]
  @>Script: $scene = Recipes_List.new
  @>
 : When [Time for Alchemy]
  @>Script: $scene = Alchemy.new
  @>
 : Branch End
@>

well it works fine. when I choose the show recipe it shows the recipe list
and when I choose the Time for Alchemy option I get the Alchemy window
and I can create an item or two.
but if I create an Item and then talk with the guy again and choose Recipe list I get an error message that follows

Script 'Recipe' line141:NoMethodError occured.
undefined method `name' for nil:NilClass
Title: Re: Mr Wiggles Alchemy Script
Post by: Mr_Wiggles on May 28, 2010, 07:08:41 PM
did you talk to him after you created every item you could? and are you using the latest version of the script?
Title: Re: Mr Wiggles Alchemy Script
Post by: Amurant on May 29, 2010, 12:38:35 AM
Well I am using the script that is posted in this thread. And I have recreated the script and the character but as soon as I create an item the "show recipe" option makes the game to crash and I get the message

Script 'Recipe' line141:NoMethodError occured.
undefined method `name' for nil:NilClass

I can talk with him again and create more items but I can't check the recipe list again.
Title: Re: Mr Wiggles Alchemy Script
Post by: Mr_Wiggles on June 08, 2010, 10:58:59 PM
yea i found the time to fix this, but i'm not on my computer so when i get internet on it again i can upload the new version of the script.
Title: Re: Mr Wiggles Alchemy Script
Post by: Amurant on June 10, 2010, 09:58:19 AM
thanks I will be waiting
Title: Re: Mr Wiggles Alchemy Script
Post by: Mr_Wiggles on June 12, 2010, 02:15:47 AM
*Updated the script*
Title: Re: Mr Wiggles Alchemy Script
Post by: Demonaci on July 07, 2010, 01:44:53 AM
Hey Mr. Wiggles I get this error Script 'Alchemy' Line 37: NameError occurred uninitialized Constant ALCHEMY::Keys. I was wondering if u could help me fix and possible to add it to my menu screen
Title: Re: Mr Wiggles Alchemy Script
Post by: Mr_Wiggles on July 07, 2010, 02:19:59 AM
OH sorry that's my bad, i am useing an Input module in my game so i have some extra keys i can use. To fix this just go to that line and where it says "Keys::SHIFT" Change that to any one of RPG Inputs...
#----- Button -------- #
#  A B C X Y Z L R    #
#------Key Borad ----#     The equivalent on the keyboard.
#  Z B C A S D Q W  #         
#--------------------------#

So "Input::A" would be key "Z" and so forth. (yes you have to have Input:: before your desired button)

For adding it into your game menu you'll have to edit a little bit in the menu script and a few others.
Title: Re: Mr Wiggles Alchemy Script
Post by: Yggdrasil12 on August 04, 2010, 09:26:58 PM
Hello, Mr. Wiggles.  This seems like it would be a great addition to any game.  However, I am new to scripting and am having some problems with the script.

First of all, there is absolutely no text on any of the items or descriptions in the alchemy menu.  Only the icons appear.  How do I fix this?

Also, when I try to load the Blue Print list in-game using a $game_system.add_blue_prints( ), I get a bad syntax on line 354 "undefined method 'size' for 'nil:NilClass'  What am I doing wrong.

I can't wait to get this script working and use it for my game.  Great job!
Title: Re: Mr Wiggles Alchemy Script
Post by: dewm3734 on August 14, 2010, 12:32:52 PM
hey mr wiggles, iv had a few probs but iv managed to fix them by reading the forum so this question hasn't been asked before (I think...). For some reason i cant add any knew recipes, like combination's of stuff to make you know? its a syntax on line 56 please help i also tried shifting the default down a line and added my own in between and it still says the same thing so i think that iv missed something that tells the computer how many recipes there are maybe??
Title: Re: Mr Wiggles Alchemy Script
Post by: Mr_Wiggles on August 25, 2010, 01:51:56 AM
i will look into these errors when i find the chance i was gone for 3 weeks RL stuff and getting into college classes, chances are i will look at these errors this week end.

[edit]
   @Yggdrasil12 - you need to put the blue print number for the blue prints your adding to the list of known ones. IE add blue prints 4 you would
$game_system.add_blue_prints(4)
or like to add prints 15
$game_system.add_blue_prints(15)

[edit2]
  @dewm3734 - ca you post what you have on that line so i can see what is wrong with it.
Title: Re: Mr Wiggles Alchemy Script
Post by: drmckillicuddy on March 15, 2011, 11:50:01 PM
Don't know if you even come here anymore, but Mr Wiggles, I'm having a problem with the call script command for the blueprints. When I try to add a recipe, I get a message that reads, line 357 NoMethodError occured
                             undefined method `size' for nil:NilClass

Any thoughts?
Title: Re: Mr Wiggles Alchemy Script
Post by: Mr_Wiggles on March 21, 2011, 03:06:41 AM
Yea sorry about the delays, but i do check this forum from time to time for support on my scripts, i have updated with a newer version which i think fixed all the problems.
Title: Re: Mr Wiggles Alchemy Script
Post by: drmckillicuddy on April 09, 2011, 01:59:21 PM
Thanks, it works great now.
Title: Re: Mr Wiggles Alchemy Script
Post by: crow5757 on August 23, 2011, 05:40:32 PM
this is annoying me. This script keeps putting all it's info on one line in my script editor. I'm quite frustrated. Also, the screenshots don't work anymore on this topic.  what is going on?  :-\
Title: Re: Mr Wiggles Alchemy Script
Post by: Mr_Wiggles on August 25, 2011, 07:57:14 PM
The img urls expired and i have no clue why its putting all the script information on one line.
Title: Re: Mr Wiggles Alchemy Script
Post by: pacdiggity on August 26, 2011, 08:10:30 AM
It's because SMF code-boxes and Internet Explorer do not mix. It works on pretty much everything else.
Title: Re: Mr Wiggles Alchemy Script
Post by: drmckillicuddy on October 16, 2011, 01:25:45 AM
I don't have a clue why, but the recipe book script isn't working for me anymore. It worked when I was first using it, everything that my characters learned to make in the alchemy script would show up just fine. I haven't done anything to any other scripts or added any new ones, but now when I try to call the recipe list, I get a message reading, "...line 123 NoMethodError occurred. Undefined method `[]' for nil:NilClass.
Title: Re: Mr Wiggles Alchemy Script
Post by: drmckillicuddy on October 16, 2011, 01:54:43 PM
I know it can't be a problem with your script, I just want to determine where the problem lies. 'Line 123' is in the "Draw Item" section of the script. What does that pertain to, anyway? If I know, then I can probably find the problem.
Title: Re: Mr Wiggles Alchemy Script
Post by: drmckillicuddy on October 18, 2011, 12:10:05 AM
Okay, never mind. I don't know what the hell is going on, but I got it working. I needed to keep a blank line between my last creatable item and the line that says
"]# needs to be here" in the alchemy script for the recipe script to work. I don't know why exactly...I never had to do that before...
Title: Re: Mr Wiggles Alchemy Script
Post by: Mr_Wiggles on October 24, 2011, 09:06:19 PM
So you do in fact have this working? Also there is an edit button for your previous post and i know not using it makes mods here angry, just saying.
Title: Error
Post by: rayquaza1000 on December 14, 2011, 10:59:42 PM
Help, I keep on getting this error:


Script 'Recipes' line 139: NoMethodError occured.

undefined method 'blue_prints' for #<Game_System:0x83ccd30>


I am a noob and have no idea how to fix this error. HELP!
Title: Re: Mr Wiggles Alchemy Script
Post by: Mr_Wiggles on December 14, 2011, 11:11:26 PM
I can fix your error but you'll need to wait till tomorrow, i don't have the time right now to fix it. I just wanted you to know that i know about it.
Title: Re: Mr Wiggles Alchemy Script
Post by: rayquaza1000 on December 16, 2011, 10:22:32 PM
Thanks I'll be waiting! ^-^
Title: Re: Mr Wiggles Alchemy Script
Post by: rayquaza1000 on December 20, 2011, 11:51:16 PM
Mr. Wiggles?
Is anyone there? :-\
Title: Re: Mr Wiggles Alchemy Script
Post by: pacdiggity on December 21, 2011, 12:44:38 AM
An error like that is probably caused by a corrupt save file. Does the project work in a new game?
Title: Re: Mr Wiggles Alchemy Script
Post by: rayquaza1000 on December 21, 2011, 11:31:27 AM
Nope, I get the same error! :'(
Title: Re: Mr Wiggles Alchemy Script
Post by: rayquaza1000 on December 21, 2011, 10:38:12 PM
Aaaaaahhhhhh!
I have a new error:
Script 'Alchemy' line263:NoMethodError occured.
undefined method `include?' for nil:NilClass
Help
I think I'm going crazy, I keep seeing errors everywhere :aryan:
Title: Re: Mr Wiggles Alchemy Script
Post by: rayquaza1000 on December 27, 2011, 10:00:41 PM
HEY, is anyone there?
Title: Re: Mr Wiggles Alchemy Script
Post by: Mr_Wiggles on January 05, 2012, 07:50:18 PM
Yep, im here, and im looking into replicating the error so i can fix it.

[edit]
Can you post what your script header looks like?