MV How To Prevent The Miss Tag From Duplicating? (FFXV Black Hood Effect)

So I'm trying to replicate the black hood effect from Final Fantasy 15 which automatically dodges an attack, but in turn uses some MP. I got it working, but the only problem is the miss tag will show 3 times instead of once, and I'm not sure how to prevent this from happening.
JavaScript:
<Custom React Effect>
if (Math.random() < 1) { 
    target.result().evaded = true;
    var mpCost = 20;
    if (target.mp >= mpCost) {
        target.gainMp(-mpCost);
    } else {
        target.removeState(141);
    }
}
</Custom React Effect>
I got it working,
to my knowledge, this shouldnt work? by the time youre running react effects, the hit calc has already been made, is no longer being considered, and the game is already partway through executing the damage because the attack was determined to have hit. the damage popup should say the attack missed, but are you sure the damage isnt still being taken?

but the only problem is the miss tag will show 3 times instead of once, and I'm not sure how to prevent this from happening.
target.result().evaded = true;
with how the popups are handled, forcefully changing the result to say the attack missed is going to do funny things to the popups. if youre using it, i think yanfly's battle engine core only ever makes miss popups if the result says miss and always makes at least one, but it still checks to see if hp and mp are affected individually before trying to setup popups for those too. So that would result in 3 misses if your result ends up containing an hp effect and an mp effect

I think the easiest way to do what you want is to give the state maxxed evasion traits, run a deselect effect to check if the incoming attack missed, and then deduct mp/remove the state

also...
if (Math.random() < 1) {
Math.random() can only give a number thats less than 1. that condition can never be false. if that's intended, then the conditional statement is not needed at all.
to my knowledge, this shouldnt work? by the time youre running react effects, the hit calc has already been made, is no longer being considered, and the game is already partway through executing the damage because the attack was determined to have hit. the damage popup should say the attack missed, but are you sure the damage isnt still being taken?



with how the popups are handled, forcefully changing the result to say the attack missed is going to do funny things to the popups. if youre using it, i think yanfly's battle engine core only ever makes miss popups if the result says miss and always makes at least one, but it still checks to see if hp and mp are affected individually before trying to setup popups for those too. So that would result in 3 misses if your result ends up containing an hp effect and an mp effect

I think the easiest way to do what you want is to give the state maxxed evasion traits, run a deselect effect to check if the incoming attack missed, and then deduct mp/remove the state

also...

Math.random() can only give a number thats less than 1. that condition can never be false. if that's intended, then the conditional statement is not needed at all.
Took your advice and got it working. Thank you. Also for some reason the one I was using was working somehow. The user wouldn't take any damage, and the mp was consumed. The only problem was miss showing up 3 times per hit. I guess it was possible that it was still registering the damage behind the scenes but the player's hp wouldn't go down. I'm not entirely sure.

Here's the code I'm using if anyone else would like to replicate the effect.
JavaScript:
<Custom Deselect Effect>
if (target.result().missed || target.result().evaded) {
   
    var mpCost = 10;
   
    if (target.mp >= mpCost) {
        target.gainMp(-mpCost);
    } else {
        target.removeState(126); // replace with your state ID
    }
}
</Custom Deselect Effect>

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/how-to-prevent-the-miss-tag-from-duplicating-ffxv-black-hood-effect.182444/