MV State effect damage popup doesn't display properly when the target is hit

1736893304206.png


I asked this before along with another issue, but since it couldn't be resolved, I'm re-uploading just this problem.

Using Yanfly Buff&State Core's functionality, I set it up so that when an enemy takes damage from a skill, they take damage equal to (5 * atk)/100. (The skill uses the same calculation formula)

Since the player's attack is 100, they should take 5 damage,
and since the skill's damage is 7, both 7 and 5 damage should appear simultaneously for it to be correct.
However, in the right picture, you can see that 5 appears twice.

How should I modify the script to display this correctly?




1736893338763.png

(Skill formula)


Code:
<Reapply Add Turns>
<Category: debuff>

<Custom Respond Effect>
if (this.isDamage() && value > 0) {
 target.gainHp(-Math.ceil((5 * origin.atk)/100 * target.elementRate(1)));
 target.startDamagePopup();
 if (target.isDead()) {
  target.performCollapse();
 }
 target._stateTurns[19] -= 1;
}
</Custom Respond Effect>
(State Note)
If you can't get it to work, can you use Deselect effect? That shows the different damage values. Though you might have to use Respond effect for checking conditionals value (like the Respond IF turns on a switch and then Deselect checks the switch to run rest of code and turns off the switch).
If you can't get it to work, can you use Deselect effect? That shows the different damage values. Though you might have to use Respond effect for checking conditionals value (like the Respond IF turns on a switch and then Deselect checks the switch to run rest of code and turns off the switch).

Thank you for your answer! I wrote it as you suggested, but when an enemy evades an attack, an error code appears and the game freezes... What could be the problem?


Code:
YEP_CoreEngine.js:1098 TypeError: Cannot read property 'scale' of undefined
    at Sprite_Damage.defaultMovementCode (LGP_BetterDamagePopup.js:870)
    at Sprite_Damage.updateMovement (LGP_BetterDamagePopup.js:770)
    at Sprite_Damage.update (LGP_BetterDamagePopup.js:751)
    at Sprite_Enemy.Sprite_Battler.updateDamagePopup (rpg_sprites.js:549)
    at Sprite_Enemy.Sprite_Battler.update (rpg_sprites.js:495)
    at Sprite_Enemy.Sprite_Battler.update (YEP_BattleEngineCore.js:2897)
    at Sprite_Enemy.Sprite_Battler.update (YEP_X_ActSeqPack2.js:1200)
    at Sprite_Enemy.Sprite_Battler.update (Olivia_BattleImpact.js:467)
    at Sprite_Enemy.update (rpg_sprites.js:952)
    at Sprite_Enemy.update (YEP_BattleEngineCore.js:3220)


Code:
<Reapply Add Turns>
<Category: debuff>

<Custom Respond Effect>
if (this.isDamage() && value > 0) {
 $gameSwitches.setValue(2, true);
} else {
 $gameSwitches.setValue(2, false);
}
</Custom Respond Effect>

<Custom Deselect Effect>
if ($gameSwitches.value(2) == true) {
 target.gainHp(-Math.ceil((origin.mdf * origin.atk)/100 * target.elementRate(1)));
 target.startDamagePopup();
 if (target.isDead()) {
  target.performCollapse();
 }
 target._stateTurns[19] -= 1;
 $gameSwitches.setValue[2] = false
}
</Custom Deselect Effect>
Since the player's attack is 100, they should take 5 damage,
and since the skill's damage is 7, both 7 and 5 damage should appear simultaneously for it to be correct.
However, in the right picture, you can see that 5 appears twice.

you might need to adjust the target's action result a little. iirc if you run a respond effect that uses gainHp() (i might be confusing it with react, but im not checking 😀) , itll overwrite the target's result with that damage value before it even creates the first popup and you get the double popup. try this:
Code:
<Custom Respond Effect>
if (this.isDamage() && value > 0) {

 var result = JsonEx.makeDeepCopy(target._result); //save the current action result
 target.clearResult();

 target.gainHp(-Math.ceil((5 * origin.atk)/100 * target.elementRate(1)));
 target.startDamagePopup();
 
 target._result = result; //set it back afterwards
 
 if (target.isDead()) {
  target.performCollapse();
 }
 target._stateTurns[19] -= 1;
}
</Custom Respond Effect>
you might need to adjust the target's action result a little. iirc if you run a respond effect that uses gainHp() (i might be confusing it with react, but im not checking 😀) , itll overwrite the target's result with that damage value before it even creates the first popup and you get the double popup. try this:
Code:
<Custom Respond Effect>
if (this.isDamage() && value > 0) {

 var result = JsonEx.makeDeepCopy(target._result); //save the current action result
 target.clearResult();

 target.gainHp(-Math.ceil((5 * origin.atk)/100 * target.elementRate(1)));
 target.startDamagePopup();
 
 target._result = result; //set it back afterwards
 
 if (target.isDead()) {
  target.performCollapse();
 }
 target._stateTurns[19] -= 1;
}
</Custom Respond Effect>
Thank you so much! It was solved perfectly!🙂
no problem. i didnt realize that you mentioned it in the thread last month and focused on the popup placement. i could have told you if you brought it up after the popup issue was resolved back then.

Original thread: https://forums.rpgmakerweb.com/threads/state-effect-damage-popup-doesnt-display-properly-when-the-target-is-hit.174704/