RMRK is retiring.
Registration is disabled. The site will remain online, but eventually become a read-only archive. More information.

RMRK.net has nothing to do with Blockchains, Cryptocurrency or NFTs. We have been around since the early 2000s, but there is a new group using the RMRK name that deals with those things. We have nothing to do with them.
NFTs are a scam, and if somebody is trying to persuade you to buy or invest in crypto/blockchain/NFT content, please turn them down and save your money. See this video for more information.
Dual Wield Fix by Lytanathan

0 Members and 1 Guest are viewing this topic.

**
Rep:
Level 82
Living proof that paradoxes exist in reality.
Dual Wield Fix
Author: Lytanathan
Version:1.0
Date: June 30, 2011

Description


If you're like me, you may want your dual-wielding characters to be able to use shields. Now, one COULD make shields out of weapons, but then everyone would have to be dual-wielders to use them. This script makes that unnecessary, by allowing a character to equip either a weapon OR a shield in their second hand. (Main hand is still restricted to weapons only)

Features

  • Allows dual-wielding characters to hold shields.

Instructions

Cut and paste into script editor. No other setup is necessary.

Script


Code: [Select]
#==============================================================================
#+-----------------------------------------------------------------------------
#| *** Dual Wield Fix by Lytanathan
#+-----------------------------------------------------------------------------
#|  If you're like me, you may want your dual-wielding characters to have the
#| option of equipping shields. Now, you COULD make shields out of weapons, but
#| then ALL of your characters would have to be able to dual-wield to use them.
#|
#|  This script allows a dual-wielding character to hold a weapon OR a shield
#| in their offhand. Note that shields still cannot be equipped in the first
#| weapon slot.
#|
#|  Compatability issues may arise with other scripts that change the equip
#| system. You may also encounter issues with custom menu systems that modify
#| the equip menu, as I had to slightly modify Window_EquipItem.
#+-----------------------------------------------------------------------------
#|  For those who are interested, this is how the script works:
#| When a weapon is equipped in the second hand slot, @armor1_id is assigned
#| the ID of the weapon, as the original script worked. However, when a shield
#| is equipped, @armor1_id becomes the ID of the shield PLUS 1000.
#|  Thus, any code that references @armor1_id first must check whether it is
#| over or under 1000. Under, and the item is a weapon, over, it is a shield.
#+-----------------------------------------------------------------------------
#|  Anyone may use and modify this script as much as they please. I honestly
#| don't even care if you credit me, just don't outright claim it as your own.
#|  If you modify it in such a way that it works better, please tell me. I'm
#| not the best scripter, and always looking for ways to improve. It took a lot
#| of tweaking here and there to make it work properly, and I imagine there are
#| a lot of areas that could have been done simpler.
#+-----------------------------------------------------------------------------
#==============================================================================

#==============================================================================
# ** Game_Actor
#------------------------------------------------------------------------------
#  This class handles actors. It's used within the Game_Actors class
# ($game_actors) and referenced by the Game_Party class ($game_party).
#==============================================================================

class Game_Actor < Game_Battler
  #--------------------------------------------------------------------------
  # * Get Weapon Object Array
  #--------------------------------------------------------------------------
  def weapons
    result = []
    result.push($data_weapons[@weapon_id])
    if (two_swords_style and @armor1_id < 1000)
      result.push($data_weapons[@armor1_id])
    end
    return result
  end
  #--------------------------------------------------------------------------
  # * Get Armor Object Array
  #--------------------------------------------------------------------------
  def armors
    result = []
    if not two_swords_style and @armor1_id < 1000
      @armor1_id += 1000
    end
    if @armor1_id >= 1000
      result.push($data_armors[@armor1_id - 1000])
    end
    result.push($data_armors[@armor2_id])
    result.push($data_armors[@armor3_id])
    result.push($data_armors[@armor4_id])
    return result
  end
  #--------------------------------------------------------------------------
  # * Change Equipment (designate ID)
  #     equip_type : Equip region (0..4)
  #     item_id    : Weapon ID or armor ID
  #     test       : Test flag (for battle test or temporary equipment)
  #    Used by event commands or battle test preparation.
  #--------------------------------------------------------------------------
  def change_equip_by_id(equip_type, item_id, test = false)
    if equip_type == 0 or (equip_type == 1 and two_swords_style and item_id < 1000)
      change_equip(equip_type, $data_weapons[item_id], test)
    elsif (equip_type == 1 and item_id > 1000)
      change_equip(equip_type, $data_armors[item_id - 1000], test)
    else
      change_equip(equip_type, $data_armors[item_id], test)
    end
  end
  #--------------------------------------------------------------------------
  # * Change Equipment (designate object)
  #     equip_type : Equip region (0..4)
  #     item       : Weapon or armor (nil is used to unequip)
  #     test       : Test flag (for battle test or temporary equipment)
  #--------------------------------------------------------------------------
  def change_equip(equip_type, item, test = false)
    last_item = equips[equip_type]
    unless test
      return if $game_party.item_number(item) == 0 if item != nil
      $game_party.gain_item(last_item, 1)
      $game_party.lose_item(item, 1)
    end
    item_id = item == nil ? 0 : item.id
    case equip_type
    when 0  # Weapon
      @weapon_id = item_id
      unless two_hands_legal?             # If two hands is not allowed
        change_equip(1, nil, test)        # Unequip from other hand
      end
    when 1  # Shield
      if item.is_a?(RPG::Weapon)
        @armor1_id = item_id
      elsif item.is_a?(RPG::Armor)
        @armor1_id = item_id + 1000
      else
        @armor1_id = 0
      end
      unless two_hands_legal?             # If two hands is not allowed
        change_equip(0, nil, test)        # Unequip from other hand
      end
    when 2  # Head
      @armor2_id = item_id
    when 3  # Body
      @armor3_id = item_id
    when 4  # Accessory
      @armor4_id = item_id
    end
  end
  #--------------------------------------------------------------------------
  # * Discard Equipment
  #     item : Weapon or armor to be discarded.
  #    Used when the "Include Equipment" option is enabled.
  #--------------------------------------------------------------------------
  def discard_equip(item)
    if item.is_a?(RPG::Weapon)
      if @weapon_id == item.id
        @weapon_id = 0
      elsif two_swords_style and @armor1_id == item.id
        @armor1_id = 0
      end
    elsif item.is_a?(RPG::Armor)
      if @armor1_id - 1000 == item.id
        @armor1_id = 0
      elsif @armor2_id == item.id
        @armor2_id = 0
      elsif @armor3_id == item.id
        @armor3_id = 0
      elsif @armor4_id == item.id
        @armor4_id = 0
      end
    end
  end
  #--------------------------------------------------------------------------
  # * Determine if Equippable
  #     item : item
  #--------------------------------------------------------------------------
  def equippable?(item)
    if item.is_a?(RPG::Weapon)
      return self.class.weapon_set.include?(item.id)
    elsif item.is_a?(RPG::Armor)
      return self.class.armor_set.include?(item.id)
    end
    return false
  end
end

#==============================================================================
# ** Window_EquipItem
#------------------------------------------------------------------------------
#  This window displays choices when opting to change equipment on the
# equipment screen.
#==============================================================================

class Window_EquipItem < Window_Item
  #--------------------------------------------------------------------------
  # * Object Initialization
  #     x          : sindow X coordinate
  #     y          : sindow Y corrdinate
  #     width      : sindow width
  #     height     : sindow height
  #     actor      : actor
  #     equip_type : equip region (0-4)
  #--------------------------------------------------------------------------
  def initialize(x, y, width, height, actor, equip_type)
    @actor = actor
    @equip_type = equip_type
    super(x, y, width, height)
  end
  #--------------------------------------------------------------------------
  # * Whether to include item in list
  #     item : item
  #--------------------------------------------------------------------------
  def include?(item)
    return true if item == nil
    if @equip_type == 0
      return false unless item.is_a?(RPG::Weapon)
    else
      if item.is_a?(RPG::Armor)
        return false unless (item.kind == @equip_type - 1)
      elsif item.is_a?(RPG::Weapon)
        return false unless (@actor.two_swords_style and (@equip_type == 1))
      end
    end
    return @actor.equippable?(item)
  end
end


Credit


  • Lytanathan
  • Enterbrain I guess, as I mostly just modified the default scripts.

Support


If it doesn't work in your project, probably because of a compatability issue, I will likely be unable to help. It took me a lot of tweaking just to get it working in the first place, as I'm not a terribly good scripter.

Known Compatibility Issues

Will probably not work with scripts that change the equip system, at least not without modifications of some kind.
May also encounter issues with scripts that change the default equip menu.
Demo


I don't think a demo is necessary here.

Restrictions

I don't really care how or what you use this script for. I don't even care if you credit me as the creator, just don't claim it as your own please.

*
Rep:
Level 97
2014 Most Unsung Member2014 Best RPG Maker User - Engine2013 Best RPG Maker User (Scripting)2012 Most Mature Member2012 Favorite Staff Member2012 Best RPG Maker User (Scripting)2012 Best MemberSecret Santa 2012 ParticipantProject of the Month winner for July 20092011 Best Use of Avatar and Signature Space2011 Best RPG Maker User (Scripting)2011 Most Mature Member2011 Favourite Staff Member2011 Best Veteran2010 Most Mature Member2010 Favourite Staff Member
I always thought that was weird - nice idea for a script! Thanks for sharing.