Graphical "bug" with Recoil Damage from Yanfly Plugins

I'm using Yanfly plugin's to get a damage recoil effect on my armor.
So that if you get attacked, the enemy takes damage in return.
This is done either with a passive state (YEP plugin), or a normal state.

I want this state on a few items (Spiked shield, ring of thorns, etc.).
And also made a counter attack, which hurts anyone who hurts you for that turn.
Each of these have their own unique state (Passive state for armor) with the same parameters.
And that works fine. The damage stacks up like it should... BUT... The damage numbers displayed on the enemy are wrong. They only take one of the States into account.
Does anyone know how to fix this? I'm not smart enough. :/


I've turned off every plugin exept these:
Yep_ CoreEngine
Yep_ BattleEngineCore
Yep_BuffStatesCore
Yep_AutoPassiveStates

To get the recoil effect I took this from the internet and put it into the notebox of the state (Uses YEP_BuffStatesCore):

<Custom Respond Effect>
if (value > 0 && this.isPhysical()) {
var rate = 0.10;
var recoil = value * rate;
var dmg = Math.ceil(recoil);
user.gainHp(-1 * dmg);
if (user.isDead()) {
user.performCollapse();
}
}
</Custom Respond Effect>
Just as a tip, when you post code use the CODE tag (the </> on the edit bar). That preserves indentation and brackets.

You're getting the error because you're damaging separately through multiple function calls at basically the same time.

Instead of having multiple states, use one state that adds up the equipment. So all of your equipment would have the same passive state on them. Then you'd do something like:
Code:
<Custom Respond Effect>
if (value > 0 && this.isPhysical()) {
    let armors = 0;

// List the IDs of all armors that contribute to the recoil
    [13, 22, 25, 48].forEach(id => {if (user.armors().includes($dataArmors[id])) armors++});

    user.gainHp(Math.ceil(-.1 * armors * value));
    user.startDamagePopup();

    if (user.hp <= 0)
        user.performCollapse();
}
</Custom Respond Effect>
Just as a tip, when you post code use the CODE tag (the </> on the edit bar). That preserves indentation and brackets.

You're getting the error because you're damaging separately through multiple function calls at basically the same time.

Instead of having multiple states, use one state that adds up the equipment. So all of your equipment would have the same passive state on them. Then you'd do something like:
Code:
<Custom Respond Effect>
if (value > 0 && this.isPhysical()) {
    let armors = 0;

// List the IDs of all armors that contribute to the recoil
    [13, 22, 25, 48].forEach(id => {if (user.armors().includes($dataArmors[id])) armors++});

    user.gainHp(Math.ceil(-.1 * armors * value));
    user.startDamagePopup();

    if (user.hp <= 0)
        user.performCollapse();
}
</Custom Respond Effect>
I'll use the Code thingy next time, thank you. 🙂

And thank you for the code... But...
Could you dumb it down even further for me?
I can't quite get it to work.
This would completely replace my previous formula? Just have all armors refer to a state with that code?
How do I go about setting the recoil damage %? I thought let armors = number, but that did nothing.
Can I still have a different value per armor?
And I would also like for it to still work on a skill or two! (Counter Attack skill, I guess I didn't specify that! whups.)
I think there is a syntax error in the code @ATT_Turan provided. (Unless it's some deep javascript magic I don't know).
Try user.gainHp(Math.ceil(-1 instead of user.gainHp(Math.ceil(-.1
I think there is a syntax error in the code @ATT_Turan provided. (Unless it's some deep javascript magic I don't know).
Try user.gainHp(Math.ceil(-1 instead of user.gainHp(Math.ceil(-.1
Thank you 🙂, but the code still doesn't seem to be doing anything.
Though there's a good probability I'm just doing it wrong D:
I think there is a syntax error in the code @ATT_Turan provided.
var rate = 0.10;
...
user.gainHp(-1 * dmg);
user.gainHp(Math.ceil(-.1 * armors * value));


(Unless it's some deep javascript magic I don't know).
The eldritch magic of combining two statements that say ".1" and "* -1" into one statement that says "* -.1" 😉

How do I go about setting the recoil damage %? I thought let armors = number, but that did nothing.
Can I still have a different value per armor?
You can, but first this code should work for you before you try to change things if you don't understand them.

Please confirm you followed my instructions and filled in the IDs of your armors. Then post a screenshot of the state and one of the armors from your database.
Dang, I did not know you could omit the leading 0 in 0.1 👋
Dang, I did not know you could omit the leading 0 in 0.1 👋
Yup! The interpreter is smart enough to see the decimal and go from there.

1710425226439.png
The eldritch magic of combining two statements that say ".1" and "* -1" into one statement that says "* -.1" 😉


You can, but first this code should work for you before you try to change things if you don't understand them.

Please confirm you followed my instructions and filled in the IDs of your armors. Then post a screenshot of the state and one of the armors from your database.
Well, this is my most literal attempt. I only changed the [13, 22, 25, 48]. to [7, 16].

STATES.jpg
ARMORS.jpg
you are testing with a physical attack, right? not a certain hit?
you are testing with a physical attack, right? not a certain hit?
Yeah, it's a physical attack. It works fine with the old formula except for the shown numbers being wrong thing.
i see it now. change the "user" in "user.armors().includes..." to "target"
Oops. It should be target.armors, not user.

Edit: Simultaneous error-finding from @Robro33!
i see it now. change the "user" in "user.armors().includes..." to "target"
Nice find! 🙂
I guess it was looking for the enemy's armor. That's no good.

It's certanly a step closer. It works now... Sort of... But the damage numbers appear twice! (If it does 3 damage it say 3, 3... Which is very misleading.)

The amount of armor listed/ worn doesn't seem to affect this.
But the damage numbers appear twice!
remove the "user.startDamagePopup()"

thats strange though. I thought by default gainHp doesnt trigger popups on the user inside a respond effect without a call for one

Edit: Noticed the original didnt need it either and it wasnt an issue. For future reference, theres times when you have to use it with for the buffs and states plugin note tags. this just wasnt one of them
remove the "user.startDamagePopup()"

thats strange though. I though by default respond effects dont trigger popups on the user without a call for one
Thank you 🙂
Hmm, Well, it worked. Only one popup number now, and it seems to be correct.

my monkey brain figured out where the armor damage comes from too.
(-.1 * armors * value)); Means 10% * amount of armor armor worn * damage taken
(I know you all know this, but I'm starting to follow along a teeny tiny bit)


Thank you to everyone with the help so far 🙂
This looks a ton better already 🙂

Still no idea about the recoil skill and having different recoil for different armor though! D:
Now that you've gotten the basic thing working:
Still no idea about the recoil skill and having different recoil for different armor though! D:
If that's what you want, you get rid of that nice, efficient, single line of code I made, and count each one.

Code:
<Custom Respond Effect>
if (value > 0 && this.isPhysical()) 
{
    let armors = 0;

    if (target.isEquipped($dataArmors[7]))
        armors -= .07;

    if (target.isEquipped($dataArmors[16]))
        armors -= .07;

// Copy and paste whatever other armor IDs and percentages you want

    user.gainHp(Math.ceil(armors * value));

    if (user.hp <= 0)
        user.performCollapse();
}
</Custom Respond Effect>
Still no idea about the recoil skill and having different recoil for different armor though! D:
you can have the state apply a different rate for each set of armor if you just adjust it a little
Code:
if (value > 0 && this.isPhysical()) {
    let rate = 0;

// List the IDs of all armors that contribute to the recoil (7%)
    [13, 22].forEach(id => {if (target.armors().includes($dataArmors[id])) rate+=.07});
// List the IDs of all armors that contribute to the recoil (10%)
    [25, 48].forEach(id => {if (target.armors().includes($dataArmors[id])) rate+=.1});

    user.gainHp(Math.ceil(-rate * value));

    if (user.hp <= 0)
        user.performCollapse();
}
now armors 13 and 22 add 7% and 25 and 48 add 10%. add more as needed

EDIT: Now im the one behind 🤣, but you should have gotten the idea between both examples @FELIXfelixFELIX
Now that you've gotten the basic thing working:

If that's what you want, you get rid of that nice, efficient, single line of code I made, and count each one.

Code:
<Custom Respond Effect>
if (value > 0 && this.isPhysical())
{
    let armors = 0;

    if (target.isEquipped($dataArmors[7]))
        armors -= .07;

    if (target.isEquipped($dataArmors[16]))
        armors -= .07;

// Copy and paste whatever other armor IDs and percentages you want

    user.gainHp(Math.ceil(armors * value));

    if (user.hp <= 0)
        user.performCollapse();
}
</Custom Respond Effect>
Works like a charm! Thank you 🙂

Any way to implement the skill into any of this? (It worked by using a state with the formula from the first post with magical and physical damage and 150% recoil.)

Otherwise I can probably make something close to what I had with YEP_Countercontrol.

Thanks a lot for the help 🙂
I never would've figured this out myself ^.^
Any way to implement the skill into any of this? (It worked by using a state with the formula from the first post with magical and physical damage and 150% recoil.)
I don't understand the question. What skill? What does "implement the skill" mean?

Original thread: https://forums.rpgmakerweb.com/threads/graphical-bug-with-recoil-damage-from-yanfly-plugins.166207/