Weapon Damage

Help spread the word!Share on FacebookShare on TumblrTweet about this on TwitterShare on Google+Share on LinkedInShare on RedditFlattr the author

(日本語の説明はこちらです)

weaponDamage1

In RPG Maker, weapons can be equipped to actors.
You can also equip them to enemies if you use plugins like Enemy Equips.

Weapons can provide parameter bonuses like extra atk and agi, but you can’t specify a damage value for the weapons themselves.

For example, if you wanted to have the normal attack skill’s damage value to be equal to the amount of damage dealt by the weapon, you would be unable to say this directly.

You could say that the “atk” bonus from the weapon represents how much damage the weapon can do, but if you were to reference the actor’s atk, you would be including any additional atk bonuses that aren’t part of the weapon.

This plugin allows you to define weapon damage formulas, which can be used in your skill formulas if necessary.

By separating the weapon damage from your atk, you have more control over how your want your skills to be set up!

Download

Plugin: download here (right-click, save-as)

Installation

Download the plugin and place it in the “plugins” folder in your project’s “js” folder. Then open your Plugin Manager (F10), double-click an empty row, and select the HIME_WeaponDamage plugin.

Once it is in your list of plugins, turn the plugin on.

Usage

To define a damage formula for you weapons, note-tag them with

<weapon damage>
  FORMULA
</weapon damage>

For example, let’s say you wanted your weapon’s damage to be between 2 and 16.You could write

2 * (Math.randomInt(8) + 1)

Note that we add 1 because randomInt picks a number between 0 and the value you provided.

For those that are familiar, this is equivalent to 2d8.

So if you wanted to write something like 1d6 + 4, you would write

(1 * (Math.randomInt(6) + 1)) + 4

For now, weapon damages are assumed to be simple.

Using Weapon Damage

Weapon damage formulas are not automatically included in your skill damage calculations, because you may not want to consider the weapon.

For example, if you’re casting a spell and you’re holding a sword, would you include the sword damage in the spell damage? Maybe, maybe not.

To use the weapon damage formula, in your skill formula, you can write

a.weaponDamage(b)

Which will return how much damage the attacker’s weapons dealt, based on the formula that you defined earlier. This value includes all weapons, so if the attacker is holding two weapons or three weapons or more, they will all be included in this total, which you can then use as part of the skill.

So let’s say your normal attack was equal to your weapon’s damage.
You would write

a.weaponDamage(b)

But let’s say you wanted to add a bonus for having extra “atk” power, which could represent your physical strength. You might say

a.weaponDamage(b) + a.atk / 10

Which adds 1 point of damage per 10 points in atk.
The weapon itself may provide atk bonus as well, but it is not necessary.

Bare Hands

Now, what happens when you don’t have a weapon? If no weapon is held, weapon damage is assumed to be “bare-hands” damage. Enemies by default are assumed to be bare-handed.

Bare-hands is set up as a weapon in your database. You don’t need to actually hold this in order to use the damage formula, but you could if you wanted to.

In the plugin manager, choose the ID of the weapon that will represent bare-hands, and then set up the weapon damage formulas usual.

weaponDamage2

This damage formula will be used as the weapon damage.

Help spread the word!Share on FacebookShare on TumblrTweet about this on TwitterShare on Google+Share on LinkedInShare on RedditFlattr the author

You may also like...

65 Responses

  1. Bishoujo Helper says:

    Skeezix and Nol mentioned this earlier, but I wanted to ping it again because it gets to the heart of why I’ll have to figure out my own way to implement this kind of plugin: rolling multiple dice is not easily supported, and perhaps misunderstood. In the very top image for the plugin, at least as shown now, “2d6+5” in the Description box is supposed to equate to “2 * (Math.randomInt(6) + 1) + 5”, but that’s rolling a single d6 and doubling it, not rolling two dice independently. Later, the Usage example repeats the error, but while you could argue that 2*(1d8) does give the same range as 2d8, it’s not the same distribution of totals, i.e. how would you get a 15 total? “(Math.randomInt(8) + 1) + (Math.randomInt(8) + 1)” is really “is equivalent to 2d8”.

    Anyway, I’m planning on getting this plugin, then seeing if I can create my own overlay (or something, never done it before) to process strings like “2d6+5” and generate the independent die rolls needed. This is for a project converting a scenario from the Bard’s Tale Construction Set, which used weapon damage die rolls and a D&D-like combat system. The need is there, because there’s weapons that do up to “32d100”, and trying to manage 32 “Math.randomInt(100)+1” in a row manually is just ludicrous.

    • Hime says:

      You're right, the screenshot does not accurately represent what the description says. You could write an add-on that will parse damage strings as needed. Alternatively, you might define a helper method d that takes two numbers or something like

      d(2,6) + 5

      Where the first number represents how many rolls, and the second represents the number of sides. And then function d would be something like this (it could probably be written more compactly but I'll just go with a simple example)

      function d(times, sides) {
         var total = 0;
         for (var i = 0; i < times; i++) {
            total += Math.randomInt(sides) + 1
         }
         return total;
      }
      

      Then you could say things like

      d(32, 100)

      Which doesn't look as nice, but at least it would be logically correct.

      • Bishoujo Helper says:

        I’ve come up with some code that could be integrated into your plugin, if that’s OK. This would go just after the “if (res) {” line:

        var diceRegex = /\s*(\d+)[dD](\d+)/m;
        var diceRes = diceRegex.exec(res[1]);
        var numDice, numSides, diceTotal, i;
        while (diceRes) {
        numDice = diceRes[1];
        numSides = diceRes[2];
        diceTotal = 0;
        for (i = 0; i < numDice; i++) {
        diceTotal += Math.floor(Math.random() * numSides) + 1;
        }
        res[1] = res[1].replace(diceRegex, diceTotal.toString());
        diceRes = diceRegex.exec(res[1]);
        }

        but it does raise the question that Forteller (I think) asked: in testing, it looks like this is calculated only once on creation, not every time you use it!
        Which makes any random element in the formula, or dependence on a variable statistic, useless.

  2. Forteller says:

    hmm anyway just have the weapon damage calculated on creation and not dynamically, so that if i make the weapon damage (a.level3+4)(1+a.atk/5*.10), the damage wouldnt scale as i leveled up

  3. PYR games says:

    One of your examples is wrong.

    You wrote
    ‘a.weaponDamage(b) * a.atk / 10’

    and simplified it as adding an extra point of damage per 10 ATK, but really that would add 10% damage per point in ATK, and only if that character had over 10 ATK.

  4. Skeezixs says:

    Just a quick question, if you have 2 * (Math.randomInt(8) + 1) does this work like 1d8 + 1d8 or is it 1d8 * 2?
    Would i need to set it to something like below, or is there another way?
    $gameVariable.variable[10] === 2, if $gameVariable.variable[10] >= 1, (Math.randomInt(8) + 1), $gameVariable.variable[10] — i

    • Nol says:

      it multiplies the 1d8 result by two.
      I added multiple itterations of (Math.randomInt(8) + 1) + (Math.randomInt(8) + 1) to obtain a 2d8

  5. Nol says:

    Hello !
    As everyone before, let me thank you for this plugin, which simplifiies my life a lot !
    The formula works fine, ….

    Except…. that my ennemies use the same as my actor

    If i give a (2 * (Math.randomInt(6) + 1))</weapon damage> Sword to my lone actor, my bat encounter ends up hitting exaclty as hard, when they should do à fixed “a.weaponDamage(b) + (a.atk-10)*0.5”
    (since they have no weapons…)
    Is the a.weaponDamage always using my actor’s ? have i missed something ?

    I might try to set up a second actor, see if it adds ALL the weapons ^^

  6. Anonymous says:

    First off, awesome plugin, ive been looking for something like this for a while now!

    Is it possible to do this?

    EX: Sword attack will be determined by actors atk times 3

    • Hime says:

      Yes. Weapon damage formulas have access to the user and the target. If you look at how the skill damage formula is written, you write

      a.weaponDamage(b)
      

      This means that a is the user, and b is the target. Consequently, a and b are now available to use in the formula. So if you wanted the damage of the weapon to factor in the user’s attack (or anything else that may be related to the user or target). So you could say

      a.atk * 3
      

      And so the weapon damage will be equal to the user’s attack, multiplied by 3.

  7. Dago says:

    I always get 0 value for damage, my setup are copy-pasted from a post from here and it doesnt work, here`s my log;

    SyntaxError: Unexpected token ILLEGAL
    at Game_Actor.Game_Battler.evalWeaponDamage (file:///C:/Users/Administrator/Documents/Games/Projeto/js/plugins/HIME_WeaponDamage.js:160:23)
    at Game_Actor.Game_Battler.weaponDamage (file:///C:/Users/Administrator/Documents/Games/Projeto/js/plugins/HIME_WeaponDamage.js:174:23)
    at Game_Action.eval (eval at (file:///C:/Users/Administrator/Documents/Games/Projeto/js/plugins/mv_damage_formula_debug.js:11:46), :1:3)
    at Game_Action.evalDamageFormula (file:///C:/Users/Administrator/Documents/Games/Projeto/js/plugins/mv_damage_formula_debug.js:11:30)
    at Game_Action.makeDamageValue (file:///C:/Users/Administrator/Documents/Games/Projeto/js/plugins/YEP_DamageCore.js:1218:27)
    at Game_Action.makeDamageValue (file:///C:/Users/Administrator/Documents/Games/Projeto/js/plugins/YEP_X_SelectionControl.js:977:44)
    at Game_Action.makeDamageValue (file:///C:/Users/Administrator/Documents/Games/Projeto/js/plugins/YEP_Debugger.js:426:54)
    at Game_Action.apply (file:///C:/Users/Administrator/Documents/Games/Projeto/js/rpg_objects.js:1656:30)
    at Game_Action.apply (file:///C:/Users/Administrator/Documents/Games/Projeto/js/plugins/YEP_BattleEngineCore.js:3096:34)
    at Game_Action.apply (file:///C:/Users/Administrator/Documents/Games/Projeto/js/plugins/YEP_BattleAICore.js:701:37)

    I deactivated a bunch of scripts, but more errors keep popping up every time i try again.

  8. Kerykeion says:

    I’d like to add weapon damage using YEP Item Upgrade Slots. If I give my base item 5 slots and a flat 5 weapon damage, I’d like to be able to upgrade it 5 times to “Base Item”+5 and add 5 more weapon damage.

    Any help would be appreciated!

    • Hime says:

      You should consult the instructions for yanfly’s plugin to see how to check how many upgrades have been done, and then include that in the weapon damage formula.

  9. jbt1234 says:

    From what I understand of the instructions, would I put this in the weapon tag:
    1 * (Math.randomInt(6) + 1)

    And this in the skill take to add a D&D style proficiency bonus:
    a.weaponDamage(b) + ((a.atk – 10) * 0.5)

    So this would separately add the proficiency bonus to the normal attack skill, rather than on the weapon itself?

  10. AngryAragami says:

    Hi Hime, is there a way to duplicate the effect of this script with your VX Ace scripts? There a number of reasons I want to build my project in VX Ace, but I need weapon specific damage like the script provides.

  11. Tevak says:

    Hi Hime, is there a way to give enemies weapon damage without using the equip slots core and enemy equips plugin?

  12. ODevil says:

    Is it possible to make armor increase weapon damage as well?

    • Hime says:

      Is the bonus based on the weapon checking what you’re wearing?

      • ODevil says:

        No, It would have been a flat increase to damage.
        In this scenario the weapon is a laser gun (dual-wield) and the armor being an energy core that increases the damage of energy damage.
        I’m fairly new to RM so I might not have fully understood what you just said though ._.

        • Hime says:

          You can use a formula to check whether that armor is equipped. How that condition is written will depend on what plugins you might have installed, but assuming you don’t have any special plugins that changes the way equips are handled, you could say

          if (a.armors().contains($dataArmors[14])) {
             110
          }
          else {
             10
          }
          

          This means that if armor 14 is equipped, the weapon will deal 100 damage. Otherwise, it will deal 10 damage.

          What this logic means is having that specific armor equipped will give the weapon a damage bonus.

  13. Podglu says:

    Is there a way to change the Damage Formula of a weapon mid-game, like an item with Damage+1 property on the equipped weapon ?

    • Hime says:

      That would depend on how the bonuses are implemented, and consequently, how you would check what bonuses you have.
      What are you using to add the Damage+1 property?

      • Podglu says:

        First, I thought to use an item with YEP’s Attachable Augments, but i don’t think this would work, so is this possible to use an Item on a character and his equipped weapon have +1 in its weapon damage ? A bit like the Monogrinder in Phantasy Star Online on Gamecube.

        • Hime says:

          Do you mean that each character will have a “weapon bonus” property, and then all weapons that are equipped will have that bonus?
          So if you gave the character an item that gives +2 bonus, and then another item that gives +3 bonus, that character will effectively have +5 bonus to all weapons?

  14. Dragon3025 says:

    I set up the basic attack skill to a.weaponDamage() then I added this in my weapon’s note:

    a.atk * 4 – b.def * 2
    </weapon damage>
    I tried attacking using the skill with the weapon equipped, but the damage was 0. The character has 26 atk total and the enemy has 30 defense. I tried this with just this plugin activated and I still get 0 damage.

    • Dragon3025 says:

      Weird, my note tag cut off, this is what I added in my weapon’s note:

      a.atk * 4 – b.def * 2
      </weapon damage>

      • Dragon3025 says:

        I’d edit my comments if I could. Basically the weapon has:
        (less_than_sign)weapon damage(greater_than_sign)
        a.atk * 4 – b.def * 2
        </weapon damage>

    • Hime says:

      Add this plugin to help debug the issue

      https://gist.github.com/HimeWorks/428d2357c7751f1438da2a760bfa2980

      Open the console (F8) and then execute the skill. See if there’s any messages.

      • Dragon3025 says:

        Okay, I used it and got this log:

        mv_damage_formula_debug.js:15 ReferenceError: b is not defined
        at Game_Actor.eval (eval at (file:///C:/Users/cntdr/Game%20Making/RPG%20Making/RPG%20MV/Projects/Legends%20of%20Asteria/js/plugins/HIME_WeaponDamage.js:160:23), :2:13)
        at Game_Actor.Game_Battler.evalWeaponDamage (file:///C:/Users/cntdr/Game%20Making/RPG%20Making/RPG%20MV/Projects/Legends%20of%20Asteria/js/plugins/HIME_WeaponDamage.js:160:12)
        at Game_Actor.Game_Battler.weaponDamage (file:///C:/Users/cntdr/Game%20Making/RPG%20Making/RPG%20MV/Projects/Legends%20of%20Asteria/js/plugins/HIME_WeaponDamage.js:174:23)
        at Game_Action.eval (eval at (file:///C:/Users/cntdr/Game%20Making/RPG%20Making/RPG%20MV/Projects/Legends%20of%20Asteria/js/plugins/mv_damage_formula_debug.js:11:46), :1:3)
        at Game_Action.evalDamageFormula (file:///C:/Users/cntdr/Game%20Making/RPG%20Making/RPG%20MV/Projects/Legends%20of%20Asteria/js/plugins/mv_damage_formula_debug.js:11:30)
        at Game_Action.makeDamageValue (file:///C:/Users/cntdr/Game%20Making/RPG%20Making/RPG%20MV/Projects/Legends%20of%20Asteria/js/rpg_objects.js:1668:26)
        at Game_Action.apply (file:///C:/Users/cntdr/Game%20Making/RPG%20Making/RPG%20MV/Projects/Legends%20of%20Asteria/js/rpg_objects.js:1656:30)
        at Function.BattleManager.invokeNormalAction (file:///C:/Users/cntdr/Game%20Making/RPG%20Making/RPG%20MV/Projects/Legends%20of%20Asteria/js/rpg_managers.js:2297:18)
        at Function.BattleManager.invokeAction (file:///C:/Users/cntdr/Game%20Making/RPG%20Making/RPG%20MV/Projects/Legends%20of%20Asteria/js/rpg_managers.js:2288:14)
        at Function.BattleManager.updateAction (file:///C:/Users/cntdr/Game%20Making/RPG%20Making/RPG%20MV/Projects/Legends%20of%20Asteria/js/rpg_managers.js:2270:14)

        • Hime says:

          I’ve updated the plugin. Previously, weapon damage formulas didn’t support the b variable.
          I’ve changed it so that you have to say this:
          a.weaponDamage(b)
          And then in your weapon damage formula, b will represent the target specified above.

          • Dragon3025 says:

            The newest update is 1.2? I updated the plugin with the download link on this page, then put a.weaponDamage(b), and still got 0 damage. This is the log I got:

            ReferenceError: b is not defined
            at Game_Actor.eval (eval at (file:///C:/Users/cntdr/Game%20Making/RPG%20Making/RPG%20MV/Projects/Legends%20of%20Asteria/js/plugins/HIME_WeaponDamage.js:160:23), :2:13)
            at Game_Actor.Game_Battler.evalWeaponDamage (file:///C:/Users/cntdr/Game%20Making/RPG%20Making/RPG%20MV/Projects/Legends%20of%20Asteria/js/plugins/HIME_WeaponDamage.js:160:12)
            at Game_Actor.Game_Battler.weaponDamage (file:///C:/Users/cntdr/Game%20Making/RPG%20Making/RPG%20MV/Projects/Legends%20of%20Asteria/js/plugins/HIME_WeaponDamage.js:174:23)
            at Game_Action.eval (eval at (file:///C:/Users/cntdr/Game%20Making/RPG%20Making/RPG%20MV/Projects/Legends%20of%20Asteria/js/plugins/mv_damage_formula_debug.js:11:46), :1:3)
            at Game_Action.evalDamageFormula (file:///C:/Users/cntdr/Game%20Making/RPG%20Making/RPG%20MV/Projects/Legends%20of%20Asteria/js/plugins/mv_damage_formula_debug.js:11:30)
            at Game_Action.makeDamageValue (file:///C:/Users/cntdr/Game%20Making/RPG%20Making/RPG%20MV/Projects/Legends%20of%20Asteria/js/rpg_objects.js:1668:26)
            at Game_Action.apply (file:///C:/Users/cntdr/Game%20Making/RPG%20Making/RPG%20MV/Projects/Legends%20of%20Asteria/js/rpg_objects.js:1656:30)
            at Function.BattleManager.invokeNormalAction (file:///C:/Users/cntdr/Game%20Making/RPG%20Making/RPG%20MV/Projects/Legends%20of%20Asteria/js/rpg_managers.js:2297:18)
            at Function.BattleManager.invokeAction (file:///C:/Users/cntdr/Game%20Making/RPG%20Making/RPG%20MV/Projects/Legends%20of%20Asteria/js/rpg_managers.js:2288:14)
            at Function.BattleManager.updateAction (file:///C:/Users/cntdr/Game%20Making/RPG%20Making/RPG%20MV/Projects/Legends%20of%20Asteria/js/rpg_managers.js:2270:14)

          • Hime says:

            1.3 is the latest version. You may need to clear your cache.

          • Dragon3025 says:

            Here’s a link to a fresh project using the plugin: https://www.dropbox.com/s/o9kw9odyn57ewxl/Weapon%20Damage%20Gives%200.zip?dl=0

          • Dragon3025 says:

            Oh, okay. I have 1.3 and the formula is working now. Thanks.

  15. Garlyle says:

    It would appear that, at current, “Barehanded” is not working as intended. With only your script running, I consistently get 0 damage attacks when barehanded (Attack command formula is, for testing purposes, literally just “a.weaponDamage()”)

    To specify, I can confirm that the weapon that’s supposed to be substituted in is working. If I manually equip the intended barehanded weapon to characters, then the values work out correctly, and damage is dealt.

    However, this weapon is not substituted in correctly, for either enemies or players.

  16. Daari says:

    First of all, great script but im having a small problem.

    Here is my weapon damage:
    1 * (Math.randomInt(4) + 1) + ((a.atk – 10) / 2)

    and here is my skill damage: a.weaponDamage() – b.def

    Somehow my characters always end up doing 0 damage, am I doing something wrong?

    Yes, brackets and everything is included.

    The only scripts im using are Yanflys Battle System and equip core. thanks!

  17. Lightheaven says:

    a.weaponDamage() return 0 for me.

    YEP_ItemCore
    HIME_EquipSlotsCore
    HIME_YanflyItemCoreEquipSlotsCore
    HIME_EnemyEquips
    HIME_WeaponDamage

    • Hime says:

      I believe yanfly’s ItemCore had a feature where note-tags are deleted from all individual equips once they’re created.
      This means that the weapon damage note-tag does not exist on any of your equips.

      Yanfly has introduced a feature in a later update called “Midgame Note Parsing” that you can set in your plugin parameters.
      By default it is turned off, but try turning it on and see if it makes a difference.

  18. Tredecimal says:

    This is /exactly/ what I was looking for my current project! Awesome! XD

    Just a quick question, though. Does this work with armor as well, or only with weapon?
    e.g. Someone creates a “Vanguard” class that has a Skill to deal damage equal to their shield’s DEF, not counting their “pure” DEF

    Thanks before~

  19. Culio says:

    I tried to make it work with Yanfly`s plugins but I couldnt reproduce the weapon attack formula.
    Is it just not compatible or am I missing something?

    Here what`s on my weapon formula tag:

    2 * (Math.randomInt(8) + 1) + ((a.atk – 10) / 2)
    </weapon damage>

  20. Netmonmatt says:

    This is fantastic. The only possible way I can think it could be improved off the top of my head would be if somehow pulled up a different line for normal attacks based on the weapon equipped.
    You know, how in Dragon Quest, it will say “Eight slashes with a Longsword!” or “Eight threw the Boomerang!” I’ve never understood why RPG Maker never supported that sort of thing without huge workarounds, when it likes Dragon Quest so much.
    That’s just me nitpicking though, this is great and a big improvement over the VX Ace version!

  21. Lowell says:

    Will the option to draw damage/formula’s from individual weapons and/or armors be an option in future releases?

    • Hime says:

      What do you mean by “individual weapons”?

      • Lowell says:

        pulling a formula based on the equipped item’s slot like, 0 for weapon, 1 for shield, etc

        • Hime says:

          We had considered the possibility of specifying each weapon, so like first weapon’s damage plus second weapon’s damage, but then you’d have to actually check whether the second weapon exists, and there were some other complications involved like what if you were only striking with one weapon, how would the skill know which weapon was used, and so on.

          So I ended up just having each weapon calculate their damage and then sum it up for the damage formula, assuming when you perform an action, all weapons will be used (this is based on default battle system).

          There was the possibility of using “Attacking Weapon” as part of the damage formula, so the game determines which weapon is currently striking, but that didn’t work out since we didn’t have a way to test it since there weren’t any battle systems where you could choose which weapon to strike with.

Leave a Reply

Your email address will not be published.

To create code blocks or other preformatted text, indent by four spaces:

    This will be displayed in a monospaced font. The first four 
    spaces will be stripped off, but all other whitespace
    will be preserved.
    
    Markdown is turned off in code blocks:
     [This is not a link](http://example.com)

To create not a block, but an inline code span, use backticks:

Here is some inline `code`.

For more help see http://daringfireball.net/projects/markdown/syntax