Show Damage Value on Enemy

Display Damage Value v1.07
by Roninator2​

Introduction
A script I made for my game, but I like to share my work.

Features
- Display potential damage to the enemy for the skill selected
- Accounts for element weakness or defense
- Set text colour

How to Use
Put below ▼ Materials

Images
Spoiler: images
1620920334147.png
1620920360331.png
1620929073460.png
skill window hidden

Script
script
Notes
If you want the skill window to be hidden, you'll have to find a script or code snippet for that.
This was bugging me so I added it in. Skill window hides when selecting the enemy.

If the text does not show up for you, adjust the numbers for width/height and location .
I thought it wasn't working in my game until I changed the numbers.
I had to change the TEXT_OFFSET_Y from 2 to 100

Update
- Added support for Yanfly Battle Engine due to conflicts

Credit and Thanks
- Roninator2
- Vlue - for replicating some code
- Tsukihime - for replicating some code

Terms of use
Follow the original Authors terms of use where applicable
- When not made by me (Roninator2)
Free for all uses in RPG Maker except nudity
Anyone using this script in their project before these terms
were changed are allowed to use this script even if it conflicts
with these new terms. New terms effective 03 Apr 2024
No part of this code can be used with AI programs or tools
Credit must be given
That is very neat. Actually have not seen a tooltip type damage show before. First time for me.

good job!
good job!
Thanks. I actually modified it a bit more to be turned on or off with a switch. Then using CT BOLT's state switch script, I set it so that when the actor uses a skill to apply a state (2-5 turns), the switch is turned on and then the player can see the damage.
But I did that for my game.
Do note that due to how you get the damage value here, everything in the damage formula gets executed more than once, even before the skill/item is actually used. This means that it can mess up some things depending on what you use in your damage formulas (a variable/switch change is probably the most common things people use here for some special cases).

This issue is present in all of these damage prediction scripts, since all of them do the same thing (use the damage formula without accounting for these special cases). At least the variable/switch cases can be fixed easily by saving the old values before the damage calculation part and re-load it after.
gets executed more than once
Thanks for the notice. Didn't think about that. Bad coding on my part then.
And thanks for the suggestion. Yea, a switch is certainly the easiest way to control that.
Script updated.
Ohh, I didn't even notice that part. 😀

I meant this line:
Code:
value = item.damage.eval(user, enemy, $game_variables)
This will execute whatever is used in the damage formula.
For example:
Code:
dmg = v[15] % 3 == 0 ? a.atk * 10 : -a.atk; $game_variables[15] += 1; dmg
This will make the skill do 10 * ATK damage if variable 15 is divisible by 3, otherwise it heals the target.
Variable 15 is increased by 1 every time this skill is used.
That's how it should work.
Spoiler
I'm kinda rusty with the damage formula things, so there may be some errors in the example, but I hope you get the idea behind it.

But because you execute the damage formula to calculate the possible damage, variable 15 will be increased for every single calculation without actually using the skill, effectively breaking the skill.
This is just one example, but I imagine a lot of people who actually put some effort to come up with some more unique skills will have at least some similar cases.

To fix this, you can save the switch and variable arrays before the damage calculation, and re-load it when you are done with it. Something like:
Code:
ovars = Marshal.load(Marshal.dump($game_variables))
oswitchs = $game_switches.clone
# Insert damage calculation here
$game_variables = ovars
$game_switches = oswitchs
I used marshal for the variables because people could use other things there, like strings and even other arrays/hashes, so simply cloning it may not be enough.

Other than these cases, your script should work fine. It's only an issue when something like the example I gave is used in the damage formulas.
After some testing I discovered a strange bug.

If a player Actor uses a skill with a specific element; Against an enemy with an attack element of the same type, the damage preview turns into all 0. However when you attack the damage calculation is done as normal.

So for example. If Actor has a skill called "Ice slash" which has a forced "Ice" element, and they fight against some ice elemental with an attack element of "Ice", which causes any attacks with the element "Normal Attack" to have "Ice" element instead. Using the "Ice slash" against that enemy will display a preview of 0 to 0 damage, even if attacking does actually deal damage above 0.

This bug does not happen if the actor uses a skill with the "Normal attack" enemy, and then uses equipment to change its attack element to "Ice", or whatever attack element the enemy also has.

I am not knowledgeable enough with Ruby to figure out exactly what's causing this. But I at least managed to stumble across a consistent set of instructions to replicate the bug, which I hope helps you, if you decide to try to fix it.

Thanks and good evening.
So for example. If Actor has a skill called "Ice slash" which has a forced "Ice" element, and they fight against some ice elemental with an attack element of "Ice", which causes any attacks with the element "Normal Attack" to have "Ice" element instead. Using the "Ice slash" against that enemy will display a preview of 0 to 0 damage, even if attacking does actually deal damage above 0.
I cannot replicate this. I get damage values consistent with the skill formula and element resistances
Can you provide a demo or screen shot the enemy, skill and anything else you did to show this?
Thanks
I cannot replicate this. I get damage values consistent with the skill formula and element resistances
Can you provide a demo or screen shot the enemy, skill and anything else you did to show this?
Thanks
Strange. But I was also pondering the posibility that it's caused by a different script. I'll have to test some more to land with a culprit.
My apologies for taking your time. I'll report back if I discover something.

Original thread: https://forums.rpgmakerweb.com/threads/show-damage-value-on-enemy.136493/