The RPG Maker Resource Kit

RMRK RPG Maker Creation => VX Ace => VXA Scripts Database => Topic started by: modern algebra on September 22, 2012, 11:08:02 PM

Title: [VXA] Individual Strikes when Dual Wielding
Post by: modern algebra on September 22, 2012, 11:08:02 PM
Individual Strikes when Dual Wielding
Version: 1.0.1
Author: modern algebra
Date: 2 February 2013

Version History



Description


This script changes the dual wielding option so that, instead of the actor attacking only once with increased damage, the actor attacks twice, once with each weapon. Additionally, this script allows you to modify the damage formula when dual wielding, thus allowing you to, for instance, make the actor's proficiency with dual wielding dependent on the actor's dexterity or some other stat.

Features


Instructions

Paste the script into its own slot in the Script Editor, above Main but below Materials.

If you wish, you can assign a modifying formula at line 38. What that will do is allow you to change the damage formula for a weapon when you are dual wielding, and it serves as a way to assign a penalty to dual wielding for balance purposes.

Script


Code: [Select]
#==============================================================================
#    Individual Strikes when Dual Wielding
#    Version: 1.0.1
#    Author: modern algebra (rmrk.net)
#    Date: 2 February 2013
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Description:
#   
#    This script changes the dual wielding option so that, instead of the actor
#   attacking only once with increased damage, the actor attacks twice, once
#   with each weapon. Additionally, this script allows you to modify the
#   damage formula when dual wielding, thus allowing you to, for instance, make
#   the actor's proficiency with dual wielding dependent on the actor's
#   dexterity or some other stat.
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Instructions:
#   
#    Paste this script into its own slot in the Script Editor, above Main but
#   below Materials.
#
#    If you wish, you can assign a modifying formula at line 38. What that will
#   do is allow you to change the damage formula for a weapon when you are dual
#   wielding, and it serves as a way to assign a penalty to dual wielding for
#   balance purposes.
#==============================================================================

$imported ||= {}
$imported[:MA_DWIndividualStrikes] = true

#\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
#  BEGIN Editable Region
#||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
#  By modifying this constant, you are able to modify the damage formula when
# dual wielding. It must be a string, and the original damage formula will
# replace the %s. In other words, if the original damage formula is something
# like "a.atk * 4 - b.def * 2", and you assign the constant to the following:
#    MAISDW_DUAL_DAMAGE_MODIFIER = "(%s)*0.75"
# then the formula when dual wielding would be: "(a.atk * 4 - b.def * 2)*0.75"
MAISDW_DUAL_DAMAGE_MODIFIER = "(%s)"
#||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
#  END Editable Region
#//////////////////////////////////////////////////////////////////////////////

#==============================================================================
# ** Scene_Battle
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Summary of Changes:
#    aliased method - apply_item_effects
#==============================================================================

class Scene_Battle
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Apply Skill/Item Effect
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  alias maisdw_aplyitm_2uv7 apply_item_effects
  def apply_item_effects(target, item, *args)
    # If Actor attacking with more than one weapon
    if @subject.actor? && !item.is_a?(RPG::Item) &&
      item.id == @subject.attack_skill_id && @subject.weapons.size > 1
      @subject.weapons.each { |weapon|
        maisdw_dual_wield_attack(target, item, weapon, *args) }
    else
      maisdw_aplyitm_2uv7(target, item, *args) # Call original method
    end
  end
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Dual Wield Attack
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  def maisdw_dual_wield_attack(target, item, weapon, *args)
    #  Select from equips to record position, accounting for extra equip
    # scripts that might change order.
    equips_to_replace = [] # Record which equips are removed
    selected = false
    for i in 0...@subject.equips.size
      equip = @subject.equips[i]
      if equip.is_a?(RPG::Weapon)
        # Actual identity in case using an instantiated item system
        if weapon.equal?(equip) && !selected
          selected = true # Only keep it once if two of the same item
          next
        end
        equips_to_replace << [i, equip] # Preserve weapon
        @subject.change_equip(i, nil)   # Remove weapon
      end
    end
    # Get the attack skill
    attack_skill = $data_skills[@subject.attack_skill_id]
    attack_skill = item if attack_skill.nil?
    real_formula = attack_skill.damage.formula.dup # Preserve Formula
    # Modify damage formula
    unless MAISDW_DUAL_DAMAGE_MODIFIER.empty?
      attack_skill.damage.formula = sprintf(MAISDW_DUAL_DAMAGE_MODIFIER, real_formula)
    end
    # Call original apply_item_effects method
    maisdw_aplyitm_2uv7(target, attack_skill, *args)
    attack_skill.damage.formula = real_formula # Restore damage formula
    # Replace removed equips
    equips_to_replace.each { |i, weapon| @subject.change_equip(i, weapon) }
  end
end

If you're using Internet Explorer, then code boxes do not play nice. You might need to retrieve the script from Pastebin (http://pastebin.com/KbpU2a48) instead.

Credit



Thanks


Support


Please post in this topic at RMRK for support.

Known Compatibility Issues

I am not currently aware of any compatibility issues.

SiliconDragon reports (http://rmrk.net/index.php?action=profile;u=18250) that it appears to work well with Kread-EX's Custom Weapon Formulas (http://grimoirecastle.wordpress.com/2011/12/13/custom-weapon-formulas/), but that the expected damage is mildly reduced.

Author's Notes


I wrote this script basically to complement my Weapon Damage Formulas (http://rmrk.net/index.php/topic,46809.0.html) script since the default dual wielding scheme did not accomodate for a situation where the two weapons have different formulas.

Terms of Use


I adopt RMRK's default Terms of Use (http://rmrk.net/index.php/topic,45481.0.html).
Title: Re: Individual Strikes when Dual Wielding
Post by: Wiimeiser on September 24, 2012, 12:33:42 PM
How would Yanfly's Weapon Attack Replace work with this? Would it use both attack skills as set on both weapons?
Title: Re: Individual Strikes when Dual Wielding
Post by: modern algebra on September 24, 2012, 08:12:37 PM
Well, I've never looked at that script before, but judging by its name, I assume it is essentially like my Weapon Damage Formula (http://rmrk.net/index.php/topic,46809.0.html) script? If so and if it is similarly designed, then yes. Why not try it out and get back to me if you discover it doesn't work?
Title: Re: Individual Strikes when Dual Wielding
Post by: Wiimeiser on September 25, 2012, 01:30:36 AM
All Yanfly's script seems to be doing is stopping yours from working correctly, though it's hard to tell using the default battle system. It just displays one attack, simply says "(name) attacks!"; but giving one weapon an attack that merely poisons without fail and an attack that merely blinds without fail(both with 1000% chance) has them both work.
Title: Re: Individual Strikes when Dual Wielding
Post by: modern algebra on September 25, 2012, 01:39:01 AM
That sounds fine? What should happen is that it should say:

"(name) attacks"
"x damage dealt"

And then "x damage dealt" should be replaced with the damage of the second weapon.

I assume that both animations are shown?
Title: Re: Individual Strikes when Dual Wielding
Post by: Wiimeiser on September 25, 2012, 02:16:57 AM
Both animations seem to be shown, the second one appears mirrored which I believe is normal
Title: Re: Individual Strikes when Dual Wielding
Post by: modern algebra on September 25, 2012, 02:44:57 AM
Yeah, then I think it's working as intended. Is there a problem with the way it executes?
Title: Re: Individual Strikes when Dual Wielding
Post by: Wiimeiser on September 25, 2012, 09:26:10 AM
Not as far as I can tell. I didn't test it too extensively, not every single possible combination, but I couldn't see anything wrong, just the "(name) attacks!" only appearing once.
Title: Re: Individual Strikes when Dual Wielding
Post by: modern algebra on September 25, 2012, 10:39:53 AM
Alright, then I think that's fine. It's only supposed to show "(name) attacks" once.
Title: Re: Individual Strikes when Dual Wielding
Post by: SiliconDragon on September 28, 2012, 10:33:29 PM
Will this script use the damage formulas of both weapons if they have custom formulas using this script: http://grimoirecastle.wordpress.com/2011/12/13/custom-weapon-formulas/ (http://grimoirecastle.wordpress.com/2011/12/13/custom-weapon-formulas/) by Kread-Ex?
Title: Re: Individual Strikes when Dual Wielding
Post by: modern algebra on September 28, 2012, 10:59:20 PM
Hmm, my guess is yes. Why not try it out and see?
Title: Re: Individual Strikes when Dual Wielding
Post by: SiliconDragon on September 29, 2012, 03:35:40 PM
Just tried it out and it seems to be working, except it subtracts one from the damage of each weapon, and the off hand weapon seems to never miss.  I need to test the off hand weapon more, but in three battles of ten to twenty rounds it never missed, though the main weapon did about half the time.
Title: Re: Individual Strikes when Dual Wielding
Post by: modern algebra on September 29, 2012, 05:26:11 PM
Well, the lessened damage might be because this script unequips the non-attacking weapon for each attack, in order that the stats of the non-attacking weapon don't affect the damage of the attacking one.

As for the off-hand weapon not missing, err, don't know? Nothing in this script should affect hit rate.
Title: Re: Individual Strikes when Dual Wielding
Post by: SiliconDragon on September 30, 2012, 09:25:35 PM
Thanks, unequipping a weapon shouldn't have changed the damage because I used an set damage of 10 for main weapon, and 5 for off-hand weapon, no stats or anything else effecting it so I could see if I was getting expected values.
Title: Re: Individual Strikes when Dual Wielding
Post by: modern algebra on September 30, 2012, 09:34:44 PM
And the damage formula for the skills you are using is purely just actor.atk? It doesn't subtract from the opponent's defence, it has no variance, etc.?

Anyway, are you asking me to do something? If so, then please clarify, and also create a new project with both scripts in it and recreate the error, then upload it to me so I can see what's going on.
Title: Re: Individual Strikes when Dual Wielding
Post by: Watfordj on September 30, 2012, 09:44:26 PM
can you make it where you can select the hand you attack with?
Title: Re: Individual Strikes when Dual Wielding
Post by: modern algebra on September 30, 2012, 09:46:44 PM
Not with this script, no. You always attack with both.

It would be possible to add that option, but I don't intend to write that.
Title: Re: Individual Strikes when Dual Wielding
Post by: SiliconDragon on October 03, 2012, 09:13:47 PM
@modern algebra, no there is no request I just others trying use both scripts would like to know how they worked together, and to test them I just placed 10 in the main hand formula and 5 in the off hand weapon formula so I knew exactly what the damage was supposed to be, in actual game the formulas will be a bit more complex.
Title: Re: Individual Strikes when Dual Wielding
Post by: modern algebra on October 03, 2012, 09:20:34 PM
Alright, thank you for doing that. It is very helpful for those other users and I will add that information to the initial post.
Title: Re: [VXA] Individual Strikes when Dual Wielding
Post by: Ven01273 on February 03, 2013, 01:49:55 AM
There seems to be a bug in your script.
When using a healing item with dual wielding character, such as a potion, instead of healing it damages.
Title: Re: [VXA] Individual Strikes when Dual Wielding
Post by: modern algebra on February 03, 2013, 02:29:16 AM
Thank you for reporting that bug! I've updated the script to v. 1.0.1 to fix it.