PrexCraft - Crafting Script

PrexCraft
Version: 2.0

Introduction

Similar to Axe Man Deke's crafting script, this is PrexCraft

Allows you to generate any number of recipes, quickly and easily. Offers multiple components, one result, consumable and non-consumable components, and a quick and simple interface.

V1.01: Fixed a small bug allowing for the same recipe to be learned more than once.

V1.02: Removed the Elements module, as it was brought to my attention that I could use $data_system.elements[]

v2.0: Added many new features. These are listed below in the Features section.

Features
  • Quick and Easy!
  • Multiple Components
  • Built-In Interface!
New in 2.0!
  • Recipe Types! You can now separate cooking recipes from smithing, tailoring, or anything you wish!
  • Recipe and Trade Levels! You can now apply trade levels to your party, allowing you to level up skills and be capable of new recipes!
  • Icons! You can now enable and disable icons in each of the three Craft windows.

Demo

Version 1.0 Demo hosted at rm-dev.org (Out of Date!)

Version 2.0 Demo hosted at rm-dev.org

Script

Version 2.0 Show
  1. #===============================================================================
  2. # Module Craft by Prexus
  3. #  - Version 2.0 (12.31.06)
  4. #-------------------------------------------------------------------------------
  5. # This is the primary module of the PrexCraft script. Be sure to read the
  6. # instructions to learn how to create new recipes. Do not change any of the
  7. # constants in the DO NOT TOUCH section.
  8. #===============================================================================
  9.  
  10. module Craft
  11.   #=============================================================================
  12.   # CONSTANTS :: DO NOT TOUCH
  13.   #=============================================================================
  14.   ITEM = 0; ARMOR = 1; WEAPON = 2
  15.   NOT_CONSUMED = false; CONSUMED = true;
  16.  
  17.   #=============================================================================
  18.   # CONSTANTS :: PLEASE TOUCH THESE.. BABY!
  19.   #=============================================================================
  20.   USE_LEVELS           = true  # Use Levels for skills.
  21.   SHOW_COLORS          = true  # Use colorcoding (only for Levels)
  22.   SHOW_LEVELS          = true  # Show recipe level display
  23.   SHOW_LEVEL_UP        = true  # Show level up window
  24.   SHOW_LIST_ICONS      = true  # Show icons in recipe list
  25.   SHOW_RESULT_ICON     = true  # Show icons in result window
  26.   SHOW_COMPONENT_ICONS = true  # Show icons in component window
  27.  
  28.   #=============================================================================
  29.   # TRADE :: OFFSET LEVEL RANGE (edit with caution) (For use with levels only)
  30.   #=============================================================================
  31.   TRADE_LEVEL_OFFSET = 10
  32.  
  33.   #=============================================================================
  34.   # COLORS :: EDIT WITH CAUTION (For use with Levels only)
  35.   #=============================================================================
  36.   TRIVIAL    = Color.new( 64,  64,  64, 255)
  37.   LOW        = Color.new(  0, 255,   0, 255)
  38.   MID        = Color.new(255, 255,   0, 255)
  39.   HIGH       = Color.new(255, 128,   0, 255)
  40.   IMPOSSIBLE = Color.new(255,   0,   0, 255)
  41.  
  42.   #=============================================================================
  43.   # RECIPES :: Follow Instructions
  44.   #-----------------------------------------------------------------------------
  45.   # FORMAT :
  46.   # {'NAME' => 'RECIPE NAME AS STRING',
  47.   #  'TYPE' => 'RECIPE TYPE AS STRING',
  48.   #  'LEVEL' => LEVEL_AS_INTEGER,  << Not Necessary with USE_LEVELS set to False
  49.   #  'RESULT' => [TYPE, ID, VALUE],
  50.   #  'COMPONENTS' => [
  51.   #    [TYPE, ID, VALUE, CONSUMED?],
  52.   #    [TYPE, ID, VALUE, CONSUMED?],
  53.   #    ...
  54.   #  ]
  55.   # }
  56.   #-----------------------------------------------------------------------------
  57.   # To setup a recipe, follow the example below:
  58.   #-----------------------------------------------------------------------------
  59.   # {'NAME' => 'Cold Iron Sword',
  60.   #  'TYPE' => 'Blacksmith',
  61.   #  'LEVEL' => 10,
  62.   #  'RESULT' => [WEAPON, 1, 1],
  63.   #  'COMPONENTS' => [
  64.   #    [ITEM, 1, 1, CONSUMED],
  65.   #    [ITEM, 2, 1, CONSUMED],
  66.   #    [WEAPON, 3, 1, NOT_CONSUMED]
  67.   #  ]
  68.   # } # End Recipe [WEAPON, 1, 1]
  69.   #=============================================================================
  70.   RECIPES = [
  71.     {'NAME' => 'Cold Sword',
  72.      'TYPE' => 'Blacksmith',
  73.      'LEVEL' => 1,
  74.      'RESULT' => [WEAPON, 33, 1],
  75.      'COMPONENTS' => [
  76.        [ITEM, 33, 1, CONSUMED],
  77.        [WEAPON, 1, 1, CONSUMED]
  78.      ]
  79.     },
  80.     {'NAME' => 'Tempered Sword',
  81.      'TYPE' => 'Blacksmith',
  82.      'LEVEL' => 20,
  83.      'RESULT' => [WEAPON, 34, 1],
  84.      'COMPONENTS' => [
  85.        [ITEM, 38, 1, NOT_CONSUMED],
  86.        [WEAPON, 1, 1, CONSUMED]
  87.      ]
  88.     },
  89.     {'NAME' => 'Apple Pie',
  90.      'TYPE' => 'Cook',
  91.      'LEVEL' => 1,
  92.      'RESULT' => [ITEM, 36, 1],
  93.      'COMPONENTS' => [
  94.        [ITEM, 34, 1, NOT_CONSUMED],
  95.        [ITEM, 35, 3, CONSUMED]
  96.      ]
  97.     }
  98.   ]
  99.  
  100.   #=============================================================================
  101.   # Craft Methods
  102.   #-----------------------------------------------------------------------------
  103.   # valid_recipe? : name
  104.   # Checks if the recipe name given exists in the recipe data store.
  105.   #=============================================================================
  106.   def self.valid_recipe?(name)
  107.     for recipe in RECIPES
  108.       return true if name == recipe['NAME']
  109.     end
  110.     return false
  111.   end
  112.  
  113.   #=============================================================================
  114.   # Craft Methods
  115.   #-----------------------------------------------------------------------------
  116.   # can_make? : name
  117.   # Checks if the recipe is possible to make. First finds if the recipe given is
  118.   # valid, then checks if there are enough components in your inventory.
  119.   #=============================================================================
  120.   def self.can_make?(name)
  121.     return false unless self.valid_recipe?(name)
  122.     for r in RECIPES
  123.       next unless name == r['NAME']
  124.       recipe = r
  125.     end
  126.     return false unless recipe
  127.     for component in recipe['COMPONENTS']
  128.       case component[0]
  129.       when 0 # ITEM
  130.         return false unless $game_party.item_number(component[1]) >= component[2]
  131.       when 1 # ARMOR
  132.         return false unless $game_party.armor_number(component[1]) >= component[2]
  133.       when 2 # WEAPON
  134.         return false unless $game_party.weapon_number(component[1]) >= component[2]
  135.       end
  136.     end
  137.     return true
  138.   end
  139.  
  140.   #=============================================================================
  141.   # Craft Methods
  142.   #-----------------------------------------------------------------------------
  143.   # get_recipe : name
  144.   # Returns the hash object containing the data information for the recipe if
  145.   # the recipe is valid. Else returns nil.
  146.   #=============================================================================
  147.   def self.get_recipe(name)
  148.     return nil unless self.valid_recipe?(name)
  149.     for recipe in RECIPES
  150.       return recipe if recipe['NAME'] == name
  151.     end
  152.     return nil
  153.   end
  154.  
  155.   #=============================================================================
  156.   # Craft Methods for LEVELS
  157.   #-----------------------------------------------------------------------------
  158.   # color_chart : diff
  159.   # Returns the color suited for the recipe based on the difference between the
  160.   # recipe level and your party's skill level
  161.   #=============================================================================
  162.   def self.color_chart(diff)
  163.     if diff < 0
  164.       return IMPOSSIBLE
  165.     elsif (0...TRADE_LEVEL_OFFSET).to_a.include?(diff)
  166.       return HIGH
  167.     elsif (TRADE_LEVEL_OFFSET...TRADE_LEVEL_OFFSET * 2).to_a.include?(diff)
  168.       return MID
  169.     elsif (TRADE_LEVEL_OFFSET * 2...TRADE_LEVEL_OFFSET * 3).to_a.include?(diff)
  170.       return LOW
  171.     else
  172.       return TRIVIAL
  173.     end
  174.   end
  175.  
  176.   #=============================================================================
  177.   # Craft Methods for LEVELS
  178.   #-----------------------------------------------------------------------------
  179.   # level_skill : skill, diff
  180.   # Raises the level of the skill based on the difference between the recipe
  181.   # level and the party's skill level.
  182.   #=============================================================================
  183.   def self.level_skill(skill, diff)
  184.     if (0...TRADE_LEVEL_OFFSET).to_a.include?(diff)
  185.       if rand(10) >= 1
  186.         $game_party.trade_level_up(skill, 1)
  187.         return true
  188.       else
  189.         return false
  190.       end
  191.     elsif (TRADE_LEVEL_OFFSET...TRADE_LEVEL_OFFSET * 2).to_a.include?(diff)
  192.       if rand(10) >= 3
  193.         $game_party.trade_level_up(skill, 1)
  194.         return true
  195.       else
  196.         return false
  197.       end
  198.     elsif (TRADE_LEVEL_OFFSET * 2...TRADE_LEVEL_OFFSET * 3).to_a.include?(diff)
  199.       if rand(10) >= 6
  200.         $game_party.trade_level_up(skill, 1)
  201.         return true
  202.       else
  203.         return false
  204.       end
  205.     else
  206.       return false
  207.     end
  208.   end
  209. end
  210.  
  211. #===============================================================================
  212. # Scene Craft
  213. #-------------------------------------------------------------------------------
  214. # This is the main interface for the crafting system. You can run it by using
  215. # the callscript command '$scene = Scene_Craft.new' or by adding it to your own
  216. # code in the same manner.
  217. #===============================================================================
  218.  
  219. class Scene_Craft
  220.   def initialize(type = nil)
  221.     @type = type
  222.   end
  223.   def main
  224.     @recipe_list = Window_RecipeList.new(@type)
  225.     @result_info = Window_ResultInfo.new(@recipe_list.data)
  226.     @result_comp = Window_ResultComponents.new(@recipe_list.data)
  227.     Graphics.transition
  228.     loop do
  229.       Graphics.update
  230.       Input.update
  231.       update
  232.       break if $scene != self
  233.     end
  234.     Graphics.freeze
  235.     @recipe_list.dispose
  236.     @result_info.dispose
  237.     @result_comp.dispose
  238.     @level_window.dispose if @level_window
  239.   end
  240.   #-----------------------------------------------------------------------------
  241.   def update
  242.     @recipe_list.update
  243.     @result_info.update(@recipe_list.data)
  244.     @result_comp.update(@recipe_list.data)
  245.     if @level_window
  246.       @level_window.update
  247.       @level_window.opacity -= 2
  248.       @level_window.contents_opacity -= 2
  249.       if @level_window.opacity == 0
  250.         @level_window.dispose
  251.         @level_window = nil
  252.       end
  253.     end
  254.     if Input.trigger?(Input::B)
  255.       $game_system.se_play($data_system.cancel_se)
  256.       $scene = Scene_Map.new
  257.       return
  258.     end
  259.     if Input.trigger?(Input::C)
  260.       if craft(@recipe_list.data)
  261.         $game_system.se_play($data_system.decision_se)
  262.       else
  263.         $game_system.se_play($data_system.buzzer_se)
  264.       end
  265.       @recipe_list.refresh
  266.       @result_info.refresh
  267.       @result_comp.refresh
  268.       return
  269.     end
  270.   end
  271.   #-----------------------------------------------------------------------------
  272.   def craft(recipe)
  273.     return false unless Craft.can_make?(recipe)
  274.     recipe = Craft.get_recipe(@recipe_list.data)
  275.     if Craft::USE_LEVELS
  276.       skill = (recipe['TYPE'] ? recipe['TYPE'] : nil)
  277.       level = (recipe['LEVEL'] ? recipe['LEVEL'] : 1)
  278.       if skill
  279.         return unless $game_party.trade_check?(skill, level)
  280.         diff = ($game_party.trade_skills[skill] - level).abs
  281.         old_level = $game_party.trade_skills[skill]
  282.         if Craft.level_skill(skill, diff)
  283.           if Craft::SHOW_LEVEL_UP
  284.             if @level_window
  285.               @level_window.dispose
  286.               @level_window = nil
  287.             end
  288.             @level_window = Window_Base.new(0, 0, 256, 64)
  289.             @level_window.contents = Bitmap.new(224, 32)
  290.             @level_window.x = 320 - @level_window.width / 2
  291.             @level_window.y = 240 - @level_window.height / 2
  292.             @level_window.z = 9998
  293.             @level_window.contents.draw_text(4, 0, 224, 32,
  294.               "#{skill} +#{($game_party.trade_skills[skill] - old_level).abs}", 1)
  295.           end
  296.         end
  297.       end
  298.     end
  299.     for component in recipe['COMPONENTS']
  300.       case component[0]
  301.       when 0 # Item
  302.         $game_party.lose_item(component[1], component[2]) if component[3]
  303.       when 1 # Armor
  304.         $game_party.lose_armor(component[1], component[2]) if component[3]
  305.       when 2 # Weapon
  306.         $game_party.lose_weapon(component[1], component[2]) if component[3]
  307.       end
  308.     end
  309.     case recipe['RESULT'][0]
  310.     when 0 # Item
  311.       $game_party.gain_item(recipe['RESULT'][1], recipe['RESULT'][2])
  312.     when 1 # Armor
  313.       $game_party.gain_armor(recipe['RESULT'][1], recipe['RESULT'][2])
  314.     when 2 # Weapon
  315.       $game_party.gain_weapon(recipe['RESULT'][1], recipe['RESULT'][2])
  316.     end
  317.     return true
  318.   end
  319. end
  320.  
  321. #===============================================================================
  322. # Window RecipeList
  323. #-------------------------------------------------------------------------------
  324. # This is a standard command window which shows all the recipes known by the
  325. # party. They will appear in White if you have the proper reagents to combine
  326. # or grey otherwise.
  327. #===============================================================================
  328.  
  329. class Window_RecipeList < Window_Selectable
  330.   def initialize(type)
  331.     super(0, 0, 224, 480)
  332.     self.contents = Bitmap.new(width - 32, height - 32)
  333.     @data = []
  334.     @type = type
  335.     refresh
  336.   end
  337.   #-----------------------------------------------------------------------------
  338.   def data
  339.     return @data[self.index]
  340.   end
  341.   #-----------------------------------------------------------------------------
  342.   def refresh
  343.     self.contents.clear
  344.     @data = []
  345.     for recipe in $game_party.recipes
  346.       if @type
  347.         next unless Craft.get_recipe(recipe)['TYPE'] == @type
  348.       end
  349.       @data.push(recipe) if Craft.valid_recipe?(recipe)
  350.     end
  351.     @item_max = @data.size
  352.     self.index = [[self.index, 0].max, @item_max].min
  353.     for i in [email hidden]
  354.       data = @data[i]
  355.       next unless data
  356.       x = (Craft::SHOW_LIST_ICONS ? 32 : 4)
  357.       recipe = Craft.get_recipe(data)
  358.       if Craft::SHOW_LIST_ICONS
  359.         case recipe['RESULT'][0]
  360.         when 0 # ITEM
  361.           bitmap = RPG::Cache.icon($data_items[recipe['RESULT'][1]].icon_name)
  362.           self.contents.blt(4, i * 32 + 4, bitmap, Rect.new(0, 0, 24, 24))
  363.         when 1 # ARMOR
  364.           bitmap = RPG::Cache.icon($data_armors[recipe['RESULT'][1]].icon_name)
  365.           self.contents.blt(4, i * 32 + 4, bitmap, Rect.new(0, 0, 24, 24))
  366.         when 2 # WEAPON
  367.           bitmap = RPG::Cache.icon($data_weapons[recipe['RESULT'][1]].icon_name)
  368.           self.contents.blt(4, i * 32 + 4, bitmap, Rect.new(0, 0, 24, 24))
  369.         end
  370.       end
  371.       if Craft::USE_LEVELS
  372.         level = (recipe['LEVEL'] ? recipe['LEVEL'] : 1)
  373.         diff = $game_party.trade_skills[recipe['TYPE']] - level
  374.         if Craft::SHOW_COLORS
  375.           self.contents.font.color = Craft.color_chart(diff)
  376.         else
  377.           self.contents.font.color = (Craft.can_make?(data) ? normal_color : disabled_color)
  378.         end
  379.         if Craft::SHOW_LEVELS
  380.           self.contents.draw_text(x, i * 32, self.contents.width - x, 32,
  381.             "(#{recipe['LEVEL']}) #{data}")
  382.         else
  383.           self.contents.draw_text(x, i * 32, self.contents.width - x, 32, data.to_s)
  384.         end
  385.       else
  386.         self.contents.font.color = (Craft.can_make?(data) ? normal_color : disabled_color)
  387.         self.contents.draw_text(x, i * 32, self.contents.width - x, 32, data.to_s)
  388.       end
  389.     end
  390.   end
  391. end
  392.  
  393. #===============================================================================
  394. # Window ResultInfo
  395. #-------------------------------------------------------------------------------
  396. # This window displays all the information regarding the resulting item.
  397. #===============================================================================
  398.  
  399. class Window_ResultInfo < Window_Base
  400.   def initialize(recipe)
  401.     super(224, 0, 640-224, 272)
  402.     self.contents = Bitmap.new(width - 32, height - 32)
  403.     @recipe = recipe
  404.     refresh
  405.   end
  406.   #-----------------------------------------------------------------------------
  407.   def refresh
  408.     self.contents.clear
  409.     recipe = Craft.get_recipe(@recipe)
  410.     return unless recipe
  411.     case recipe['RESULT'][0]
  412.     when 0 # ITEM
  413.       item = $data_items[recipe['RESULT'][1]]
  414.       return unless item
  415.       if Craft::SHOW_RESULT_ICON
  416.         bitmap = RPG::Cache.icon(item.icon_name)
  417.         self.contents.blt(4, 4, bitmap, Rect.new(0, 0, 24, 24))
  418.         self.contents.draw_text(32,  0, self.contents.width - 36, 32, item.name.to_s)
  419.       else
  420.         self.contents.draw_text(4,  0, self.contents.width - 8, 32, item.name.to_s)
  421.       end
  422.       self.contents.draw_text(4,  0, self.contents.width - 8, 32, "#{item.price} #{$data_system.words.gold}", 2)
  423.       if item.recover_hp_rate != 0
  424.         self.contents.draw_text(4, 48, self.contents.width - 8, 32, "HP: #{item.recover_hp_rate}%")
  425.       elsif item.recover_hp != 0
  426.         self.contents.draw_text(4, 48, self.contents.width - 8, 32, "HP: #{item.recover_hp}")
  427.       end
  428.       if item.recover_sp_rate != 0
  429.         self.contents.draw_text(4, 48, self.contents.width - 8, 32, "SP: #{item.recover_sp_rate}%", 1)
  430.       elsif item.recover_sp != 0
  431.         self.contents.draw_text(4, 48, self.contents.width - 8, 32, "SP: #{item.recover_sp}", 1)
  432.       end
  433.       self.contents.draw_text(4, 80, self.contents.width - 8, 32, "Hit%: #{item.hit}")
  434.       self.contents.draw_text(4, 80, self.contents.width - 8, 32, "Variance: #{item.variance}", 2)
  435.       case item.parameter_type
  436.       when 1
  437.         self.contents.draw_text(4, 48, self.contents.width - 8, 32, "Max HP: +#{item.parameter_points}", 2)
  438.       when 2
  439.         self.contents.draw_text(4, 48, self.contents.width - 8, 32, "Max SP: +#{item.parameter_points}", 2)
  440.       when 3
  441.         self.contents.draw_text(4, 48, self.contents.width - 8, 32, "STR: +#{item.parameter_points}", 2)
  442.       when 4
  443.         self.contents.draw_text(4, 48, self.contents.width - 8, 32, "DEX: +#{item.parameter_points}", 2)
  444.       when 5
  445.         self.contents.draw_text(4, 48, self.contents.width - 8, 32, "AGI: +#{item.parameter_points}", 2)
  446.       when 6
  447.         self.contents.draw_text(4, 48, self.contents.width - 8, 32, "INT: +#{item.parameter_points}", 2)
  448.       end
  449.       state_text = 'State + '
  450.       for state in item.plus_state_set
  451.         state_text += ', ' unless state == item.plus_state_set.first
  452.         state_text += $data_states[state].name
  453.       end
  454.       self.contents.draw_text(4, 112, self.contents.width - 8, 32, "#{state_text}")
  455.       state_text = 'State - '
  456.       for state in item.minus_state_set
  457.         state_text += ', ' unless state == item.minus_state_set.first
  458.         state_text += $data_states[state].name
  459.       end
  460.       self.contents.draw_text(4, 144, self.contents.width - 8, 32, "#{state_text}")
  461.     when 1 # ARMOR
  462.       item = $data_armors[recipe['RESULT'][1]]
  463.       return unless item
  464.       if Craft::SHOW_RESULT_ICON
  465.         bitmap = RPG::Cache.icon(item.icon_name)
  466.         self.contents.blt(4, 4, bitmap, Rect.new(0, 0, 24, 24))
  467.         self.contents.draw_text(32,  0, self.contents.width - 36, 32, item.name.to_s)
  468.       else
  469.         self.contents.draw_text(4,  0, self.contents.width - 8, 32, item.name.to_s)
  470.       end
  471.       self.contents.draw_text(4, 0, self.contents.width - 8, 32, "#{item.price} #{$data_system.words.gold}", 2)
  472.       case item.kind
  473.       when 0 # Shield
  474.         self.contents.draw_text(4, 48, self.contents.width - 8, 32, 'Shield')
  475.       when 1 # Helmet
  476.         self.contents.draw_text(4, 48, self.contents.width - 8, 32, 'Helmet')
  477.       when 2 # Body Armor
  478.         self.contents.draw_text(4, 48, self.contents.width - 8, 32, 'Body Armor')
  479.       when 3 # Accessory
  480.         self.contents.draw_text(4, 48, self.contents.width - 8, 32, 'Accessory')
  481.       end
  482.       self.contents.draw_text(4, 48, self.contents.width - 8, 32, "EVA: #{item.eva}", 2)
  483.       self.contents.draw_text(4, 80, self.contents.width - 8, 32, "PDEF: #{item.pdef}")
  484.       self.contents.draw_text(4, 80, self.contents.width - 8, 32, "STR: #{item.str_plus}", 1)
  485.       self.contents.draw_text(4, 80, self.contents.width - 8, 32, "DEX: #{item.dex_plus}", 2)
  486.       self.contents.draw_text(4, 112, self.contents.width - 8, 32, "MDEF: #{item.mdef}")
  487.       self.contents.draw_text(4, 112, self.contents.width - 8, 32, "AGI: #{item.agi_plus}", 1)
  488.       self.contents.draw_text(4, 112, self.contents.width - 8, 32, "INT: #{item.int_plus}", 2)
  489.       state_text = 'State Guard: '
  490.       for state in item.guard_state_set
  491.         state_text += ', ' unless state == item.guard_state_set.first
  492.         state_text += $data_states[state].name
  493.       end
  494.       self.contents.draw_text(4, 144, self.contents.width - 8, 32, "#{state_text}")
  495.       state_text = 'Element Guard: '
  496.       for state in item.guard_element_set
  497.         state_text += ', ' unless state == item.guard_element_set.first
  498.         state_text += $data_system.elements[state]
  499.       end
  500.       self.contents.draw_text(4, 176, self.contents.width - 8, 32, "#{state_text}")
  501.       if item.auto_state_id != 0
  502.         self.contents.draw_text(4, 208, self.contents.width - 8, 32, "Auto State: #{$data_states[item.auto_state_id].name}")
  503.       end
  504.     when 2 # WEAPON
  505.       item = $data_weapons[recipe['RESULT'][1]]
  506.       return unless item
  507.       if Craft::SHOW_RESULT_ICON
  508.         bitmap = RPG::Cache.icon(item.icon_name)
  509.         self.contents.blt(4, 4, bitmap, Rect.new(0, 0, 24, 24))
  510.         self.contents.draw_text(32,  0, self.contents.width - 36, 32, item.name.to_s)
  511.       else
  512.         self.contents.draw_text(4,  0, self.contents.width - 8, 32, item.name.to_s)
  513.       end
  514.       self.contents.draw_text(4, 0, self.contents.width - 8, 32, "#{item.price} #{$data_system.words.gold}", 2)
  515.       self.contents.draw_text(4, 48, self.contents.width - 8, 32, "ATK: #{item.atk}")
  516.       self.contents.draw_text(4, 48, self.contents.width - 8, 32, "PDEF: #{item.pdef}", 1)
  517.       self.contents.draw_text(4, 48, self.contents.width - 8, 32, "MDEF: #{item.mdef}", 2)
  518.       self.contents.draw_text(4, 80, self.contents.width - 8, 32, "STR: #{item.str_plus}")
  519.       self.contents.draw_text(4, 80, self.contents.width - 8, 32, "DEX: #{item.dex_plus}", 2)
  520.       self.contents.draw_text(4, 112, self.contents.width - 8, 32, "AGI: #{item.agi_plus}")
  521.       self.contents.draw_text(4, 112, self.contents.width - 8, 32, "INT: #{item.int_plus}", 2)
  522.       state_text = 'State + '
  523.       for state in item.plus_state_set
  524.         state_text += ', ' unless state == item.plus_state_set.first
  525.         state_text += $data_states[state].name
  526.       end
  527.       self.contents.draw_text(4, 144, self.contents.width - 8, 32, "#{state_text}")
  528.       state_text = 'State - '
  529.       for state in item.minus_state_set
  530.         state_text += ', ' unless state == item.minus_state_set.first
  531.         state_text += $data_states[state].name
  532.       end
  533.       self.contents.draw_text(4, 176, self.contents.width - 8, 32, "#{state_text}")
  534.       state_text = 'Element: '
  535.       for state in item.element_set
  536.         state_text += ', ' unless state == item.element_set.first
  537.         state_text += $data_system.elements[state]
  538.       end
  539.       self.contents.draw_text(4, 208, self.contents.width - 8, 32, "#{state_text}")
  540.     end
  541.   end
  542.   #-----------------------------------------------------------------------------
  543.   def update(recipe)
  544.     super()
  545.     return unless recipe != @recipe
  546.     @recipe = recipe
  547.     refresh
  548.   end
  549. end
  550.  
  551. #===============================================================================
  552. # Window ResultComponents
  553. #-------------------------------------------------------------------------------
  554. # This window displays all the components required for the combination, as well
  555. # as the amount you have and the amount required of each. If an item has a *
  556. # after the name, it will not be consumed in the combination.
  557. #===============================================================================
  558.  
  559. class Window_ResultComponents < Window_Base
  560.   def initialize(recipe)
  561.     super(224, 272, 640-224, 208)
  562.     self.contents = Bitmap.new(width - 32, height - 32)
  563.     @recipe = recipe
  564.     refresh
  565.   end
  566.   #-----------------------------------------------------------------------------
  567.   def refresh
  568.     self.contents.clear
  569.     recipe = Craft.get_recipe(@recipe)
  570.     return unless recipe
  571.     i = 0
  572.     for component in recipe['COMPONENTS']
  573.       case component[0]
  574.       when 0 # ITEM
  575.         item = $data_items[component[1]]
  576.         number = $game_party.item_number(component[1])
  577.       when 1 # ARMOR
  578.         item = $data_armors[component[1]]
  579.         number = $game_party.armor_number(component[1])
  580.       when 2 # WEAPON
  581.         item = $data_weapons[component[1]]
  582.         number = $game_party.weapon_number(component[1])
  583.       end
  584.       next unless item
  585.       text = "#{item.name}"
  586.       text += ' (*)' unless component[3]
  587.       x = (Craft::SHOW_COMPONENT_ICONS ? 32 : 4)
  588.       if Craft::SHOW_COMPONENT_ICONS
  589.         bitmap = RPG::Cache.icon(item.icon_name)
  590.         self.contents.blt(4, i * 32 + 4, bitmap, Rect.new(0, 0, 24, 24))
  591.       end
  592.       self.contents.draw_text(x, i * 32, self.contents.width - x - 4, 32, "#{text}")
  593.       self.contents.draw_text(x, i * 32, self.contents.width - x - 4, 32, "#{number}/#{component[2]}", 2)
  594.       i += 1
  595.     end
  596.   end
  597.   #-----------------------------------------------------------------------------
  598.   def update(recipe)
  599.     super()
  600.     return unless recipe != @recipe
  601.     @recipe = recipe
  602.     refresh
  603.   end
  604. end
  605.  
  606. #===============================================================================
  607. # Game_Party
  608. #-------------------------------------------------------------------------------
  609. # This is a small edit of the original Game_Party class to add recognition for
  610. # recipes. It also adds the methods below:
  611. #   add_recipe() : name
  612. #     - this will teach the party the recipe, if it's valid. name is the name
  613. #       of the recipe.
  614. #   remove_recipe() : name
  615. #     - this will force the party to forget the recipe, if it's known. name is
  616. #       the name of the recipe.
  617. #   have_recipe() : name
  618. #     - this will return true or false, depending on if the party knows the
  619. #       recipe. Primary used in the can_make? method of the Craft module.
  620. # -- FOR LEVELS --
  621. #   learn_trade() : name
  622. #     - this will set the level of the 'trade skill' to 1, enabling it for use
  623. #       with recipes.
  624. #   forget_trade() : name
  625. #     - this will reset the level of the 'trade skill' to 0.
  626. #   trade_check() : name, level
  627. #     - this will return true or false, depending on if the arguement 'level' is
  628. #       less than or equal to the 'trade skill'.
  629. #   trade_level_up() : name, value = 1
  630. #     - this will add the value to the existing trade level. Used primary by
  631. #       the Craft module.
  632. #===============================================================================
  633.  
  634. class Game_Party
  635.   attr_reader :recipes
  636.   attr_reader :trade_skills
  637.   #-----------------------------------------------------------------------------
  638.   alias prexcraft_g_party_initialize initialize
  639.   #-----------------------------------------------------------------------------
  640.   def initialize
  641.     prexcraft_g_party_initialize
  642.     @recipes = []
  643.     @trade_skills = Hash.new(0)
  644.   end
  645.   #-----------------------------------------------------------------------------
  646.   def add_recipe(name)
  647.     @recipes.push(name) if Craft.valid_recipe?(name) and !have_recipe(name)
  648.   end
  649.   #-----------------------------------------------------------------------------
  650.   def remove_recipe(name)
  651.     @recipes.delete(name)
  652.   end
  653.   #-----------------------------------------------------------------------------
  654.   def have_recipe(name)
  655.     return @recipes.include?(name)
  656.   end
  657.   #-----------------------------------------------------------------------------
  658.   def learn_trade(name)
  659.     @trade_skills[name] = 1
  660.   end
  661.   #-----------------------------------------------------------------------------
  662.   def forget_trade(name)
  663.     @trade_skills[name] = 0
  664.   end
  665.   #-----------------------------------------------------------------------------
  666.   def trade_check?(name, level)
  667.     return (@trade_skills[name] >= level)
  668.   end
  669.   #-----------------------------------------------------------------------------
  670.   def trade_level_up(name, value = 1)
  671.     @trade_skills[name] += value
  672.   end
  673. end
Expand to see the code.


[indent]
OLD VERSIONS Show
[spoiler=Version 1.02]
  1. #===============================================================================
  2. # Module Craft by Prexus
  3. #  - Version 1.02 (12.24.06)
  4. #-------------------------------------------------------------------------------
  5. # This is the primary module of the PrexCraft script. Be sure to read the
  6. # instructions to learn how to create new recipes. Do not change any of the
  7. # constants in the DO NOT TOUCH section.
  8. #===============================================================================
  9.  
  10. module Craft
  11.   #=============================================================================
  12.   # CONSTANTS :: DO NOT TOUCH
  13.   #=============================================================================
  14.   ITEM = 0; ARMOR = 1; WEAPON = 2
  15.   NOT_CONSUMED = false; CONSUMED = true;
  16.  
  17.   #=============================================================================
  18.   # RECIPES :: Follow Instructions
  19.   #-----------------------------------------------------------------------------
  20.   # FORMAT :
  21.   # {'NAME' => 'RECIPE NAME AS STRING',
  22.   #  'RESULT' => [TYPE, ID, VALUE],
  23.   #  'COMPONENTS' => [
  24.   #    [TYPE, ID, VALUE, CONSUMED?],
  25.   #    [TYPE, ID, VALUE, CONSUMED?],
  26.   #    ...
  27.   #  ]
  28.   # }
  29.   #-----------------------------------------------------------------------------
  30.   # To setup a recipe, follow the example below:
  31.   #-----------------------------------------------------------------------------
  32.   # {'NAME' => 'Cold Iron Sword',
  33.   #  'RESULT' => [ARMOR, 1, 1],
  34.   #  'COMPONENTS' => [
  35.   #    [ITEM, 1, 1, CONSUMED],
  36.   #    [ITEM, 2, 1, CONSUMED],
  37.   #    [WEAPON, 3, 1, NOT_CONSUMED]
  38.   #  ]
  39.   # } # End Recipe [ARMOR, 1, 1]
  40.   #=============================================================================
  41.   RECIPES = [
  42.     {'NAME' => 'Cold Sword',
  43.      'RESULT' => [WEAPON, 33, 1],
  44.      'COMPONENTS' => [
  45.        [ITEM, 33, 1, CONSUMED],
  46.        [WEAPON, 1, 1, CONSUMED]
  47.      ]
  48.     },
  49.     {'NAME' => 'Apple Pie',
  50.      'RESULT' => [ITEM, 36, 1],
  51.      'COMPONENTS' => [
  52.        [ITEM, 34, 1, NOT_CONSUMED],
  53.        [ITEM, 35, 3, CONSUMED]
  54.      ]
  55.     }
  56.   ]
  57.  
  58.   #=============================================================================
  59.   # Craft Methods
  60.   #-----------------------------------------------------------------------------
  61.   # valid_recipe? : name
  62.   # Checks if the recipe name given exists in the recipe data store.
  63.   #=============================================================================
  64.   def self.valid_recipe?(name)
  65.     for recipe in RECIPES
  66.       return true if name == recipe['NAME']
  67.     end
  68.     return false
  69.   end
  70.  
  71.   #=============================================================================
  72.   # Craft Methods
  73.   #-----------------------------------------------------------------------------
  74.   # can_make? : name
  75.   # Checks if the recipe is possible to make. First finds if the recipe given is
  76.   # valid, then checks if there are enough components in your inventory.
  77.   #=============================================================================
  78.   def self.can_make?(name)
  79.     return false unless self.valid_recipe?(name)
  80.     for r in RECIPES
  81.       next unless name == r['NAME']
  82.       recipe = r
  83.     end
  84.     return false unless recipe
  85.     for component in recipe['COMPONENTS']
  86.       case component[0]
  87.       when 0 # ITEM
  88.         return false unless $game_party.item_number(component[1]) >= component[2]
  89.       when 1 # ARMOR
  90.         return false unless $game_party.armor_number(component[1]) >= component[2]
  91.       when 2 # WEAPON
  92.         return false unless $game_party.weapon_number(component[1]) >= component[2]
  93.       end
  94.     end
  95.     return true
  96.   end
  97.  
  98.   #=============================================================================
  99.   # Craft Methods
  100.   #-----------------------------------------------------------------------------
  101.   # get_recipe : name
  102.   # Returns the hash object containing the data information for the recipe if
  103.   # the recipe is valid. Else returns nil.
  104.   #=============================================================================
  105.   def self.get_recipe(name)
  106.     return nil unless self.valid_recipe?(name)
  107.     for recipe in RECIPES
  108.       return recipe if recipe['NAME'] == name
  109.     end
  110.     return nil
  111.   end
  112. end
  113.  
  114. #===============================================================================
  115. # Scene Craft
  116. #-------------------------------------------------------------------------------
  117. # This is the main interface for the crafting system. You can run it by using
  118. # the callscript command '$scene = Scene_Craft.new' or by adding it to your own
  119. # code in the same manner.
  120. #===============================================================================
  121.  
  122. class Scene_Craft
  123.   def main
  124.     @recipe_list = Window_RecipeList.new
  125.     @result_info = Window_ResultInfo.new(@recipe_list.data)
  126.     @result_comp = Window_ResultComponents.new(@recipe_list.data)
  127.     Graphics.transition
  128.     loop do
  129.       Graphics.update
  130.       Input.update
  131.       update
  132.       break if $scene != self
  133.     end
  134.     Graphics.freeze
  135.     @recipe_list.dispose
  136.     @result_info.dispose
  137.     @result_comp.dispose
  138.   end
  139.   #-----------------------------------------------------------------------------
  140.   def update
  141.     @recipe_list.update
  142.     @result_info.update(@recipe_list.data)
  143.     @result_comp.update(@recipe_list.data)
  144.     if Input.trigger?(Input::B)
  145.       $game_system.se_play($data_system.cancel_se)
  146.       $scene = Scene_Map.new
  147.       return
  148.     end
  149.     if Input.trigger?(Input::C)
  150.       if craft(@recipe_list.data)
  151.         $game_system.se_play($data_system.decision_se)
  152.       else
  153.         $game_system.se_play($data_system.buzzer_se)
  154.       end
  155.       @recipe_list.refresh
  156.       @result_info.refresh
  157.       @result_comp.refresh
  158.       return
  159.     end
  160.   end
  161.   #-----------------------------------------------------------------------------
  162.   def craft(recipe)
  163.     return false unless Craft.can_make?(recipe)
  164.     recipe = Craft.get_recipe(@recipe_list.data)
  165.     for component in recipe['COMPONENTS']
  166.       case component[0]
  167.       when 0 # Item
  168.         $game_party.lose_item(component[1], component[2]) if component[3]
  169.       when 1 # Armor
  170.         $game_party.lose_armor(component[1], component[2]) if component[3]
  171.       when 2 # Weapon
  172.         $game_party.lose_weapon(component[1], component[2]) if component[3]
  173.       end
  174.     end
  175.     case recipe['RESULT'][0]
  176.     when 0 # Item
  177.       $game_party.gain_item(recipe['RESULT'][1], recipe['RESULT'][2])
  178.     when 1 # Armor
  179.       $game_party.gain_armor(recipe['RESULT'][1], recipe['RESULT'][2])
  180.     when 2 # Weapon
  181.       $game_party.gain_weapon(recipe['RESULT'][1], recipe['RESULT'][2])
  182.     end
  183.     return true
  184.   end
  185. end
  186.  
  187. #===============================================================================
  188. # Window RecipeList
  189. #-------------------------------------------------------------------------------
  190. # This is a standard command window which shows all the recipes known by the
  191. # party. They will appear in White if you have the proper reagents to combine
  192. # or grey otherwise.
  193. #===============================================================================
  194.  
  195. class Window_RecipeList < Window_Selectable
  196.   def initialize
  197.     super(0, 0, 224, 480)
  198.     self.contents = Bitmap.new(width - 32, height - 32)
  199.     @data = []
  200.     refresh
  201.   end
  202.   #-----------------------------------------------------------------------------
  203.   def data
  204.     return @data[self.index]
  205.   end
  206.   #-----------------------------------------------------------------------------
  207.   def refresh
  208.     self.contents.clear
  209.     @data = []
  210.     for recipe in $game_party.recipes
  211.       @data.push(recipe) if Craft.valid_recipe?(recipe)
  212.     end
  213.     @item_max = @data.size
  214.     self.index = 0
  215.     for i in [email hidden]
  216.       data = @data[i]
  217.       next unless data
  218.       self.contents.font.color = (Craft.can_make?(data) ? normal_color : disabled_color)
  219.       self.contents.draw_text(4, i * 32, self.contents.width - 8, 32, data.to_s)
  220.     end
  221.   end
  222. end
  223.  
  224. #===============================================================================
  225. # Window ResultInfo
  226. #-------------------------------------------------------------------------------
  227. # This window displays all the information regarding the resulting item.
  228. #===============================================================================
  229.  
  230. class Window_ResultInfo < Window_Base
  231.   def initialize(recipe)
  232.     super(224, 0, 640-224, 272)
  233.     self.contents = Bitmap.new(width - 32, height - 32)
  234.     @recipe = recipe
  235.     refresh
  236.   end
  237.   #-----------------------------------------------------------------------------
  238.   def refresh
  239.     self.contents.clear
  240.     recipe = Craft.get_recipe(@recipe)
  241.     return unless recipe
  242.     case recipe['RESULT'][0]
  243.     when 0 # ITEM
  244.       item = $data_items[recipe['RESULT'][1]]
  245.       return unless item
  246.       self.contents.draw_text(4,  0, self.contents.width - 8, 32, item.name.to_s)
  247.       self.contents.draw_text(4,  0, self.contents.width - 8, 32, "#{item.price} #{$data_system.words.gold}", 2)
  248.       if item.recover_hp_rate != 0
  249.         self.contents.draw_text(4, 48, self.contents.width - 8, 32, "HP: #{item.recover_hp_rate}%")
  250.       elsif item.recover_hp != 0
  251.         self.contents.draw_text(4, 48, self.contents.width - 8, 32, "HP: #{item.recover_hp}")
  252.       end
  253.       if item.recover_sp_rate != 0
  254.         self.contents.draw_text(4, 48, self.contents.width - 8, 32, "SP: #{item.recover_sp_rate}%", 1)
  255.       elsif item.recover_sp != 0
  256.         self.contents.draw_text(4, 48, self.contents.width - 8, 32, "SP: #{item.recover_sp}", 1)
  257.       end
  258.       self.contents.draw_text(4, 80, self.contents.width - 8, 32, "Hit%: #{item.hit}")
  259.       self.contents.draw_text(4, 80, self.contents.width - 8, 32, "Variance: #{item.variance}", 2)
  260.       case item.parameter_type
  261.       when 1
  262.         self.contents.draw_text(4, 48, self.contents.width - 8, 32, "Max HP: +#{item.parameter_points}", 2)
  263.       when 2
  264.         self.contents.draw_text(4, 48, self.contents.width - 8, 32, "Max SP: +#{item.parameter_points}", 2)
  265.       when 3
  266.         self.contents.draw_text(4, 48, self.contents.width - 8, 32, "STR: +#{item.parameter_points}", 2)
  267.       when 4
  268.         self.contents.draw_text(4, 48, self.contents.width - 8, 32, "DEX: +#{item.parameter_points}", 2)
  269.       when 5
  270.         self.contents.draw_text(4, 48, self.contents.width - 8, 32, "AGI: +#{item.parameter_points}", 2)
  271.       when 6
  272.         self.contents.draw_text(4, 48, self.contents.width - 8, 32, "INT: +#{item.parameter_points}", 2)
  273.       end
  274.       state_text = 'State + '
  275.       for state in item.plus_state_set
  276.         state_text += ', ' unless state == item.plus_state_set.first
  277.         state_text += $data_states[state].name
  278.       end
  279.       self.contents.draw_text(4, 112, self.contents.width - 8, 32, "#{state_text}")
  280.       state_text = 'State - '
  281.       for state in item.minus_state_set
  282.         state_text += ', ' unless state == item.minus_state_set.first
  283.         state_text += $data_states[state].name
  284.       end
  285.       self.contents.draw_text(4, 144, self.contents.width - 8, 32, "#{state_text}")
  286.     when 1 # ARMOR
  287.       item = $data_armors[recipe['RESULT'][1]]
  288.       return unless item
  289.       self.contents.draw_text(4, 0, self.contents.width - 8, 32, item.name.to_s)
  290.       self.contents.draw_text(4, 0, self.contents.width - 8, 32, "#{item.price} #{$data_system.words.gold}", 2)
  291.       case item.kind
  292.       when 0 # Shield
  293.         self.contents.draw_text(4, 48, self.contents.width - 8, 32, 'Shield')
  294.       when 1 # Helmet
  295.         self.contents.draw_text(4, 48, self.contents.width - 8, 32, 'Helmet')
  296.       when 2 # Body Armor
  297.         self.contents.draw_text(4, 48, self.contents.width - 8, 32, 'Body Armor')
  298.       when 3 # Accessory
  299.         self.contents.draw_text(4, 48, self.contents.width - 8, 32, 'Accessory')
  300.       end
  301.       self.contents.draw_text(4, 48, self.contents.width - 8, 32, "EVA: #{item.eva}", 2)
  302.       self.contents.draw_text(4, 80, self.contents.width - 8, 32, "PDEF: #{item.pdef}")
  303.       self.contents.draw_text(4, 80, self.contents.width - 8, 32, "STR: #{item.str_plus}", 1)
  304.       self.contents.draw_text(4, 80, self.contents.width - 8, 32, "DEX: #{item.dex_plus}", 2)
  305.       self.contents.draw_text(4, 112, self.contents.width - 8, 32, "MDEF: #{item.mdef}")
  306.       self.contents.draw_text(4, 112, self.contents.width - 8, 32, "AGI: #{item.agi_plus}", 1)
  307.       self.contents.draw_text(4, 112, self.contents.width - 8, 32, "INT: #{item.int_plus}", 2)
  308.       state_text = 'State Guard: '
  309.       for state in item.guard_state_set
  310.         state_text += ', ' unless state == item.guard_state_set.first
  311.         state_text += $data_states[state].name
  312.       end
  313.       self.contents.draw_text(4, 144, self.contents.width - 8, 32, "#{state_text}")
  314.       state_text = 'Element Guard: '
  315.       for state in item.guard_element_set
  316.         state_text += ', ' unless state == item.guard_element_set.first
  317.         state_text += $data_system.elements[state]
  318.       end
  319.       self.contents.draw_text(4, 176, self.contents.width - 8, 32, "#{state_text}")
  320.       if item.auto_state_id != 0
  321.         self.contents.draw_text(4, 208, self.contents.width - 8, 32, "Auto State: #{$data_states[item.auto_state_id].name}")
  322.       end
  323.     when 2 # WEAPON
  324.       item = $data_weapons[recipe['RESULT'][1]]
  325.       return unless item
  326.       self.contents.draw_text(4, 0, self.contents.width - 8, 32, item.name.to_s)
  327.       self.contents.draw_text(4, 0, self.contents.width - 8, 32, "#{item.price} #{$data_system.words.gold}", 2)
  328.       self.contents.draw_text(4, 48, self.contents.width - 8, 32, "ATK: #{item.atk}")
  329.       self.contents.draw_text(4, 48, self.contents.width - 8, 32, "PDEF: #{item.pdef}", 1)
  330.       self.contents.draw_text(4, 48, self.contents.width - 8, 32, "MDEF: #{item.mdef}", 2)
  331.       self.contents.draw_text(4, 80, self.contents.width - 8, 32, "STR: #{item.str_plus}")
  332.       self.contents.draw_text(4, 80, self.contents.width - 8, 32, "DEX: #{item.dex_plus}", 2)
  333.       self.contents.draw_text(4, 112, self.contents.width - 8, 32, "AGI: #{item.agi_plus}")
  334.       self.contents.draw_text(4, 112, self.contents.width - 8, 32, "INT: #{item.int_plus}", 2)
  335.       state_text = 'State + '
  336.       for state in item.plus_state_set
  337.         state_text += ', ' unless state == item.plus_state_set.first
  338.         state_text += $data_states[state].name
  339.       end
  340.       self.contents.draw_text(4, 144, self.contents.width - 8, 32, "#{state_text}")
  341.       state_text = 'State - '
  342.       for state in item.minus_state_set
  343.         state_text += ', ' unless state == item.minus_state_set.first
  344.         state_text += $data_states[state].name
  345.       end
  346.       self.contents.draw_text(4, 176, self.contents.width - 8, 32, "#{state_text}")
  347.       state_text = 'Element: '
  348.       for state in item.element_set
  349.         state_text += ', ' unless state == item.element_set.first
  350.         state_text += $data_system.elements[state]
  351.       end
  352.       self.contents.draw_text(4, 208, self.contents.width - 8, 32, "#{state_text}")
  353.     end
  354.   end
  355.   #-----------------------------------------------------------------------------
  356.   def update(recipe)
  357.     super()
  358.     return unless recipe != @recipe
  359.     @recipe = recipe
  360.     refresh
  361.   end
  362. end
  363.  
  364. #===============================================================================
  365. # Window ResultComponents
  366. #-------------------------------------------------------------------------------
  367. # This window displays all the components required for the combination, as well
  368. # as the amount you have and the amount required of each. If an item has a *
  369. # after the name, it will not be consumed in the combination.
  370. #===============================================================================
  371.  
  372. class Window_ResultComponents < Window_Base
  373.   def initialize(recipe)
  374.     super(224, 272, 640-224, 208)
  375.     self.contents = Bitmap.new(width - 32, height - 32)
  376.     @recipe = recipe
  377.     refresh
  378.   end
  379.   #-----------------------------------------------------------------------------
  380.   def refresh
  381.     self.contents.clear
  382.     recipe = Craft.get_recipe(@recipe)
  383.     return unless recipe
  384.     i = 0
  385.     for component in recipe['COMPONENTS']
  386.       case component[0]
  387.       when 0 # ITEM
  388.         item = $data_items[component[1]]
  389.         number = $game_party.item_number(component[1])
  390.       when 1 # ARMOR
  391.         item = $data_armors[component[1]]
  392.         number = $game_party.armor_number(component[1])
  393.       when 2 # WEAPON
  394.         item = $data_weapons[component[1]]
  395.         number = $game_party.weapon_number(component[1])
  396.       end
  397.       next unless item
  398.       text = "#{item.name}"
  399.       text += ' (*)' unless component[3]
  400.       self.contents.draw_text(4, i * 32, self.contents.width - 8, 32, "#{text}")
  401.       self.contents.draw_text(4, i * 32, self.contents.width - 8, 32, "#{number}/#{component[2]}", 2)
  402.       i += 1
  403.     end
  404.   end
  405.   #-----------------------------------------------------------------------------
  406.   def update(recipe)
  407.     super()
  408.     return unless recipe != @recipe
  409.     @recipe = recipe
  410.     refresh
  411.   end
  412. end
  413.  
  414. #===============================================================================
  415. # Game_Party
  416. #-------------------------------------------------------------------------------
  417. # This is a small edit of the original Game_Party class to add recognition for
  418. # recipes. It also adds the methods below:
  419. #   add_recipe() : name
  420. #     - this will teach the party the recipe, if it's valid. name is the name
  421. #       of the recipe.
  422. #   remove_recipe() : name
  423. #     - this will force the party to forget the recipe, if it's known. name is
  424. #       the name of the recipe.
  425. #   have_recipe() : name
  426. #     - this will return true or false, depending on if the party knows the
  427. #       recipe. Primary used in the can_make? method of the Craft module.
  428. #===============================================================================
  429.  
  430. class Game_Party
  431.   attr_reader :recipes
  432.   #-----------------------------------------------------------------------------
  433.   alias prexcraft_g_party_initialize initialize
  434.   #-----------------------------------------------------------------------------
  435.   def initialize
  436.     prexcraft_g_party_initialize
  437.     @recipes = []
  438.   end
  439.   #-----------------------------------------------------------------------------
  440.   def add_recipe(name)
  441.     @recipes.push(name) if Craft.valid_recipe?(name)
  442.   end
  443.   #-----------------------------------------------------------------------------
  444.   def remove_recipe(name)
  445.     @recipes.delete(name)
  446.   end
  447.   #-----------------------------------------------------------------------------
  448.   def have_recipe(name)
  449.     return @recipes.include?(name)
  450.   end
  451. end
Expand to see the code.
[/spoiler][/indent]

Instructions for Version 2.0

When calling the Craft scene, be sure to include a parameter after the call to designate what type of trade skill you want to list.. such as:
$scene = Scene_Craft.new('Blacksmith')
Be sure that the type of skill corresponds with the skill type of the recipes.

There are instructions within the script but for quick reference:
Setting Up Recipes Show
  1.  
  2.  {'NAME' => 'RECIPE NAME AS STRING',
  3.   'TYPE' => 'RECIPE TYPE AS STRING',
  4.   'LEVEL' => RECIPE_LEVEL_AS_INTEGER,
  5.   'RESULT' => [ITEM_TYPE, ID, VALUE],
  6.   'COMPONENTS' => [
  7.     [ITEM_TYPE, ID, VALUE, CONSUMED?],
  8.     [ITEM_TYPE, ID, VALUE, CONSUMED?],
  9.     ...
  10.   ]
  11.  }
Expand to see the code.

ITEM_TYPE = ITEM, WEAPON, or ARMOR
ID = ID within the Database
VALUE = Amount used in combination, or as a result of combination.
CONSUMED? = CONSUMED or NOT_CONSUMED


Learning and Forgetting Recipes Show
To Learn: $game_party.add_recipe('RECIPE NAME')
To Forget: $game_party.remove_recipe('RECIPE NAME')


Learning and Forgetting Trade Skills Show
To Learn: $game_party.learn_trade('TRADE NAME')
To Forget: $game_party.forget_trade('TRADE NAME')
Pretty awesome Prexus. Nice and easy:thumb:

I tested the demo and noticed if you learn a recipe you already know, it will be on there twice. And you can do this over and over to have the same recipe 50 times. Any way to fix this?
Nice Script PrexusBut just to give some idea: would be great to need some xp or skill points to craft a new thingy, like:
apple pie: xp needed: 0; xp adding: 1/(actor.bakery_xp+1)
cherry pie: xp needed: 10; xp adding: 5/(actor.bakery_xp+1)
strawberry pie: ...
the higher the xp the less the xp earn, like a limited growth formula
but then it wouldn't be that simple...
[QUOTE=Caldaron;121390]Nice Script PrexusBut just to give some idea: would be great to need some xp or skill points to craft a new thingy, like:
apple pie: xp needed: 0; xp adding: 1/(actor.bakery_xp+1)
cherry pie: xp needed: 10; xp adding: 5/(actor.bakery_xp+1)
strawberry pie: ...
the higher the xp the less the xp earn, like a limited growth formula
but then it wouldn't be that simple...[/QUOTE]

To add to your idea there, how about with XP and levels you get better at making the item? so instead of making say a apple pie you burn it because you're to low of level in baking?
Wow! I gotta give this a shot. Deke's script looked awesome but it was contributing to Pale being on pause. ':|
[QUOTE=Italianstal1ion;121363]Pretty awesome Prexus. Nice and easy:thumb:

I tested the demo and noticed if you learn a recipe you already know, it will be on there twice. And you can do this over and over to have the same recipe 50 times. Any way to fix this?[/QUOTE]

I'll fix this. It was a bit of an oversight. One or two lines of code will fix it.

Fixed.

Regarding the 'Crafting XP', please submit this as a Script Request. It is not the intention of this system.
Looks like a nice and user-friendly script, but I'm still wondering what the 'Consumed' option does. Maybe you can enlighten me?
This is, say, for example, you needed a Smith's Hammer to forge a weapon. If it is set to NOT_CONSUMED, the item is still needed for the combination, but it will still be in your inventory afterwards.
Well, I missed this while I was away but great script Prex. It's good to see you still coming up with masterpieces.
Do you think you could adapt this so you don't need recipes? You just mix items together and see what comes out?
Added Version 2.0

See the 'Features' section for the updated features (It's a doozey!)

Special Thanks to ScriptKitty for inspiring me to update the script.
Why do you make a Scene that contain the trade skill, with an icon an exp bar?
Why should I?
When ever I use this script (along with Deke's) when the menu to craft opens up all the font isn't there. I can see the icons and everything and I can still craft (game doesn't lock up or give error message) but I just simply cannot see the text. I looked over the script and I have SDK but I haven't been able to find anything plus I am not that avid of a scripter...Any help would be nice. Thanks
First of all, you can't use both.

Secondly, you need to buy the legal RMXP for $60 from http://www.download.com; The cause of not being able to see text is that the Illegal RMXP uses a japanese language font by default. Sorry to say, but you'll be needing to buy the legal RMXP before I or anyone else here helps you.
No I have the LEGAL version I paid my $60.00 I can see all the other text (i.e. scripts are in english, text = english, events = english, everything = english) But I didn't get it from Download.com though. I got it when it first came out. And I'm not using both I'm just saying that both of the Crafting Scripts(only in the crafting menu) I cannot see the text. Everything thing else in my RMXP works, just not the crafting menu.
Download.com was the launch website for RMXP English.

Try this: Go to the 'Main' script, and add the lines
Font.default_name = 'Verdana'
Font.default_size = '24'

before the $scene = Scene_Title.new line.
Hmm..ok now it works. I think I know what happened. This project file I'm using, I had before the Eng. version came out. (I was using a demo japanese one that a friend sent me) Then I bought the English version of RMXP, you think might be the source of the problem? Because now it seems to be working... sorry about all the earlier confusion...

Edit: I'm using the same file on the Eng. ver. as I was with the Jap. ver.
i get a no method error on line 659 when i try to teach my party trade skills. help! this looks so cool!
Check your spelling.
i copied and pasted the script and event from your demo just because it wasnt working for me and still same error.
You have Version 2.0, right?
it reads:
undefined method '[]=' for nil:NilClass

ya
Don't double post.

If the Call Script is cut off, it acts a little weird. Try this:

g = $game_party
t = 'TradeskillNameGoesHere'
g.learn_trade(t)
Expand to see the code.
I resolved my problems with the script i ended up just copying and pasting all my custom scripts and data to a new project and i got it to work. Thanks for your help Prexus and AMAZING SCRIPT!
You are a scripting god Prexus. :o Brilliant script thanks a ton for posting it. Definately going to use it.
This is an AWESOME script. I just need to know one thing..
I'm using it in my game Time to Split, it's for a board I go to. Anyhow, I'm making a tutorial at the beginning of the game that teaches you how to cook, crack safes, and pick the lock on doors. Anyhow, I can call the script fine, but I can't make anything. I have a recipe and the ingredients, but nothing happens.
@ Prexus : your Craft Script is great but it isn't perfect .... when craft an item , you should set a " Are you sure " window . How to do it ? I need it so much , please help me

.
This is cool. But I'd like to request some features for it...
1: Like Keke suggests, a confirmation window would be nice.
2: The ability to change the SE played when you make a recipe- I'd like to hear a 'clink-clink-clink' noise for smithing, and a bubbling/boiling noise for potion making and so forth. Just adds significantly to the immersion.
3: Perhaps a way to show how stats have changed from the base item rather than just showing the new items stats. This would be very useful in the case of weapons & armours; I may not remember what the base objects stats are, and when If I changing 'pointy sword' into 'vicious sword' I'd like to know what the difference is without having to check my inventory, write it down and come back again to ensure I'm not wasting my stuff...
Is it possible to make it where I can have Fletching, Smithing, and Alchmeyi n this? Im kinda comfused with this...

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