MZ Is it possible to get the damaged elements in "Sprite_Damage.prototype.setup"?

Hi all, I want to show different colored numbers for different damage elements, for example, the fire elements shows red, water elements show blue color, I found where the damage numbers were plotted:

JavaScript:
Sprite_Damage.prototype.setup = function(target) {
    const result = target.result();
    if (result.missed || result.evaded) {
        this._colorType = 0;
        this.createMiss();
    } else if (result.hpAffected) {
        this._colorType = result.hpDamage >= 0 ? 0 : 1;
        this.createDigits(result.hpDamage);
    } else if (target.isAlive() && result.mpDamage !== 0) {
        this._colorType = result.mpDamage >= 0 ? 2 : 3;
        this.createDigits(result.mpDamage);
    }
    if (result.critical) {
        this.setupCriticalEffect();
    }
};

But I don't know how to get the elements here, does anyone know what to do? Any advice would be helpful!
Game_ActionResult is the source of information here, which does not include information about the action item or its elements.

The relevant info would need to be stored somewhere that is accessible from Sprite_Damage#setup, e.g. the target's result. For example, that could be done with a plugin that patches the apply method of Game_Action.
Game_ActionResult is the source of information here, which does not include information about the action item or its elements.

The relevant info would need to be stored somewhere that is accessible from Sprite_Damage#setup, e.g. the target's result. For example, that could be done with a plugin that patches the apply method of Game_Action.
Thanks, caethyril, I'll check out Game_Action.prototype.apply.
Good luck~ 👋
Good luck~ 👋
Thank you, I succeeded, using the following code:

JavaScript:
const _Game_Action_Apply = Game_Action.prototype.apply;
    Game_Action.prototype.apply = function(target) {
    _Game_Action_Apply.apply(this, arguments);
    tempSkillElement = this.item().damage.elementId;
};

I ran into a new problem, I want the damage number that pops up when you lose HP due to a poisoned state to be able to turn green, but Game_Action.prototype.apply won't run when HP is lost due to poisoned state, where do I monitor every time I lose HP due to status?

I've found that this doesn't seem to be possible, as the same character could have both states, one fire and one Poison, and at the end of the round their damage is settled together, damage numbers will only appear once
By default Game_Battler.prototype.regenerateHp is responsible for regeneration/poison like effects in your game.

That said this is a little tricky since by default states don't trigger their effects one by one like you might see in other games.

So even if you could use Game_Battler.prototype.regenerateHp to check when the user is damaged it won't be the most reliable way.
By default Game_Battler.prototype.regenerateHp is responsible for regeneration/poison like effects in your game.

That said this is a little tricky since by default states don't trigger their effects one by one like you might see in other games.

So even if you could use Game_Battler.prototype.regenerateHp to check when the user is damaged it won't be the most reliable way.
Yes, the damage values of the statuses will be put together in a settlement.
The best way would probably be to turn a flag on in regenerateHp and then check for that flag in the part that colours the text.

One thing to be aware of is that the method you used created a *global variable*. This is generally advised against because you're now polluting the global namespace with a variable called "tempSkillElement" and if you ever reuse that somewhere else or happen to start using a plugin that uses that identifier somehow, you're going to run into problems that are very difficult to troubleshoot.
The best way would probably be to turn a flag on in regenerateHp and then check for that flag in the part that colours the text.

One thing to be aware of is that the method you used created a *global variable*. This is generally advised against because you're now polluting the global namespace with a variable called "tempSkillElement" and if you ever reuse that somewhere else or happen to start using a plugin that uses that identifier somehow, you're going to run into problems that are very difficult to troubleshoot.
The key issue is that damage values caused by multiple statuses don't pop up with multiple damage numbers.

Don't worry, "let tempSkillElement = -1;" this is defined above, my whole plugin is in "const ASDynamicDamageTextNameSpace = (() => {})();".
The key issue is that damage values caused by multiple statuses don't pop up with multiple damage numbers.

Don't worry, "let tempSkillElement = -1;" this is defined above, my whole plugin is in "const ASDynamicDamageTextNameSpace = (() => {})();".
Yeah, so you'd have to decide on a priority order of sources.

Original thread: https://forums.rpgmakerweb.com/threads/is-it-possible-to-get-the-damaged-elements-in-sprite_damage-prototype-setup.166048/