How do I inflict damage on an enemy whilst also simultaneously damaging the wielder?

Greetings,

I'm currently creating what should be somewhat of an intuitive weapon known as the double edged sword for various classes in my RPG Maker MV project, but I can't seem to get the intended effect that is proposed in the title. How do I go about making it so that the weapon inflicts double damage to the enemy but as a negative drawback, damages the wielder for the same amount? Any help would be much appreciated!
damage formula coding - there is a pinned topic on how to use javascript inside the damage formula for additional effects
The easiest way would be in the damage formula - for example, you can do something like a.hp -= 50; (damage formula) to deal 50 damage to the attacker, or even a.hp -= (formula based on stats); (damage formula) to scale the the attacker's self-damage up based on, say, his strength stat.

The most "true" way to do damage, allowing things like self-crits and variance to take effect, would be to use Yanfly's Target Core and push the attacker into the targets array using a notetag.
There's another way, one that I like to use, that involves action sequences (also requires a yanfly plugin)

Code:
<Target Action>
</Target Action>
<Whole Action>
perform action
action animation: targets
action animation: user
wait for animation
action effect: targets
action effect: user
death break
perform finish
</Whole Action>

Or if you want a different animation to play on the user, replace "action animation: user" with "animation n: user" where "n" is the animation id you want to play on them. Or remove that line entirely if you want no animation to play on them.
If you want this to be specific to a weapon, rather than a skill, I'd suggest the following two plugins:
You can then try the following:
  1. On the States tab, make a new state, call it whatever you like, and put this in its notebox:
    Code:
    <Custom Confirm Effect>
    if (value > 0) {
      value *= 2;
      user.gainHp(-value);
    }
    </Custom Confirm Effect>
    I.e. just before the skill formula is applied to the target, multiply outgoing damage by 2 and subtract that amount from the user's current HP. (value is negative for healing.) If you want more conditions, e.g. physical hit skills only (not magical or certain hit), you can add stuff to the if condition:
    Spoiler: Notetag example 2
    Code:
    <Custom Confirm Effect>
    if (value > 0 && this.isPhysical()) {
      value *= 2;
      user.gainHp(-value);
    }
    </Custom Confirm Effect>

  2. Then, on the Weapons tab, find your weapon and put this in its notebox:
    Code:
    <Passive State: x>
    Replace x with the ID of the state you created in step 1. This'll attach the state to the weapon. 😮‍💨

  3. Save your project and test! 😤

One more, slightly technical note: I've used gainHp for modifying HP, partly because hp is a read-only property, and partly because gainHp performs a refresh and interfaces with the action result/damage popup stuff. 😅
If you want this to be specific to a weapon, rather than a skill, I'd suggest the following two plugins:
You can then try the following:
  1. On the States tab, make a new state, call it whatever you like, and put this in its notebox:
    Code:
    <Custom Confirm Effect>
    if (value > 0) {
    value *= 2;
    user.gainHp(-value);
    }
    </Custom Confirm Effect>
    I.e. just before the skill formula is applied to the target, multiply outgoing damage by 2 and subtract that amount from the user's current HP. (value is negative for healing.) If you want more conditions, e.g. physical hit skills only (not magical or certain hit), you can add stuff to the if condition:
    Spoiler: Notetag example 2
    Code:
    <Custom Confirm Effect>
    if (value > 0 && this.isPhysical()) {
    value *= 2;
    user.gainHp(-value);
    }
    </Custom Confirm Effect>

  2. Then, on the Weapons tab, find your weapon and put this in its notebox:
    Code:
    <Passive State: x>
    Replace x with the ID of the state you created in step 1. This'll attach the state to the weapon. 😮‍💨

  3. Save your project and test! 😤

One more, slightly technical note: I've used gainHp for modifying HP, partly because hp is a read-only property, and partly because gainHp performs a refresh and interfaces with the action result/damage popup stuff. 😅
I've tried this and it works as intended! Thank you so much. On an off topic remark, it would seem as if this has broken one of my troop's basic attacks. I now get "this.battle(...).setup weapon animation is not a function" as an error. Do you happen to know how to resolve this?
I've tried this and it works as intended! Thank you so much. On an off topic remark, it would seem as if this has broken one of my troop's basic attacks. I now get "this.battle(...).setup weapon animation is not a function" as an error. Do you happen to know how to resolve this?
Are you using any other plugins? The load order (order of the list in the Plugin Manager) can cause compatibility issues. Yanfly's plugins, for example, should be loaded in the order listed here:
You can simply click+drag plugins in the Plugin Manager to rearrange their order. Also, be sure to save your project before testing, otherwise Plugin Manager changes will not be seen during the test. 🙂

Original thread: https://forums.rpgmakerweb.com/threads/how-do-i-inflict-damage-on-an-enemy-whilst-also-simultaneously-damaging-the-wielder.122941/