What I want to happen is that the attack gets stronger and deals more damage the lower the actor's HP is. My formula is this:
a.atk*4 - b.def*2 + ((a.atk*4 - b.def*2) * (a.mhp - a.hp)/a.mhp)
I tested it against a much weaker enemy and just got Null coming up. The stats involved in the particular instance are:
atk = 60
def = 48
mhp = 622
actual hp = 373
So I work out that formula as follows
240 - 96 + ((240 - 96) * (622 - 373)/622)
=
144 + ((144) * (249)/622)
=
144 + (35856 / 622)
=
144 + 58 = 202
Where am I going wrong?
Thanks
Why is this formula giving me Null damage?
● ARCHIVED · READ-ONLY
-
-
The formula is fine. There is probably something else interfering.
-
Any suggestions what that might be?
-
Do you have a damage block script? There are some that block all damage below x damage, and if that enemy has a damage block in effect, you can get NULL then.
-
No damage block script.
-
Ok, I tested the formula you posted in my game and it works. I think something must be overwriting how make_item_damage works in the game. Maybe try CTRL+SHIFT+F and seeing if make_item_damage is changed somewhere? Otherwise, the only other think I could think of is the enemy has an element rate of 0% to whatever the attack type is that you used.
-
make_item_damage is not found anywhere. Is that exactly how it would appear? Because the wording in your post implies that it should be somewhere.
No, it's not a 0% rate issue. The only element being applied is 'Slash' (which is the element a sword has) and there is no weakness to it in the enemy I chose for testing. -
Sorry, make_damage_value. I was going off of memory and adding something else to a script when I posted that so hadn't double-checked that it was correct.
-
So when I run that this is what I get.

It looks as if a few scripts change that. I have no idea what I'm supposed to do with the information here, though. -
DuncanS skill growth overwrote the default behavior is what that tells me (by the overwrite method note above it). Can you comment out the script or short term disable it and see if it works now? If so we found what was causing it (though as to how to fix that...beyond me I'm afraid, but maybe another poster can help from there?).
-
I commented it out and tested, and still got Null.
-
Hmmm...I'm stumped here. Only thing I can think of is it is one of the aliased methods then. If you comment them out one by one, you should be able to find the error? Otherwise....I haven't the foggiest.
-
Okay, that sounds like a big job, and in my time zone it's getting late, so I'll leave that until tomorrow.
Thanks for your help. -
Don't have much experience with the battle system, but you may want to try a very generic formula and see if that returns a null, then build up from there.
a.atk
a.atk*4
a.atk*4 - b.def*2
Then try this to see if it returns the right value at all for the following:
a.mph
a.hp
(a.mhp - a.hp)/a.mhp
a.atk*4 - b.def*2 + ((a.atk*4 - b.def*2) * (a.mhp - a.hp)/a.mhp) -
I suggest you give us a screenshot of the skill that results in null damage.I commented it out and tested, and still got Null.
It might be something else (like a typo in the skill's damage box that you corrected when rewriting the formula here), and we need more data to find the cause. -
The script that gives you the null pop up is Yanfly's battle engine.
I have tested your formula with much lower enemy def and it will hit however see below.
It looks like to me that the damage is not increasing with lower actor hp.
Try this formula: a.atk*4+ (a.atk*4 *(a.mhp - a.hp))/a.mhp - b.def*2
With this my actor started with 23 attack and 2298 hp. Enemy had 48 def.
My start hits were null.
At 2000 hp it went to 6 damage.
At 661 hp it went to 61 damage.
Edit: Warpmind is correct about the parentheses for your formula. -
...The error is actually very, very simple.
To get your formula to work as intended, try the following:
(a.atk*4 - b.def*2) + ((a.atk*4 - b.def*2) * (a.mhp - a.hp)/a.mhp)
Very basic mathematics - Multiplication, Division, Addition, Subtraction, in that order. Your original formula works out, using your own numbers from the top, as the following:
240 - 96 + ((240 - 96) * (622 - 373)/622)
=
240 - 96 + ((144) * (249)/622)
=
240 - 96 + (35856 / 622)
=
240 - 96 + 58
=
240 - 154 = 86
So, with the formula as written, Please Excuse My Dear Aunt Sally, the calculations do not increase the damage dealt with the battler's lost hit points, but instead increases the enemy's defense.
As for why the damage drops from 86 to Null, I am less sure about - but check your parentheses.
-
Only thing I can think of is maybe one of the scripts you're using is rounding off integers, although that wouldn't explain the null pops.
You can't add 58 to -96 and get -154. It would be -38.240 - 96 + 58
=
240 - 154 = 86 -
Espon think you have just explained why it comes up as null.
All of the hp damage checks do not take into account negative damage thus Yanfly's battle engine will display the damage as being null. At least this is my understanding of it. -
Can you just print out the result of the damage formula?
class RPG::UsableItem::Damage def eval(a, b, v) p [Kernel.eval(@formula), 0].max * sign endendAnd if it crashes, even better.Here's some code. I copied the original formula and took out the dots.So, with the formula as written, Please Excuse My Dear Aunt Sally, the calculations do not increase the damage dealt with the battler's lost hit points, but instead increases the enemy's defense.
Code:Here are the resultsaatk = 100bdef = 50amhp = 200def run(aatk, bdef, amhp,ahp) return aatk*4 - bdef*2 + ((aatk*4 - bdef*2) * (amhp - ahp)/amhp)end10.downto(0) do |hp| hp *= 10 val = run(aatk, bdef, amhp, hp) p "HP: %d, Damage: %d" %[hp, val]end
Code:Hp down, damage up"HP: 100, Damage: 450""HP: 90, Damage: 465""HP: 80, Damage: 480""HP: 70, Damage: 495""HP: 60, Damage: 510""HP: 50, Damage: 525""HP: 40, Damage: 540""HP: 30, Damage: 555""HP: 20, Damage: 570""HP: 10, Damage: 585""HP: 0, Damage: 600"