MV State to deal Damage on Evade or Miss

Hello,

I'm trying to using this Thornmail state from Yanfly's Tips and Tricks


JavaScript:
<Custom React Effect>
// Check to see if any physical damage is dealt.
if (value > 0 && this.isPhysical()) {
  // Sets the Recoil Rate to 15%.
  var rate = 0.15;
  // Determines the amount of recoil damage dealt.
  var recoil = value * rate;
  // Sets the DEF bonus rate to 25%.
  var rate = 0.25;
  // Determines the amount of bonus damage dealt.
  var bonus = target.def * rate;
  // Rounds up the bonus damage and recoil damage.
  var dmg = Math.ceil(bonus + recoil);
  // Makes the attacker lose damage equal to the dmg variable.
  user.gainHp(-1 * dmg);
  // Check to see if the attacker is dead.
  if (user.isDead()) {
    // If the attacker is dead, make it collapse.
    user.performCollapse();
  }
}
</Custom React Effect>

However, I want to make it so it deals damage to the enemy, if the player Evades the enemy's physical attack, or if the enemy's physical attack Misses the player.

I tried a lot of things for the condition, but I just can't seem to get it to work.

Would anyone be able to help?
The problem is that if an attack roll results in a miss, that's the end of the action right there. It never proceeds to damage calculation or such things.

If you look at the top of that section in the documentation, it clearly labels which notetags will take place when:
Code:
Quick Reference:
  Action Starts
  - Attacker: Initiate
  - Defender: Select
  Action Connects as a Success Hit, skip if Missed or Evaded
  - Attacker: Confirm
  - Defender: React
  Damage is Applied to the Defender
  - Defender: Respond
  - Attacker: Establish
  These occur regardless if the action is successfully hit.
  - Defender: Deselect
  - Attacker: Conclude

So you'd need to set it up as a deselect tag. As far as the condition...well, what do you want the conditions to be? The example you quoted above is when damage is dealt from a physical skill.
I would like the condition to be if the player Evades or if the enemy Misses
So if (target.result().missed || target.result().evaded)
So I tried that, but then the damage returned is 0 , I think because there's no "value" set so everything becomes 0. I also tried changing "value" to 1 , but then no damage is dealt to the enemy at all.

Any ideas?



JavaScript:
<Custom Deselect Effect>

// Check to see if any physical damage is dealt.

if (target.result().missed || target.result().evaded) {

  // Sets the Recoil Rate to 15%.

  var rate = 0.15;

  // Determines the amount of recoil damage dealt.

  var recoil = value * rate;

  // Sets the DEF bonus rate to 25%.

  var rate = 0.25;

  // Determines the amount of bonus damage dealt.

  var bonus = target.def * rate;

  // Rounds up the bonus damage and recoil damage.

  var dmg = Math.ceil(bonus + recoil);

  // Makes the attacker lose damage equal to the dmg variable.

  user.gainHp(-1 * dmg);

  // Check to see if the attacker is dead.

  if (user.isDead()) {

    // If the attacker is dead, make it collapse.

    user.performCollapse();

  }

}

</Custom Deselect Effect>
So I tried that, but then the damage returned is 0 , I think because there's no "value" set
Well, yes, you're referencing a variable that doesn't exist.
I also tried changing "value" to 1 , but then no damage is dealt to the enemy at all.
So, following the math in your code, you're doing
rate = 0.15
recoil = 1*0.15 = 0.15
Then you redeclare rate as 0.25 (which apparently doesn't break anything in JavaScript, but it's certainly a bad habit)
bonus = 0.25 * whatever the actor's defense might be
dmg = bonus + 0.15 (so bonus+1, because Math.ceil rounds up)
Then damage the attacker for that much.

I don't off the top of my head see why that would result in nothing happening, but there are certainly a bunch of wasted/unnecessary steps.

What is the defense of your actor when you're testing this?

If I were doing this, I'd get rid of all the unnecessary fluff and extra variables confusing the world.
Code:
<Custom Deselect Effect>
if (target.result().missed || target.result().evaded)
{
    user.gainHp(0-Math.ceil(target.def*0.25));
    if (user.isDead())
        user.performCollapse();
}
</Custom Deselect Effect>
I tried the suggestion you posted, but no damage is dealt for some reason

JavaScript:
<Custom Deselect Effect>
if (target.result().missed || target.result().evaded)
{
    user.gainHp(0-Math.ceil(target.def*0.25));
    if (user.isDead())
        user.performCollapse();
}
</Custom Deselect Effect>

My Actor has 10 Defense , but I also tried with 100 Defense and same result.

Any ideas?
To clarify: when you say no damage is dealt, do you mean that nothing happens, or that a 0 pops up?
Nothing pops up
Sorry, I don't know. This works perfectly when I test it in a new game, so either you're setting it up incorrectly or there's something else in your project that's making it not work (plugins out of order, conflicting plugins, etc.).

You can post a screenshot of the state in the database, and of your plugins in the plugin manager, and ask for help troubleshooting from there...but a good starting activity is to double check the list of YEP plugins on the Web site and make sure that any you're using are in that order.
I believe I found the issue. For whatever reason, the issue seems to be "BattleEngineCore" that's causing the problem.

I had "BattleEngineCore" at the top and the issue was happening.

However, if I put "BuffStatesCore" above "BattleEngineCore" the issue no longer occurs.

This however, does appear to go against the recommended ordering of Yanfly Plugins?

Not sure if you can also confirm this on your side?

The state does indeed work with this plugin order now:


1637433910321.png
Weird, but whatever works!
Next time you're asking for stuff, don't crop your screenshots down like that - it's taking time on your part and you're getting rid of information that might help you (for example, I've noticed many times that people are running the wrong versions of plugins).

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

Original thread: https://forums.rpgmakerweb.com/threads/state-to-deal-damage-on-evade-or-miss.142275/