MV Damage type as part of HP Damage Text

Hello all, I'm looking for what is (hopefully) a quick solution to my problem. I would like to change the damage text in my game to show the element type (as I am using front view battle, this would make it much easier to display damage types than a colored number popup) when dealing damage. The image below, I would essentially like it to say "Target took 100 fire damage" or "Target took 100 lightning damage" based on the element of damage they just took.

Screenshot 2024-01-19 112015.png


I have pulled code from rpg_windows.js and copied it into a new plugin. For my new var, element, I first set it to result.hpDamage and placed element in FableDamageText.js line 12 return statement. Using the image above with the %1, %2, and %3, I was able to use the plugin below to make my text say "Target took 100 100 damage," meaning I know I am on the right track in terms of getting it to display something different than normal.

Screenshot 2024-01-19 111948.png

However, I'm having a hard time trying to find out what I need to place in line 4 of FableDamageText.js to display the element of the damage that just came in (where I Have placed ?????). I do not know if that is an rpg_windows situation but it seems like this is the closest I've been able to get to figuring this out.

If anyone has any tips or insight on how to make this work and what function or text I can change var element to spit out, I would be greatly appreciative. As mentioned, the goal is to make my new variable in that return statement say the damage type of the damage just received 🙂
The issue here is that the battle log's makeHpDamageText function doesn't have any concept of elements or even the skill that was used; it only knows the values that are sent to it, and right now all it has is the target battler and their ActionResult property.

There are several ways you could achieve your goal, but probably one of the simplest would be to add the skill element to the result object so that you can reference it. You'll have to do this earlier on in the process, at a point where the skill information is known.
The issue here is that the battle log's makeHpDamageText function doesn't have any concept of elements or even the skill that was used; it only knows the values that are sent to it, and right now all it has is the target battler and their ActionResult property.

There are several ways you could achieve your goal, but probably one of the simplest would be to add the skill element to the result object so that you can reference it. You'll have to do this earlier on in the process, at a point where the skill information is known.
Been looking into this offhandedly and I'm still having some trouble locating where the skill element is actually grabbed from. I don't believe it can be found in rpg_windows at all, but I'm not entirely sure where else I'd get it or how I'd hook it up to the plugin I have that spits out the "null" text.
I don't really have the time to properly dive into it right now but if I get a chance tomorrow I'll see if I can give you more specific instructions.
I don't really have the time to properly dive into it right now but if I get a chance tomorrow I'll see if I can give you more specific instructions.
I appreciate any future help, that's very kind of you!
So, I would take this:
add the skill element to the result object so that you can reference it. You'll have to do this earlier on in the process, at a point where the skill information is known.
and do:
Code:
var origExecuteDamage = Game_Action.prototype.executeDamage;
Game_Action.prototype.executeDamage = function(target, value)
{
    origExecuteDamage.call(this, target, value);
    target.result().element = this.item().damage.elementId;
};

So now the action result has the element stored on it. You can then reference that in your formatted text. Here's the little bit of the trick...I have no idea if there's someplace where the Terms where you define the names of the elements is actually given to the game.

I think it's only used internally in the editor.

So I believe you're going to have to redefine them there. At the top of makeHpDamageText(), after say line 5263 after the other variables have been declared, you can add:
Code:
let element = ["physical", "fire", "ice"][target.result().element];
(listing all of your elements as you have them, of course)

Then, lower down, you can add it into the formatted text:
Code:
fmt.format(target.name(), damage, element);
So, I would take this:

and do:
Code:
var origExecuteDamage = Game_Action.prototype.executeDamage;
Game_Action.prototype.executeDamage = function(target, value)
{
    origExecuteDamage.call(this, target, value);
    target.result().element = this.item().damage.elementId;
};

So now the action result has the element stored on it. You can then reference that in your formatted text. Here's the little bit of the trick...I have no idea if there's someplace where the Terms where you define the names of the elements is actually given to the game.

I think it's only used internally in the editor.

So I believe you're going to have to redefine them there. At the top of makeHpDamageText(), after say line 5263 after the other variables have been declared, you can add:
Code:
let element = ["physical", "fire", "ice"][target.result().element];
(listing all of your elements as you have them, of course)

Then, lower down, you can add it into the formatted text:
Code:
fmt.format(target.name(), damage, element);
Code:
var origExecuteDamage = Game_Action.prototype.executeDamage;
Game_Action.prototype.executeDamage = function(target, value)
{
    origExecuteDamage.call(this, target, value);
    target.result().element = this.item().damage.elementId;
};

Window_BattleLog.prototype.makeHpDamageText = function(target) {
    var result = target.result();
    var damage = result.hpDamage;
    var isActor = target.isActor();
    var fmt;
    let element = ["physical", "fire", "ice"][target.result().element];

    if (damage > 0 && result.drain) {
        fmt = isActor ? TextManager.actorDrain : TextManager.enemyDrain;
        return fmt.format(target.name(), TextManager.hp, damage);
    } else if (damage > 0) {
        fmt = isActor ? TextManager.actorDamage : TextManager.enemyDamage;
        return fmt.format(target.name(), damage, element);
    } else if (damage < 0) {
        fmt = isActor ? TextManager.actorRecovery : TextManager.enemyRecovery;
        return fmt.format(target.name(), TextManager.hp, -damage);
    } else {
        fmt = isActor ? TextManager.actorNoDamage : TextManager.enemyNoDamage;
        return fmt.format(target.name());
    }
};

Here's what I have in the actual plugin I'm keeping this all in, and i don't have it working yet. I am unsure if I've put the var origExecuteDamage and the executeDamage game action in the correct location. I am getting "actor deals 4 undefined damage!" as my hp text.
Do you literally only have those three elements in your Types tab? O__o
Do you literally only have those three elements in your Types tab? O__o
Not for the actual game, but my only elements present for testing were Physical and Fire. I noted that it was treating physical as 0, not 1, which I should have realized. It works for the other elements (fire and I added lightning after ice for testing) but not for physical in spot 1, oddly. I threw in spot 0 "typeless" and that pushed everything forward to match the index number.

So it seems to work like a charm except for when it comes to physical damage, the item in index 0/1 depending on how I wanted to set my list.
I threw in spot 0 "typeless" and that pushed everything forward to match the index number.
Huh. That's my bad, I thought the types started at 0, but they don't, they match the numbers in the editor.

So you'll want to change your element variable declaration to:
Code:
let element = ["untyped", "physical", "fire", "ice"][target.result().element];

So it seems to work like a charm except for when it comes to physical damage, the item in index 0/1 depending on how I wanted to set my list.
That seems funky. Are you sure you're not confusing Physical with Normal Attack or None?

I just changed my Attack skill to deal Physical elemental damage and it correctly registers as element ID 1.

To compensate for Normal Attack, you'd do:
Code:
let element = ["normal", "untyped", "physical", "fire", "ice"][target.result().element+1];
Huh. That's my bad, I thought the types started at 0, but they don't, they match the numbers in the editor.

So you'll want to change your element variable declaration to:
Code:
let element = ["untyped", "physical", "fire", "ice"][target.result().element];


That seems funky. Are you sure you're not confusing Physical with Normal Attack or None?

I just changed my Attack skill to deal Physical elemental damage and it correctly registers as element ID 1.

To compensate for Normal Attack, you'd do:
Code:
let element = ["normal", "untyped", "physical", "fire", "ice"][target.result().element+1];
Thank you for all the help so far. I was able to get everything to work correctly except for the element Normal Attack, it always says "normal" or whatever else I put in that spot. This means no matter the element of the weapon (tested with phys and fire), it's going to show up as incorrect text. Ideally, if it was equal to "normal," could I run the executeDamage function to get the element id AGAIN and print it that way?
The code I gave you for saving the element only records the element of the skill.

If you're using Normal Attack and elements on your weapons, that's not actually stored in any one place - it's calculated on the fly, because each attack looks at all elements you have on there to see which the target is most vulnerable to.

So you'd have to partially rewrite Game_Action.elementsMaxRate() to not just find the rate it's going to apply, but also track/record which element that is.

I'm going to take a nap, now...if Trihan or someone else pops by and wants to show you how to do that, cool beans. If it's still hanging around later this evening, I'll do it up for you.
I haven't touched this since Sunday, I'll have another look around and see if I can find something that will help or solve my issue in Game_Action.elementsMaxRate() or related functions.

Original thread: https://forums.rpgmakerweb.com/threads/damage-type-as-part-of-hp-damage-text.164941/