Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Item Crafting System

arev

Sponsor

Item Crafting System Version: 1.01
By: arev

Introduction
Simple and effective crafting system.

Features
  • Mix up to six components.
  • Use items, weapons and armors.
  • Automatic sorting of the components.

Screenshots

http://img148.imageshack.us/img148/5505/screnh.png

Demo (version 1.00)
http://www.megaupload.com/?d=CFL41HEH

Script
Code:
#==============================================================================

# ** Item Crafting System

#    version 1.01

#    created by arev (rmxp.pl)

#    released 28-12-2009, updated: 25-07-2010

#==============================================================================

# Installation & Compatibility:

#

# Copy this tab and paste it above 'Main' in your project.

# The system is compatible with default RMXP system. 

# It doesn't override any methods, so it's probably compatible

# with lots of other things.

#

#

#

# Usage:

#

# Below this introduction you'll find an array called RECIPES.

# New recipes are added with new arrays like the following:

# ['i12', 'i78', 'w3', 'a45', 'a45', 'z', 'i-99']

# i stands for items, w for weapons and a for armors.

# Acording to this recipe - to make an item of ID 99 you need

# one item with ID 12, one item with ID 78, one weapon with ID 3,

# two armors with ID 45. There is a maximum number of six components.

# If you want to make a recipe consisting of smaller number of

# components just fill the remaining fields with 'z'.

# The last ithem in the array is the recipe result. The first character

# works just like before, then there's a dash required, followed by ID

# of an item.

# 

# To enter the crafting scene call a script like this:

# $scene = Scene_Craft.new

#

# During the crafting the order of items in the component window

# is not important - they are sorted within the script.

#

#

#

# License:

#

# You are free to use this script in your non-commercial project.

# You can redistribute this script (free of charge) only if you provide 

# information about its original author.

# If you want to use this script in a commercial project please contact me

# via [url=http://www.rmxp.pl]http://www.rmxp.pl[/url] or [url=http://www.arpgmaker.com]http://www.arpgmaker.com[/url] private message system.

#==============================================================================

 

RECIPES = [

          ["i5", "i39", "i41", "z", "z", "z", "w-1"],

          ["w5", "w23", "w14", "i5", "a5", "z", "w-15"],

          ["a5", "a5", "z", "z", "z", "z", "a-8"]

          ] 

#------------------------------------------------------------------------------

class Window_Craft_Components < Window_Selectable

  

  attr_accessor :data

  

  def initialize

    super(0, 64, 320, 224)

    self.contents = Bitmap.new(width - 32, height - 32)

    self.index = 0

    self.active = true

    @data = [nil, nil, nil, nil, nil, nil]

    @item_max = 6

    refresh

  end

  

  def item

    return @data[self.index]

  end

  

  def refresh

    self.contents.clear 

    for i in 0..5

      x = 0

      y = i * 32

      if @data[i] != nil

        item = @data[i]

        bitmap = RPG::Cache.icon(item.icon_name)

        self.contents.blt(4 + x, y + 4, bitmap, Rect.new(0, 0, 24, 24))

        self.contents.font.color = normal_color

        self.contents.draw_text(x + 32, y, 160, 32, item.name, 0)

      else

        self.contents.font.color = disabled_color

        self.contents.draw_text(4 + x, y, 160, 32, "EMPTY", 0)

      end

    end

  end

  

  def update_cursor_rect

    self.cursor_rect.set(0, self.index * 32, 288, 32)

  end

  

  def nullify

    @data = [nil, nil, nil, nil, nil, nil]

  end

  

  def transmutation

    temp = []

    for i in 0..5

      if @data[i] == nil

        temp << "0"

      else

        case @data[i]

        when RPG::Item

          temp << "i" + @data[i].id

        when RPG::Weapon

          temp << "w" + @data[i].id

        when RPG::Armor

          temp << "a" + @data[i].id

        end

      end

    end

    temp = temp.sort

    return temp

  end

  

end

#------------------------------------------------------------------------------

class Window_Craft_Result < Window_Base

  

  attr_accessor :item

  

  def initialize

    super(320,64,320,224)

    self.contents = Bitmap.new(width - 32, height - 32)

    @item = nil

    @item_code = ""

    refresh

  end

  

  def refresh

    self.contents.clear

    if @item == nil

      self.contents.font.color = normal_color

      self.contents.draw_text(4,0,288,32, "Select ingredients.", 0)

    else

      bitmap = RPG::Cache.icon(@item.icon_name)

      self.contents.font.color = text_color(3)

      self.contents.draw_text(4,0,288,32, "Spectacular success!", 0)

      self.contents.blt(4, 65, bitmap, Rect.new(0, 0, 24, 24))

      self.contents.font.color = normal_color

      self.contents.draw_text(32, 65, 288, 32, @item.name, 0)

      self.contents.font.color = disabled_color

      self.contents.draw_text(4,128,288,32, "Press the 'Z' button to finalize", 0)

      self.contents.draw_text(4,160,288,32, "the crafting process!", 0)

    end

  end

  

  def make_item(text="")

    @item_code = text

    if @item_code.include?("-")

      temp = @item_code.split("-")

      if text.include?("a")

        @item = $data_armors[temp[1].to_i]

      elsif text.include?("i")

        @item = $data_items[temp[1].to_i]

      elsif text.include?("w")

        @item = $data_weapons[temp[1].to_i]

      end

      refresh

    end

  end

  

  def nullify

    @item = nil

    refresh

  end

  

end

#------------------------------------------------------------------------------

class Window_Craft_Item < Window_Selectable

 

  def initialize

    super(0, 288, 640, 192)

    @column_max = 2

    refresh

    self.active = false

    self.index = -1

  end

 

  def item

    return @data[self.index]

  end

 

  def refresh

    if self.contents != nil

      self.contents.dispose

      self.contents = nil

    end

    @data = []

    for i in 1...$data_items.size

      if $game_party.item_number(i) > 0

        @data.push($data_items[i])

      end

    end

    unless $game_temp.in_battle

      for i in 1...$data_weapons.size

        if $game_party.weapon_number(i) > 0

          @data.push($data_weapons[i])

        end

      end

      for i in 1...$data_armors.size

        if $game_party.armor_number(i) > 0

          @data.push($data_armors[i])

        end

      end

    end

    @data.push(nil)

    @item_max = @data.size

    self.contents = Bitmap.new(width - 32, row_max * 32)

    for i in 0...@item_max-1

      draw_item(i)

    end

  end

 

  def draw_item(index)

    item = @data[index]

    x = 4 + index % @column_max * 320

    y = index / @column_max * 32

    case item

    when RPG::Item

      number = $game_party.item_number(item.id)

    when RPG::Weapon

      number = $game_party.weapon_number(item.id)

    when RPG::Armor

      number = $game_party.armor_number(item.id)

    end

    bitmap = RPG::Cache.icon(item.icon_name)

    self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24))

    self.contents.font.color = normal_color

    self.contents.draw_text(x + 28, y, 212, 32, item.name, 0)

    self.contents.draw_text(x + 240, y, 16, 32, ":", 1)

    self.contents.draw_text(x + 256, y, 24, 32, number.to_s, 2)

  end

 

  def update_help

    @help_window.set_text(self.item == nil ? "" : self.item.description)

  end

 

  def update_cursor_rect

    if @index < 0

      self.cursor_rect.empty

      return

    end

    row = @index / @column_max

    if row < self.top_row

      self.top_row = row

    end

    if row > self.top_row + (self.page_row_max - 1)

      self.top_row = row - (self.page_row_max - 1)

    end

    x = index % @column_max * 320

    y = index / @column_max * 32 - self.oy

    self.cursor_rect.set(x, y, 288, 32)

  end

  

end

#------------------------------------------------------------------------------

class Scene_Craft

  

  def main

    @components = Window_Craft_Components.new

    @result = Window_Craft_Result.new

    @item_window = Window_Craft_Item.new

    @help_window = Window_Help.new

    @help_window.set_text("Item Crafting System", 1)

    Graphics.transition

    loop do

      Input.update

      Graphics.update

      update

      if $scene != self

        break

      end

    end

    Graphics.freeze

    @components.dispose

    @result.dispose

    @item_window.dispose

    @help_window.dispose

  end

  

  def update

    @item_window.update

    @components.update    

    if @components.active

      update_comp

      return

    end

    if @item_window.active

      update_item

      return

    end

  end

  

  def update_comp

    if Input.trigger?(Input::A)

      rock_baby

      return

    end

    if Input.trigger?(Input::C)

      $game_system.se_play($data_system.decision_se)

      @components.active = false

      @item_window.active = true

      @item_window.index = 0

    end

    if Input.trigger?(Input::B)

      for i in 0..5

        item = @components.data[i]

        if item != nil

          case item

          when RPG::Item

            $game_party.gain_item(item.id, 1)

          when RPG::Weapon

            $game_party.gain_weapon(item.id, 1)

          when RPG::Armor

            $game_party.gain_armor(item.id, 1)

          end

        end

      end          

      $game_system.se_play($data_system.cancel_se)

      $scene = Scene_Map.new

    end

  end

  

  def update_item

    if Input.trigger?(Input::C)

      $game_system.se_play($data_system.decision_se)

      component = @components.data[@components.index]

      if component != nil

        case component

        when RPG::Item

          $game_party.gain_item(component.id, 1)

        when RPG::Weapon

          $game_party.gain_weapon(component.id, 1)

        when RPG::Armor

          $game_party.gain_armor(component.id, 1)

        end

      end

      item = @item_window.item

      @components.data[@components.index] = item

      case item

      when RPG::Item

        $game_party.lose_item(item.id, 1)

      when RPG::Weapon

        $game_party.lose_weapon(item.id, 1)

      when RPG::Armor

        $game_party.lose_armor(item.id, 1)

      end

      @item_window.refresh

      @components.refresh

      check_recipes

      

      @item_window.active = false

      @item_window.index = -1

      @components.active = true

    end

    if Input.trigger?(Input::B)

      $game_system.se_play($data_system.cancel_se)

      @item_window.active = false

      @item_window.index = -1

      @components.active = true

    end

  end

  

  def check_recipes

    things_in_the_pot = []

    for i in 0..5

      case @components.data[i]

      when nil

        things_in_the_pot << "z"

      when RPG::Item

        things_in_the_pot << "i#{@components.data[i].id}"

      when RPG::Weapon

        things_in_the_pot << "w#{@components.data[i].id}"

      when RPG::Armor

        things_in_the_pot << "a#{@components.data[i].id}"

      end

    end

    

    things_in_the_pot = things_in_the_pot.sort

    for j in 0...RECIPES.size

      temp = RECIPES[j].dup

      temp.pop

      temp = temp.sort

      if things_in_the_pot == temp

        @result.make_item(RECIPES[j][6])

        return

      else

        @result.nullify

      end

    end

  end

  

  def rock_baby

    case @result.item

    when nil

      $game_system.se_play($data_system.buzzer_se)

    when RPG::Item

      $game_party.gain_item(@result.item.id, 1)

      finalize_crafting

    when RPG::Weapon

      $game_party.gain_weapon(@result.item.id, 1)

      finalize_crafting

    when RPG::Armor

      $game_party.gain_armor(@result.item.id, 1)

      finalize_crafting

    end

  end

  

  def finalize_crafting

    $game_system.se_play($data_system.save_se)

    @components.nullify

    @components.refresh

    @item_window.refresh

    @result.nullify

  end

  

end

Instructions
Copy this tab and paste it above 'Main' in your project.

In the script you'll find an array called RECIPES. New recipes are added with new arrays like the following:
['i12', 'i78', 'w3', 'a45', 'a45', 'z', 'i-99']
i stands for items, w for weapons and a for armors.
Acording to this recipe - to make an item of ID 99 you need one item with ID 12, one item with ID 78, one weapon with ID 3, two armors with ID 45. There is a maximum number of six components. If you want to make a recipe consisting of smaller number of components just fill the remaining fields with 'z'. The last ithem in the array is the recipe result. The first character works just like before, then there's a dash required, followed by ID of an item.

To enter the crafting scene call a script like this: $scene = Scene_Craft.new

During the crafting the order of items in the component window is not important - they are sorted within the script.

Compatibility
The system is compatible with default RMXP system. It doesn't override any methods, so it's probably compatible with lots of other things.

Credits and Thanks
arev of rmxp.pl :]

Terms and Conditions
You are free to use this script in your non-commercial project. You can redistribute this script (free of charge) only if you provide information about its original author. If you want to use this script in a commercial project please contact me via http://www.rmxp.pl or http://www.arpgmaker.com private message system.
 
Great addition Arev - I'm currently working on a XAS game with Gameface (Gameface101.com) I was just wondering whether it would be possible to edit the script so that it isn't limited to 7 items - for example:

You could take:

50 Blueberries
10 Raspberries
5 Dot Leafs

To create a healing potion.

That'd really make the script something special :biggrin:
 

arev

Sponsor

Hi Calvin. I'm glad you like the script. While it is totally possible to do what you've described, I'm afraid I won't have the time to alter the script that much.
Take care.
 
I'm adding this system to my game. Great work!

A little suggestion:

When player have enough components to mass produce some thing like potions, the repetitive progress of selecting components is quite annoying.

Maybe add something like ask the player "How many?" or simply let the seleted components stay in the list if available.
 
Beautiful crafting system, arev. Not flashy, no bugs, or anything stupid like that. Just the bare essentials, making it easy to edit :P I'll definately be using this in my upcoming project.
 
Beautiful crafting system, arev. Not flashy, no bugs, or anything stupid like that. Just the bare essentials, making it easy to edit :P I'll definately be using this in my upcoming project.
 
erm. im kinda wondering whats going on here...everything except crafting items with other items seems to be completely fucked. such as if i put 3 components in the pot to make an armor, it gives me a weapon of the same ID. also, it doesnt recognize any weapon i put in the pot, for an upgraded weapon. i really need to get this script on the ball to progress in my project any further, so any help would be greatly appreciated.

((Before you ask, its not a conflicting script, i isolated the script to make sure it wasn't my fault))

Edit: So it seems that anything that uses more than 2 components isnt working, and a weapon result is switched to armor and armor is switched to weapon >_>
 
was wondering if u ever looked at PrexCraft. i personally think its something you could learn from. im using an older version i believe(because i made tons of mods) but ill post if u wanna see what i mean. no offense intended, just wanted to see if i could show u something to help you improve.
2nr3lgk.jpg
 

arev

Sponsor

Ok, hoping I've fixed those glitches, I ask you to test the script a little and see if everything works well. I've updated the first post (only the script, not the demo).
 
This is looking pretty cool! I haven't tasted it completely yet, but I was wondering something about it. Is there anyway that I could use my own layout, a picture, you know? Instead of the windowskin? ^^
 

Winkey

Member

Hi arev ! script perfect ! you can write me a version use big icon 50x50 ? :heart:

sorry! my very bad english :dead:
 
Thanks arev, I really do appreciate the quick work. And yes plague the add-ons one ^_^

Edit: I'll test this out when i get a chance today, arev.
 
luv_kitty12":2eqqbvxg said:
This is looking pretty cool! I haven't tasted it completely yet, but I was wondering something about it. Is there anyway that I could use my own layout, a picture, you know? Instead of the windowskin? ^^
There sure is, as it's the same for all instances of the Window class. Just put self.opacity = 0 in the initialize block (where you might find stuff like self.x = 200 normally) for all windows in the scene (aka all windows in the provided script), and display a sprite in the background, doing this (in the scene, before the windows are defined):
[rgss]@background = Sprite.new
@background.bitmap = RPG::Cache.picture('PictureNameWithoutFileExtension')
[/rgss]
You also have to dispose these - look at the window definitions in the scene to see how you do it.
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top