[XP] Blacksmith System (New Configuration Program!)

Started by ForeverZer0, April 21, 2010, 04:50:15 pm

Previous topic - Next topic

Taiine

Could you then please? I'll give you lots of hugs :3

KK20

February 24, 2012, 06:53:49 pm #121 Last Edit: February 24, 2012, 06:55:04 pm by KK20
Class Window_BlacksmithCommand: ShowHide
#===============================================================================
# ** Window_BlacksmithCommand
#===============================================================================

class Window_BlacksmithCommand < Window_Selectable
 
  def initialize(level, type = 0)
    super(0, 64, 480, 64)
    @level = level
    @commands = []
    # Determine which shop this is
    case type
    when 1 then @commands.push('Forge')
    when 2 then @commands.push('Extract')
    when 0
      @commands.push('Forge')
      @commands.push('Extract')
    end
    # If the game allows enchantments
    if Blacksmith::USE_ENCHANTMENTS
      @commands.push('Enchant')
    end
    @commands.push('Exit')
    @item_max = @column_max = @commands.size
   
    self.contents = Bitmap.new(self.width - 32, self.height - 32)
    refresh
    self.index = 0
  end
  #-----------------------------------------------------------------------------
  def refresh
    self.contents.clear
    (0...@item_max).each {|i| draw_item(i) }
  end
  #-----------------------------------------------------------------------------
  def draw_item(index)
    w = self.width / @item_max
    self.contents.font.color = @level[index] ? normal_color : disabled_color
    self.contents.draw_text(4 + (w * index), 0, w, 32, @commands[index])
  end
  #-----------------------------------------------------------------------------
  def at_index
    return @commands[@index]
  end
end

Class Scene_Blacksmith: ShowHide
#===============================================================================
# ** Scene_Blacksmith
#===============================================================================

class Scene_Blacksmith
 
  def initialize(type = 0, weapons = [], armors = [], items = [], level = nil)
    # Set available goods for this shop based off passed argument.
    @goods = []
    @goods += weapons.collect {|id| $data_weapons[id] }
    @goods += armors.collect {|id| $data_armors[id] }
    @goods += items.collect {|id| $data_items[id] }
    @goods.uniq!
    # Configure the level variable
    @level = (level == nil) ? Array.new(4, true) : (level + [true])
    @enchants = Blacksmith::USE_ENCHANTMENTS
    @type = type
  end
  #-----------------------------------------------------------------------------
  def main
    # Create a Proc to handle confirmation of choices
    @confirm_proc = Proc.new {
      @help_window.set_text('Are you sure?')
      window = Window_Command.new(160, ['Confirm', 'Cancel'])
      window.x, window.y, window.z = 224, 192, 9999
      loop { Graphics.update; Input.update; window.update
        if Input.trigger?(Input::C) || Input.trigger?(Input::B)
          result = (Input.trigger?(Input::C) && window.index == 0)
          $game_system.se_play($data_system.cancel_se) unless result
          window.dispose
          break(result)
        end
      }
    }
    # Initialize the needed windows.
    @command_window = Window_BlacksmithCommand.new(@level, @type)
    @forge_window = Window_BlacksmithForge.new(@goods)
    @extract_window = Window_BlacksmithExtract.new
    @materials_window = Window_BlacksmithMaterials.new
    @enchant_window = Window_BlacksmithEnchant.new
    @status_window = Window_BlacksmithStatus.new
    @dummy_window = Window_Base.new(0, 128, 640, 352)
    @gold_window = Window_Gold.new
    @gold_window.x, @gold_window.y = 480, 64 
    @help_window = Window_Help.new
    # Bind the help window to the other windows.
    @forge_window.help_window = @extract_window.help_window = @help_window
    @enchant_window.help_window = @help_window
    # Set a windows array for easier handling of all windows.
    @windows = [@command_window, @forge_window, @extract_window, @help_window,
      @materials_window, @status_window, @dummy_window, @gold_window, @enchant_window]
    # Create map sprite if configured to do so, and set window opacity
    if Blacksmith::MAP_BACK
      @spriteset = Spriteset_Map.new
      @windows.each {|window| window.opacity = 160 }
    end
    # Execute the transition and start the main loop.
    Graphics.transition
    loop {Graphics.update; Input.update; update; break if $scene != self }
    # Freeze the Graphics and dispose the windows
    Graphics.freeze
    @windows.each {|window| window.dispose }
    if Blacksmith::MAP_BACK && @spriteset != nil
      @spriteset.dispose
    end
  end
  #-----------------------------------------------------------------------------
  def update
    # Update the windows
    @windows.each {|window| window.update }
    # Branch method depending on current action.
    if @command_window.active
      update_command
    elsif @extract_window.active
      update_extract
    elsif @forge_window.active
      update_forge
    elsif @materials_window.active
      update_materials
    elsif @enchant_window.active
      update_enchant
    end
  end
  #-----------------------------------------------------------------------------
  def back_to_map
    # Play SE and return to the map.
    $game_system.se_play($data_system.cancel_se)
    $scene = Scene_Map.new
  end
  #-----------------------------------------------------------------------------
  def update_command
    # Set help text depending on the selected index.
    help_text = case @command_window.at_index
    when "Forge" then 'Use materials to forge new weapons, armors, and items.'
    when "Extract" then 'Extract materials from weapons, armors, and items.'
    when "Enchant" then 'Enchant weapons, armors, and items using other items.'
    when "Exit" then 'Exit the shop.'
    end
    @help_window.set_text(help_text)
    # Check for Input.
    if Input.trigger?(Input::B)
      back_to_map
    elsif Input.trigger?(Input::C)
      $game_system.se_play($data_system.decision_se)
      # Branch depending on command index
      case @command_window.at_index
      when "Forge"
        # Play SE and return if option is locked.
        unless @level[0]
          $game_system.se_play($data_system.buzzer_se)
          return
        end
        # Shift scene to forge phase.
        @dummy_window.visible = false
        @forge_window.refresh(false)
        @command_window.active = false
        @forge_window.active = @forge_window.visible = true
        @status_window.visible = true
      when "Extract"
        # Play SE and return if option is locked.
        unless @level[1]
          $game_system.se_play($data_system.buzzer_se)
          return
        end
        # Shift scene to extract phase
        @extract_window.refresh
        @command_window.active = @dummy_window.visible = false
        @extract_window.active = @extract_window.visible = true
        @status_window.visible = true
      when "Enchant"
        # Play SE and return if option is locked.
        if @enchants
          unless @level[2]
            $game_system.se_play($data_system.buzzer_se)
            return
          end
          # Shift scene to enchant phase.
          @forge_window.refresh(true)
          @command_window.active = @dummy_window.visible = false
          @forge_window.active = @forge_window.visible = true
          @status_window.visible = true
        else
          back_to_map
        end
      when "Exit"
        back_to_map
      end
    end
  end
  #-----------------------------------------------------------------------------
  def update_forge
    # Update for input when forge window is active.
    @item = @status_window.item = @forge_window.item
    if Input.trigger?(Input::B)
      $game_system.se_play($data_system.cancel_se)
      @command_window.active = @dummy_window.visible = true
      @forge_window.active = @forge_window.visible = false
      @status_window.visible = false
    elsif Input.trigger?(Input::C)
      $game_system.se_play($data_system.decision_se)
      @forge_window.active = @forge_window.visible = false
      if @command_window.at_index == "Forge"
        @materials_window.refresh(@item, 0)
        @materials_window.visible = @materials_window.active = true
      else
        @enchant_window.refresh
        @enchant_window.visible = @enchant_window.active = true
      end
    end
  end
  #-----------------------------------------------------------------------------
  def update_extract
    # Update for input when extraction window is active.
    @item = @status_window.item = @extract_window.item
    if Input.trigger?(Input::B)
      $game_system.se_play($data_system.cancel_se)
      @command_window.active = @dummy_window.visible = true
      @extract_window.active = @extract_window.visible = false
      @status_window.visible = false
    elsif Input.trigger?(Input::C)
      $game_system.se_play($data_system.decision_se)
      @materials_window.refresh(@item, 1)
      @extract_window.active = @extract_window.visible = false
      @materials_window.visible = @materials_window.active = true
    end
  end
  #-----------------------------------------------------------------------------
  def update_enchant
    # Update input on the enchantment items screen.
    if Input.trigger?(Input::B)
      # Return to previous screen if cancel button is pressed.
      $game_system.se_play($data_system.cancel_se)
      @enchant_window.visible = @enchant_window.active = false
      @forge_window.active = @forge_window.visible = true
    elsif Input.trigger?(Input::C) && @confirm_proc.call
      enchant_item
    end
  end
  #-----------------------------------------------------------------------------
  def enchant_item
    # Apply enchantment to weapon/armor using item
    $game_party.lose_item(@enchant_window.item.id, 1)
    Blacksmith.create_item(@forge_window.item, @enchant_window.item)
    # Play SE
    $game_system.se_play(RPG::AudioFile.new(*Blacksmith::ENCHANT_SE))
    # Refesh windows
    [@enchant_window, @status_window].each {|window| window.refresh }
    @forge_window.refresh(true)
    # Return to previous screen
    @enchant_window.visible = @enchant_window.active = false
    @forge_window.active = @forge_window.visible = true
  end
  #-----------------------------------------------------------------------------
  def update_materials
    # Show help text.
    text = 'Press the Action Button to proceed. Press Cancel to go back'
    @help_window.set_text(text)
    if Input.trigger?(Input::B)
      # Return to previous screen if cancel button is pressed.
      $game_system.se_play($data_system.cancel_se)
      @materials_window.visible = @materials_window.active = false
      if @command_window.at_index == "Forge"
        @forge_window.active = @forge_window.visible = true
      else
        @extract_window.active = @extract_window.visible = true
      end
    elsif Input.trigger?(Input::C) && @confirm_proc.call
      @command_window.at_index == "Forge" ? forge_item : extract_item
    end
  end
  #-----------------------------------------------------------------------------
  def forge_item
    # Set local variables depending on item type.
    case @item
    when RPG::Weapon
      quantity, type = $game_party.weapon_number(@item.id), 0
      materials = Blacksmith.weapon_forges(@item.id)
      price = Blacksmith.weapon_gold(@item.id)[0]
    when RPG::Armor
      quantity, type = $game_party.armor_number(@item.id), 1
      materials = Blacksmith.armor_forges(@item.id)
      price = Blacksmith.armor_gold(@item.id)[0]
    when RPG::Item
      quantity, type = $game_party.item_number(@item.id), 2
      materials = Blacksmith.item_forges(@item.id)
      price = Blacksmith.item_gold(@item.id)[0]
    end
    # If player doesn't have the materials or gold, play SE and end method.
    unless Blacksmith.materials?(type, @item.id)
      $game_system.se_play($data_system.buzzer_se)
      return
    end
    # End method and play buzzer if inventory is full.
    return $game_system.se_play($data_system.buzzer_se) if quantity == 99
    # Play the defined SE used when forging.
    $game_system.se_play(RPG::AudioFile.new(*Blacksmith::FORGE_SE))
    # Remove required materials from inventory and subtract gold cost.
    if materials != nil
      materials.each {|material|
        case material[0]
        when 0 then $game_party.lose_weapon(material[1], material[2])
        when 1 then $game_party.lose_armor(material[1], material[2])
        when 2 then $game_party.lose_item(material[1], material[2])
        end
      }
    end
    $game_party.lose_gold(price)
    # Add forged item
    case @item
    when RPG::Weapon then $game_party.gain_weapon(@item.id, 1)
    when RPG::Armor then $game_party.gain_armor(@item.id, 1)
    when RPG::Item then $game_party.gain_item(@item.id, 1)
    end
    # Reset windows.
    @materials_window.visible = @materials_window.active = false
    @forge_window.active = @forge_window.visible = true
    # Refresh any windows that may have changed
    [@status_window, @gold_window, @extract_window, @forge_window,
      @enchant_window].each {|window| window.refresh }
  end
  #-----------------------------------------------------------------------------
  def extract_item
    # Set local variables depending on item type.
    case @item
    when RPG::Weapon
      quantity = $game_party.weapon_number(@item.id)
      materials = Blacksmith.weapon_extractions(@item.id)
      price = Blacksmith.weapon_gold(@item.id)[1]
    when RPG::Armor
      quantity = $game_party.armor_number(@item.id)
      materials = Blacksmith.armor_extractions(@item.id)
      price = Blacksmith.armor_gold(@item.id)[1]
    when RPG::Item
      quantity = $game_party.item_number(@item.id)
      materials = Blacksmith.item_extractions(@item.id)
      price = Blacksmith.item_gold(@item.id)[1]
    end
    # If nothing is defined for the extraction, return.
    if materials == nil || (materials.empty? && price == 0)
      return $game_system.se_play($data_system.buzzer_se)
    end
    # Play extraction SE
    $game_system.se_play(RPG::AudioFile.new(*Blacksmith::EXTRACT_SE))
    # Perform extraction, adding materials and increasing gold.
    materials.each {|material|
      case material[0]
      when 0 then $game_party.gain_weapon(material[1], material[2])
      when 1 then $game_party.gain_armor(material[1], material[2])
      when 2 then $game_party.gain_item(material[1], material[2])
      end
    }
    $game_party.gain_gold(price)
    # Remove extracted item from inventory
    case @item
    when RPG::Weapon then $game_party.lose_weapon(@item.id, 1)
    when RPG::Armor then $game_party.lose_armor(@item.id, 1)
    when RPG::Item then $game_party.lose_item(@item.id, 1)
    end
    # Reset windows.
    @materials_window.visible = @materials_window.active = false
    @extract_window.active = @extract_window.visible = true
    # Refresh any windows that may have changed
    [@status_window, @gold_window, @extract_window].each {|window| window.refresh }
  end
end


Script call has been modified to the following:
$scene = Scene_Blacksmith.new(type, weapons, armors, items, level)
where "type" refers to what shop you want. "type" is an integer. These values do the following:
0 => Forge and Extract
1 => Forge only
2 => Extract only

Other Projects
RPG Maker XP Ace  Upgrade RMXP to RMVXA performance!
XPA Tilemap  Tilemap rewrite with many features, including custom resolution!

Nintendo Switch Friend Code: 8310-1917-5318
Discord: KK20 Tyler#8901

Join the CP Discord Server!

Skwig

Quote from: Darth Dastardly on February 24, 2012, 05:06:41 pm
@Skwig:
Try putting the arguments on the same line: 
$scene = Scene_Blacksmith.new(w,a,i,l)


or at least the leading parenthesis:

$scene = Scene_Blacksmith.new(
w,a,i,l)



it is in one line, but the line is too long for the editor window
will try the other option, though

ForeverZer0

Alternatively you could also do this:

$scene = 
Scene_Blacksmith.new(w,a,i,l)
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

Skwig

Quote from: Darth Dastardly on February 24, 2012, 08:02:15 pm
Alternatively you could also do this:

$scene = 
Scene_Blacksmith.new(w,a,i,l)


Thanks, it worked now...

@KK20 - could you do a more retard noob friendly explanation how to set up your edit of script? i have it all copied and wondering if i should replace the parts that you edited or something...
Thanks

RPGamer5

Bump
Still have the "comparison of Fixnum with nil failed" error!

LiTTleDRAgo

Quote from: RPGamer5 on February 21, 2012, 11:55:24 am
Hi, i would really like to include this in my project (with proper credit of course), but i get an argument error if i call the Scene_BlackSmith.new:
"line 349: comparison of Fixnum with nil failed"
# Check gold, skipping item check if there is not enough.
if $game_party.gold >= materials[1][0]

Since i have no scripting knowledge, any help would be appreciated.
Btw, i also use Blizz-ABS if it matters

And i'm sorry if i dug up an old thread


try changing that line to

if !materials[1][0].nil? && $game_party.gold >= materials[1][0]

Taiine

Thanks muchly *HUG*, though I forgot this had enchanting to. Can that also be split off?


KK20

Quote from: Taiine on February 25, 2012, 12:25:54 pm
Thanks muchly *HUG*, though I forgot this had enchanting to. Can that also be split off?

Class Window_BlacksmithCommand: ShowHide
#===============================================================================
# ** Window_BlacksmithCommand
#===============================================================================

class Window_BlacksmithCommand < Window_Selectable
 
  def initialize(level, type = 0)
    super(0, 64, 480, 64)
    @level = level
    @commands = []
    # Determine which shop this is
    case type
    when 1 then @commands.push('Forge')
    when 2 then @commands.push('Extract')
    when 0
      @commands.push('Forge')
      @commands.push('Extract')
    end
    # If the game allows enchantments
    if Blacksmith::USE_ENCHANTMENTS or (!Blacksmith::USE_ENCHANTMENTS and type == 3)
      @commands.push('Enchant')
    end
    @commands.push('Exit')
    @item_max = @column_max = @commands.size
   
    self.contents = Bitmap.new(self.width - 32, self.height - 32)
    refresh
    self.index = 0
  end
  #-----------------------------------------------------------------------------
  def refresh
    self.contents.clear
    (0...@item_max).each {|i| draw_item(i) }
  end
  #-----------------------------------------------------------------------------
  def draw_item(index)
    w = self.width / @item_max
    self.contents.font.color = @level[index] ? normal_color : disabled_color
    self.contents.draw_text(4 + (w * index), 0, w, 32, @commands[index])
  end
  #-----------------------------------------------------------------------------
  def at_index
    return @commands[@index]
  end
end

Class Scene_Blacksmith: ShowHide
#===============================================================================
# ** Scene_Blacksmith
#===============================================================================

class Scene_Blacksmith
 
  def initialize(type = 0, weapons = [], armors = [], items = [], level = nil)
    # Set available goods for this shop based off passed argument.
    @goods = []
    @goods += weapons.collect {|id| $data_weapons[id] }
    @goods += armors.collect {|id| $data_armors[id] }
    @goods += items.collect {|id| $data_items[id] }
    @goods.uniq!
    # Configure the level variable
    @level = (level == nil) ? Array.new(4, true) : (level + [true])
    @type = type
  end
  #-----------------------------------------------------------------------------
  def main
    # Create a Proc to handle confirmation of choices
    @confirm_proc = Proc.new {
      @help_window.set_text('Are you sure?')
      window = Window_Command.new(160, ['Confirm', 'Cancel'])
      window.x, window.y, window.z = 224, 192, 9999
      loop { Graphics.update; Input.update; window.update
        if Input.trigger?(Input::C) || Input.trigger?(Input::B)
          result = (Input.trigger?(Input::C) && window.index == 0)
          $game_system.se_play($data_system.cancel_se) unless result
          window.dispose
          break(result)
        end
      }
    }
    # Initialize the needed windows.
    @command_window = Window_BlacksmithCommand.new(@level, @type)
    @forge_window = Window_BlacksmithForge.new(@goods)
    @extract_window = Window_BlacksmithExtract.new
    @materials_window = Window_BlacksmithMaterials.new
    @enchant_window = Window_BlacksmithEnchant.new
    @status_window = Window_BlacksmithStatus.new
    @dummy_window = Window_Base.new(0, 128, 640, 352)
    @gold_window = Window_Gold.new
    @gold_window.x, @gold_window.y = 480, 64 
    @help_window = Window_Help.new
    # Bind the help window to the other windows.
    @forge_window.help_window = @extract_window.help_window = @help_window
    @enchant_window.help_window = @help_window
    # Set a windows array for easier handling of all windows.
    @windows = [@command_window, @forge_window, @extract_window, @help_window,
      @materials_window, @status_window, @dummy_window, @gold_window, @enchant_window]
    # Create map sprite if configured to do so, and set window opacity
    if Blacksmith::MAP_BACK
      @spriteset = Spriteset_Map.new
      @windows.each {|window| window.opacity = 160 }
    end
    # Execute the transition and start the main loop.
    Graphics.transition
    loop {Graphics.update; Input.update; update; break if $scene != self }
    # Freeze the Graphics and dispose the windows
    Graphics.freeze
    @windows.each {|window| window.dispose }
    if Blacksmith::MAP_BACK && @spriteset != nil
      @spriteset.dispose
    end
  end
  #-----------------------------------------------------------------------------
  def update
    # Update the windows
    @windows.each {|window| window.update }
    # Branch method depending on current action.
    if @command_window.active
      update_command
    elsif @extract_window.active
      update_extract
    elsif @forge_window.active
      update_forge
    elsif @materials_window.active
      update_materials
    elsif @enchant_window.active
      update_enchant
    end
  end
  #-----------------------------------------------------------------------------
  def back_to_map
    # Play SE and return to the map.
    $game_system.se_play($data_system.cancel_se)
    $scene = Scene_Map.new
  end
  #-----------------------------------------------------------------------------
  def update_command
    # Set help text depending on the selected index.
    help_text = case @command_window.at_index
    when "Forge" then 'Use materials to forge new weapons, armors, and items.'
    when "Extract" then 'Extract materials from weapons, armors, and items.'
    when "Enchant" then 'Enchant weapons, armors, and items using other items.'
    when "Exit" then 'Exit the shop.'
    end
    @help_window.set_text(help_text)
    # Check for Input.
    if Input.trigger?(Input::B)
      back_to_map
    elsif Input.trigger?(Input::C)
      $game_system.se_play($data_system.decision_se)
      # Branch depending on command index
      case @command_window.at_index
      when "Forge"
        # Play SE and return if option is locked.
        unless @level[0]
          $game_system.se_play($data_system.buzzer_se)
          return
        end
        # Shift scene to forge phase.
        @dummy_window.visible = false
        @forge_window.refresh(false)
        @command_window.active = false
        @forge_window.active = @forge_window.visible = true
        @status_window.visible = true
      when "Extract"
        # Play SE and return if option is locked.
        unless @level[1]
          $game_system.se_play($data_system.buzzer_se)
          return
        end
        # Shift scene to extract phase
        @extract_window.refresh
        @command_window.active = @dummy_window.visible = false
        @extract_window.active = @extract_window.visible = true
        @status_window.visible = true
      when "Enchant"
        # Play SE and return if option is locked.
        unless @level[2]
          $game_system.se_play($data_system.buzzer_se)
          return
        end
        # Shift scene to enchant phase.
        @forge_window.refresh(true)
        @command_window.active = @dummy_window.visible = false
        @forge_window.active = @forge_window.visible = true
        @status_window.visible = true
      when "Exit"
        back_to_map
      end
    end
  end
  #-----------------------------------------------------------------------------
  def update_forge
    # Update for input when forge window is active.
    @item = @status_window.item = @forge_window.item
    if Input.trigger?(Input::B)
      $game_system.se_play($data_system.cancel_se)
      @command_window.active = @dummy_window.visible = true
      @forge_window.active = @forge_window.visible = false
      @status_window.visible = false
    elsif Input.trigger?(Input::C)
      $game_system.se_play($data_system.decision_se)
      @forge_window.active = @forge_window.visible = false
      if @command_window.at_index == "Forge"
        @materials_window.refresh(@item, 0)
        @materials_window.visible = @materials_window.active = true
      else
        @enchant_window.refresh
        @enchant_window.visible = @enchant_window.active = true
      end
    end
  end
  #-----------------------------------------------------------------------------
  def update_extract
    # Update for input when extraction window is active.
    @item = @status_window.item = @extract_window.item
    if Input.trigger?(Input::B)
      $game_system.se_play($data_system.cancel_se)
      @command_window.active = @dummy_window.visible = true
      @extract_window.active = @extract_window.visible = false
      @status_window.visible = false
    elsif Input.trigger?(Input::C)
      $game_system.se_play($data_system.decision_se)
      @materials_window.refresh(@item, 1)
      @extract_window.active = @extract_window.visible = false
      @materials_window.visible = @materials_window.active = true
    end
  end
  #-----------------------------------------------------------------------------
  def update_enchant
    # Update input on the enchantment items screen.
    if Input.trigger?(Input::B)
      # Return to previous screen if cancel button is pressed.
      $game_system.se_play($data_system.cancel_se)
      @enchant_window.visible = @enchant_window.active = false
      @forge_window.active = @forge_window.visible = true
    elsif Input.trigger?(Input::C) && @confirm_proc.call
      enchant_item
    end
  end
  #-----------------------------------------------------------------------------
  def enchant_item
    # Apply enchantment to weapon/armor using item
    $game_party.lose_item(@enchant_window.item.id, 1)
    Blacksmith.create_item(@forge_window.item, @enchant_window.item)
    # Play SE
    $game_system.se_play(RPG::AudioFile.new(*Blacksmith::ENCHANT_SE))
    # Refesh windows
    [@enchant_window, @status_window].each {|window| window.refresh }
    @forge_window.refresh(true)
    # Return to previous screen
    @enchant_window.visible = @enchant_window.active = false
    @forge_window.active = @forge_window.visible = true
  end
  #-----------------------------------------------------------------------------
  def update_materials
    # Show help text.
    text = 'Press the Action Button to proceed. Press Cancel to go back'
    @help_window.set_text(text)
    if Input.trigger?(Input::B)
      # Return to previous screen if cancel button is pressed.
      $game_system.se_play($data_system.cancel_se)
      @materials_window.visible = @materials_window.active = false
      if @command_window.at_index == "Forge"
        @forge_window.active = @forge_window.visible = true
      else
        @extract_window.active = @extract_window.visible = true
      end
    elsif Input.trigger?(Input::C) && @confirm_proc.call
      @command_window.at_index == "Forge" ? forge_item : extract_item
    end
  end
  #-----------------------------------------------------------------------------
  def forge_item
    # Set local variables depending on item type.
    case @item
    when RPG::Weapon
      quantity, type = $game_party.weapon_number(@item.id), 0
      materials = Blacksmith.weapon_forges(@item.id)
      price = Blacksmith.weapon_gold(@item.id)[0]
    when RPG::Armor
      quantity, type = $game_party.armor_number(@item.id), 1
      materials = Blacksmith.armor_forges(@item.id)
      price = Blacksmith.armor_gold(@item.id)[0]
    when RPG::Item
      quantity, type = $game_party.item_number(@item.id), 2
      materials = Blacksmith.item_forges(@item.id)
      price = Blacksmith.item_gold(@item.id)[0]
    end
    # If player doesn't have the materials or gold, play SE and end method.
    unless Blacksmith.materials?(type, @item.id)
      $game_system.se_play($data_system.buzzer_se)
      return
    end
    # End method and play buzzer if inventory is full.
    return $game_system.se_play($data_system.buzzer_se) if quantity == 99
    # Play the defined SE used when forging.
    $game_system.se_play(RPG::AudioFile.new(*Blacksmith::FORGE_SE))
    # Remove required materials from inventory and subtract gold cost.
    if materials != nil
      materials.each {|material|
        case material[0]
        when 0 then $game_party.lose_weapon(material[1], material[2])
        when 1 then $game_party.lose_armor(material[1], material[2])
        when 2 then $game_party.lose_item(material[1], material[2])
        end
      }
    end
    $game_party.lose_gold(price)
    # Add forged item
    case @item
    when RPG::Weapon then $game_party.gain_weapon(@item.id, 1)
    when RPG::Armor then $game_party.gain_armor(@item.id, 1)
    when RPG::Item then $game_party.gain_item(@item.id, 1)
    end
    # Reset windows.
    @materials_window.visible = @materials_window.active = false
    @forge_window.active = @forge_window.visible = true
    # Refresh any windows that may have changed
    [@status_window, @gold_window, @extract_window, @forge_window,
      @enchant_window].each {|window| window.refresh }
  end
  #-----------------------------------------------------------------------------
  def extract_item
    # Set local variables depending on item type.
    case @item
    when RPG::Weapon
      quantity = $game_party.weapon_number(@item.id)
      materials = Blacksmith.weapon_extractions(@item.id)
      price = Blacksmith.weapon_gold(@item.id)[1]
    when RPG::Armor
      quantity = $game_party.armor_number(@item.id)
      materials = Blacksmith.armor_extractions(@item.id)
      price = Blacksmith.armor_gold(@item.id)[1]
    when RPG::Item
      quantity = $game_party.item_number(@item.id)
      materials = Blacksmith.item_extractions(@item.id)
      price = Blacksmith.item_gold(@item.id)[1]
    end
    # If nothing is defined for the extraction, return.
    if materials == nil || (materials.empty? && price == 0)
      return $game_system.se_play($data_system.buzzer_se)
    end
    # Play extraction SE
    $game_system.se_play(RPG::AudioFile.new(*Blacksmith::EXTRACT_SE))
    # Perform extraction, adding materials and increasing gold.
    materials.each {|material|
      case material[0]
      when 0 then $game_party.gain_weapon(material[1], material[2])
      when 1 then $game_party.gain_armor(material[1], material[2])
      when 2 then $game_party.gain_item(material[1], material[2])
      end
    }
    $game_party.gain_gold(price)
    # Remove extracted item from inventory
    case @item
    when RPG::Weapon then $game_party.lose_weapon(@item.id, 1)
    when RPG::Armor then $game_party.lose_armor(@item.id, 1)
    when RPG::Item then $game_party.lose_item(@item.id, 1)
    end
    # Reset windows.
    @materials_window.visible = @materials_window.active = false
    @extract_window.active = @extract_window.visible = true
    # Refresh any windows that may have changed
    [@status_window, @gold_window, @extract_window].each {|window| window.refresh }
  end
end
Replace my old edit with these. Go into the configuration, set USE_ENCHANTMENTS equal to false. When calling up the blacksmith scene, set 'type' to 3. That will allow you to make an Enchantment-only shop. Leaving USE_ENCHANTMENTS equal to true will always push the enchantment as an available option, regardless of what value you set 'type' to.

Quote from: Skwig on February 25, 2012, 03:25:14 am
@KK20 - could you do a more retard noob friendly explanation how to set up your edit of script? i have it all copied and wondering if i should replace the parts that you edited or something...
Thanks

The edits I made were by request from Taiine, but if you would like the edit too, then do this.

1.)Obviously, copy and paste my edits into your game. They should be placed before 'Main' but after the original Blacksmith script(s).
2.) The NPC script call setup is still mostly the same. However, it should look a little like this:
Spoiler: ShowHide
where the letter 'T' can be any value from 0 to 3. As I posted before, the type of shop that opens up depends on what value you set 'T' to.

Other Projects
RPG Maker XP Ace  Upgrade RMXP to RMVXA performance!
XPA Tilemap  Tilemap rewrite with many features, including custom resolution!

Nintendo Switch Friend Code: 8310-1917-5318
Discord: KK20 Tyler#8901

Join the CP Discord Server!

Skwig

@KK20 - for slower people such as me you should add these notes somewhere:
- The number that defines T can't be in [ ]s
- When using this edit, remove the line in script call that defines L
- In the final line, t should be in the beginning ( $scene = Scene_Blacksmith.new(t, w, a, i) )

That's probably all.. would speed up the process of setting it up

KK20

Quote from: Skwig on February 25, 2012, 02:37:01 pm
@KK20 - for slower people such as me you should add these notes somewhere:
- The number that defines T can't be in [ ]s
- When using this edit, remove the line in script call that defines L
- In the final line, t should be in the beginning ( $scene = Scene_Blacksmith.new(t, w, a, i) )

That's probably all.. would speed up the process of setting it up


I stated that 'type' is an integer, not an array.
[0] (an array) is not the same as 0 (an integer).

You don't have to remove "L". That's an optional parameter. It's unrelated to my edit.
I also said that the configuration has been changed to:
$scene = Scene_Blacksmith.new(type, weapon, armor, items, level)
In the world of programming, you can't change the order of the arguments and expect the system to understand what parameter each value satisfies.

But as long as you got it working, I am content.  :)

Other Projects
RPG Maker XP Ace  Upgrade RMXP to RMVXA performance!
XPA Tilemap  Tilemap rewrite with many features, including custom resolution!

Nintendo Switch Friend Code: 8310-1917-5318
Discord: KK20 Tyler#8901

Join the CP Discord Server!

Shining Riku

I have a problem that needs fixing, if somebody could help me sort this out I'd be STOKED, man.

The enchanting system is kinda broken at the moment because it doesn't take any of your money when you use one of the items to enchant. Also, if you have 0 of the item in question when enchanting you can still "enchant" things.

I need to be able to lock the items that aren't in the inventory and to also fix it so it actually costs you the set price of the enchantment.
As it is now somebody could run into the enchantment shop and max the stats out on their starting weapon and it's...troublesome having such a fun feature
be so broken.

I could probably word this better but, if anybody has any questions for me to answer to clear this up please ask.

BTW I HAVE gone into the script and I feel like I've pinned down where the problem is but I have limited experience fixing these things. I believe it's missing just a few lines to acknowledge the enchantment price set to each item that's used to enchant and remove said price from the player's wallet.
It also lacks the ability to lock the options or "grey them out" when the player doesn't have enough money or doesn't have the item.

sirSLR

March 16, 2012, 05:17:16 pm #133 Last Edit: March 16, 2012, 05:30:31 pm by sirSLR
uhm when i take a staff that fires magic ball when atacking and i enchant it it no more fires an energy ball but instead slashes like a sword... Any way to not change that attack type?

EDIT : and also when item number for enchanting reaches 0 i can keep enchanting.

Magus

Not sure if I posted this yet, but this is like one of the best scripts ever. It's the heart of my game and if this is removed, my game would die xD.
Seriously, I'm curious about your next releases :3
I have to say though, the idea where you can even extract the materials from the object/weapon that you find was a splendid idea. Nice.  Good thing this forum doesn't have a rating system or I'd be hated for rating a lot of people's scripts 10/10.

But back to what I was saying, I wasn't until recently that I noticed: "wait, wtf, wait a sec. THERE'S AN EXTRACTION SYSTEM TOO. Oshi :o"


LEVEL ME DOWN. THE ANTI-BLIZZ GROUP IS AMONG YOU... Do it for the chick below...She watches..<br />

ForeverZer0

Lol, thanks. :)

I think there is still a minor bug with the extraction part, wherein the player can continue to extract after the piece of equipment has ran out. I forgot to put an additional check in there somewhere apparently.

I really can't find the ambition to write scripts for RGSS anymore, so I haven't really even looked into fixing it. If someone would be so kind to do so, I would be very thankful. It will probably only require a "if $game_party.whatever_number(ID) > 0", so it would not take much work. I'd be sure to add a very special thanks to the re-uploaded script, too.

Anyways, thanks for your kind feedback. ;)
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

sinister678

hey i just started to look at scripts for my game and i was wonder how to activate this script im really really new at this so i have no clue what im doing

KK20

It says it right there in the script under "Instructions". At least check the demo out and see an example of how to call it.

Other Projects
RPG Maker XP Ace  Upgrade RMXP to RMVXA performance!
XPA Tilemap  Tilemap rewrite with many features, including custom resolution!

Nintendo Switch Friend Code: 8310-1917-5318
Discord: KK20 Tyler#8901

Join the CP Discord Server!

PhoenixFire

Quote from: KK20 on December 31, 2013, 12:40:15 am
At least check the demo out and see an example of how to call it.



Yeah. That's usually the best place to start... Usually...
Quote from: Subsonic_Noise on July 01, 2011, 02:42:19 amNext off, how to create a first person shooter using microsoft excel.

Quote from: Zeriab on September 09, 2011, 02:58:58 pm<Remember when computers had turbo buttons?

KK20

January 02, 2014, 03:10:25 pm #139 Last Edit: January 02, 2014, 03:13:20 pm by KK20
Quote from: ForeverZer0 on April 09, 2012, 05:35:33 pm
I really can't find the ambition to write scripts for RGSS anymore, so I haven't really even looked into fixing it. If someone would be so kind to do so, I would be very thankful. It will probably only require a "if $game_party.whatever_number(ID) > 0", so it would not take much work. I'd be sure to add a very special thanks to the re-uploaded script, too.

I know this was a long time ago, and I'm sorry for not getting to it sooner. I guess people just stopped talking about it for a while and I forgot about the bugs.

I fixed a lot of graphical and functional bugs.

http://pastebin.com/AFrMCa2f

Looking for feedback and any more things that should be added/fixed.

Other Projects
RPG Maker XP Ace  Upgrade RMXP to RMVXA performance!
XPA Tilemap  Tilemap rewrite with many features, including custom resolution!

Nintendo Switch Friend Code: 8310-1917-5318
Discord: KK20 Tyler#8901

Join the CP Discord Server!