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.

Making an item "enchanter" NPC.

So I've been trying to make an enchanter type NPC. What it would do is let you take a weapon, plus say a "Fire Stone" and then change it to "sword name of fire"

The technique I've used for this is just to make multiple versions of the sword, then have it check if you have the items, if you do, it takes them and gives you the new sword, to give the illusion of enchanting the weapon. The problem is I can't seem to find a way to make it let you pick which weapon to enchant, but only show options for items you currently have.

So for example, say I have a Bronze Sword, Iron Sword and a Steel Sword, I'd want to talk to him and have him ask "which weapon should I enchant?" followed by a list of options that include those 3 swords, but no others. And I'd want it to work for any combination of swords.

I've tried to make a complex ocean of conditional branches, but I just can't seem to get it to work. Any help would be greatly appreciated!
 
[rgss] 
#====================================================================
# ** Item menu addon
#-------------------------------------------------------------------
#  by: Silver Wind
#
#  - What is this script for ?
#  By default, weapons, armors and items with
#  scope 'none' are disabled on the item menu.
#  This script lets the player select them anyway.
#  Once selected, the item menu will close, and the item
#  is saved in variables 001 and 002, and also in $game_temp.
#  variable 001: number of the item/weapon/armor
#  variable 002: type. 0 means item, 1=weapon and 2=armor.
#  * if you wish to use other variables,
#    change the numbers in lines 26-27.
#====================================================================
 
class Game_Temp
  attr_accessor  :select_equip    # enable weapon/armor selection?
  attr_accessor  :item_id
  attr_accessor  :item_kind
end
 
class Scene_Item
  ID_VAR    = 1
  KIND_VAR  = 2
  def update_item
    # If B button was pressed
    if Input.trigger?(Input::B)
      # Play cancel SE
      $game_system.se_play($data_system.cancel_se)
      # Switch to menu screen
      $scene = Scene_Menu.new(0)
      return
    end
    # If C button was pressed
    if Input.trigger?(Input::C)
      # Get currently selected data on the item window
      @item = @item_window.item
           
      # ---------- my edit --------------------------
      can_use = @item.is_a?(RPG::Item) and
                $game_party.item_can_use?(@item.id)
      can_use |= $game_temp.select_equip
      # If it can't be used
      unless can_use
        # Play buzzer SE
        $game_system.se_play($data_system.buzzer_se)
        return
      end
      # Play decision SE
      $game_system.se_play($data_system.decision_se)
      # chek if the item has a target
      is_weapon = @item.is_a?(RPG::Weapon)
      is_armor  = @item.is_a?(RPG::Armor)
      is_item   = @item.is_a?(RPG::Item)
      no_target = ( is_weapon or
                    is_armor or
                    @item.scope == 0 )
      if no_target
        # save the item and return
        $game_variables[ID_VAR] = @item.id
        kind = is_weapon ? 1 : (is_armor ? 2 : 0)
        $game_variables[KIND_VAR] = kind
        $game_temp.item_id = @item.id
        $game_temp.item_kind = kind
        $scene = Scene_Map.new
        return
      end
      # ---------- my edit --------------------------
     
      # If effect scope is an ally
      if @item.scope >= 3
        # Activate target window
        @item_window.active = false
        @target_window.x = (@item_window.index + 1) % 2 * 304
        @target_window.visible = true
        @target_window.active = true
        # Set cursor position to effect scope (single / all)
        if @item.scope == 4 || @item.scope == 6
          @target_window.index = -1
        else
          @target_window.index = 0
        end
      # If effect scope is other than an ally
      else
        # If command event ID is valid
        if @item.common_event_id > 0
          # Command event call reservation
          $game_temp.common_event_id = @item.common_event_id
          # Play item use SE
          $game_system.se_play(@item.menu_se)
          # If consumable
          if @item.consumable
            # Decrease used items by 1
            $game_party.lose_item(@item.id, 1)
            # Draw item window item
            @item_window.draw_item(@item_window.index)
          end
          # Switch to map screen
          $scene = Scene_Map.new
          return
        end
      end
      return
    end
  end
 
end
 
[/rgss]
I've seen other people asking 'how to let the player use item on an event'.
So, I made this simple script.
To select weapon/armor, make an event with a script command:
$game_temp.select_equip = true
$scene = Scene_Item.new

variable 001 and 002 save the selected item's number and type.
You can use them in your enchanter NPC event.
Your event will act weird since we're opening the menu, so follow my instructions carefully:
use 2 pages in your NPC event. 
page 1 :
- pull self-switch A ON,
- the script command
page 2 :
condition = 'switch A ON'.
- if variable 002 == 1 (the player selected a weapon)
if variable 001 = 1
text: you selected Bronze Sword
enchant the bronze sword.
if variable 001 = 2
text: you selected Iron Sword
enchant the iron sword.
if variable 001 = 3
text: you selected Mythril Sword
enchant the mythril sword.
...
else
text: that is not a weapon !
end
 

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