[SOLVED] How do I make an attack do reduced damage if its target has a specific state?

Hi,

For the sake of an example, let's say I've set up an attack skill that enemies will use on the player's characters, and it always deals 300 damage no matter what.
No variance, no critical hit chance, no added states, perfect accuracy, etc.

Is there a plugin or something I can put in the damage formula that checks if the target is affected by State #31 (let's call it Mettle), and if they are, reduce the damage that the skill would deal by the targeted character's Special Param grd (Guard effect rate)?
(Yes, I know that guarding does that normally, but please just humor me).

So if the targeted character has no states, they'd receive 300 damage like normal,
but if they're affected by State #31 (Mettle) and they have a guard rate of 100%, they'd receive 150 instead.
If they have a guard rate of 200%, they'd receive 75 instead.

I'm not very good with math and formulas, so I'm not sure how to make it work.
Any help is greatly appreciated!
Thanks!
You could try this formula:
JavaScript:
Math.floor(300 * (b.isStateAffected(31) ? 1 / Math.max(2 * b.grd, 1) : 1))
Some explanation:
  • Math.floor(stuff)
    Rounds stuff down to an integer.
    Just in case, to prevent any funny business with fractional HP or something. 😴​

  • b.isStateAffected(31) ? A : B
    This evaluates to A if the target is affected by state 31, or B otherwise.
    In this case, A and B are simply damage multipliers, that's why B = 1 here.​

  • Math.max(2 * b.grd, 1)
    This evaluates to the largest of the values inside the brackets, i.e. it'll be 2 times the target's GRD, unless that's less than 1 (e.g. if their GRD is less than 50%). Basically, this ensures that:
    1. The target never suffers more than normal damage when affected by state 31, and
    2. The game doesn't end up trying to divide by zero (because that would be bad).
Thank you so much caethyril!

I've tested it and it works perfectly, it's exactly what I needed!

Thank you very much : D
@TheDrifter Please report your thread as solved next time. If you simply edit the title, moderators won't be notified. Click the report button right beside the edit button and write "solved" as a reason. I'll close this thread this time, but please remember this for next time. Thank you.

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/solved-how-do-i-make-an-attack-do-reduced-damage-if-its-target-has-a-specific-state.118750/