PrexCraft - Crafting Script

Can the menu be changed so that Images are set as the background rather than the windowskins?
Oh yeah I terribly sorry about my last post, I was in such a hurry cus I had to get off and somehow forgot the details....my bad...

anyways this is what happen:

I set up an event to learn all the recipes and get all of the items (as a test run) then when the event is activated, an error message pops up saying this:

NoMethodError occurred while running script.
undefined method 'add_recipe' for #
bump
Can you please convert this script to VX. The first problem I have encountered when I use this script on VX is the RPG Cache. I think RGSS2 uses different method?
I actually already did make this for RMVX but I made it to be used in a mouse engine, so I will need to update it to be non-mouse.
Error on Line 665: No Method Error
undefined method 'include?' for nil:NilClass
so i can use this in rmvx yes?...
no you can't
Nice script... Is it compatible with KGC Scripts and SDK? Just wondering...
does anyone know where i can get a crafting script for rmvx
I remember this script..:D, might just be me..but it feels you can do a lot more with it on VX just because you can utilize the "comment" thing in the database as part of scripting..maybe for more ease of use? (Though it's already fairly easy to setup and use XP wise.)

As for rick..since it seems s/he was banned, no clue if they can even read this but:

I don't think there's a VX Crafting script just yet..unless Prexus does plan on making the XP version compatible.
Good idea, actually, Razaroic.

I think I will recode this for VX.

But in response to what you said to rick, I did tell him that I have already recoded it for RMVX, but it uses a mouse-controlled engine that is unique to a project I was coding for so I can't release that version of the script or the mouse engine.
I'd definitely want an RMVX version of this! I've tried several Crafting scripts, but none of them is as easy to use as this one... Keep it up!
Prexus wrote:
I think I will recode this for VX.


That would be gold. You ´re on it?
Eventually.
Hey Prexus, AWESOME script, however i have an issue and I am not sure if its a bug or not.

The recipe to craft an item that either was already crafted, or is in a recipe to be crafted won't show up in the crafting screen.

Heres an example.

I have an armor called Arcen Bracer that can be crafted into a Flame Bracer.
Then I want to beable to craft the Flame Bracer into a Composite Bracer.
Then the Composite Bracer into a Flame Gauntlet.

So
Arcen Bracer > Flame Bracer > Composite Bracer > Flame Gauntlet.

The recipe to create the flame bracer shows up in the menu, but recipe for the Composite Bracer, and the Flame Gauntlet will not show in the system.

All of the recipes are there, and correct, and I added all three of the recipes. ('Flame Bracer'), ('Composite Bracer'), and ('Flame Gauntlet')

But only the Flame Bracer recipe will show. Am I doing something wrong, or does this script not allow items already crafted or on another recipe to be crafted?

I am currently looking for ways around this.
Ok I have to revise this.

I found out that the Length of the items name effects if it shows or not. If the name of the item is too long, then it won't show in the recipe list when you bring up the craft menu.

SO..... how can I fix this, I sort of don't want to rename the items.......
What is likely happening is in your event to add the recipe, the name of the recipe i.e. ('Flame Bracer') is being split onto two lines. If you replace 'Flame Bracer' with x and add the line x = 'Flame Bracer' before hand, it should fix your problem.
Yeah I just figured that part out, I was fiddling with it, and i realised that it was cause of the two line thing. But I hadn't figured out what to do about it yet.

So you mean to place the X = Flame Bracer in the call script before the recipe?

Or somewhere else....
yeah

Prexus wrote:
g = $game_party
t = 'TradeskillNameGoesHere'
g.learn_trade(t)
Expand to see the code.


from earlier in the thread, same idea.
Alright COOL BEANS.

You know I don't even know why I asked... I tried it while waiting for your confirmation and it worked so. Thanks alot, This script is really something.

I don't know much about scripting... yet... but I am learning small things and sort of figuring out how it works by messing with and changing other scripts....

So thanks alot for this. I am glad that it worked well with the other scripts I have.

((Using SephirothSpawn's Equipment Skills v2, Limit break, rtab, and like 20 other scripts.... lol))

So thanks alot... hehe....
Nice script Prex, but could you explain a few of the systems to me?

+Is there a failure rate?
+If so, is there a way to disable it?
+What is the difference of having higher levels in certain trades? what does it change?
+Are the Trade Levels stored under a common variable?

thanks for your time
To save you all hassle, I'm currently making this for VX. Really it's not that hard, anyone could do it. Just involves rewording everything.

I was literally just about to PM Prexus asking whether I could post it when I was finished, I didn't realise so many people wanted it.

So I may aswell ask here.
When I'm done can I post it, Prexus?





I'm also redoing all of Retaime's Visual Scripts, but don't know whether I'll be allowed to post them...
Not if you are copying my code and posting it. I'd much rather do it myself. In addition to the code in this one being suboptimal, RMVX can do some nifty things that I want to make use of when I made the RMVX version of this.
Alright, well I was making sure to ask you first. I finished it and I was going to customise a few things, but wasn't sure if I should. But seeing as I can't post it, I may aswell ^_^
necropost i know...

but i was looking for the demo of this amazing looking script and wondered if any of you had working links i PMed Prexus but thought it would not hurt to ask you all too just in case.
I'll upload a demo for you, ill PM u the link as soon as it's uploaded.
heres the script, its fairly easy to understand, so you shouldnt really need a demo

  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.

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