Why is this formula giving me Null damage?

Kes

Veteran
Veteran
Joined
Aug 3, 2012
Messages
22,299
Reaction score
11,712
First Language
English
Primarily Uses
RMVXA
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
 

♥SOURCE♥

Too sexy for your party.
Veteran
Joined
Mar 14, 2012
Messages
693
Reaction score
411
Primarily Uses
The formula is fine. There is probably something else interfering.
 

Kes

Veteran
Veteran
Joined
Aug 3, 2012
Messages
22,299
Reaction score
11,712
First Language
English
Primarily Uses
RMVXA
Any suggestions what that might be?
 

bgillisp

Global Moderators
Global Mod
Joined
Jul 2, 2014
Messages
13,522
Reaction score
14,255
First Language
English
Primarily Uses
RMVXA
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.
 

bgillisp

Global Moderators
Global Mod
Joined
Jul 2, 2014
Messages
13,522
Reaction score
14,255
First Language
English
Primarily Uses
RMVXA
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.
 

Kes

Veteran
Veteran
Joined
Aug 3, 2012
Messages
22,299
Reaction score
11,712
First Language
English
Primarily Uses
RMVXA
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.
 

bgillisp

Global Moderators
Global Mod
Joined
Jul 2, 2014
Messages
13,522
Reaction score
14,255
First Language
English
Primarily Uses
RMVXA
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.
 

Kes

Veteran
Veteran
Joined
Aug 3, 2012
Messages
22,299
Reaction score
11,712
First Language
English
Primarily Uses
RMVXA
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.
 

bgillisp

Global Moderators
Global Mod
Joined
Jul 2, 2014
Messages
13,522
Reaction score
14,255
First Language
English
Primarily Uses
RMVXA
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?).
 

Kes

Veteran
Veteran
Joined
Aug 3, 2012
Messages
22,299
Reaction score
11,712
First Language
English
Primarily Uses
RMVXA
I commented it out and tested, and still got Null.
 

bgillisp

Global Moderators
Global Mod
Joined
Jul 2, 2014
Messages
13,522
Reaction score
14,255
First Language
English
Primarily Uses
RMVXA
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.
 

Kes

Veteran
Veteran
Joined
Aug 3, 2012
Messages
22,299
Reaction score
11,712
First Language
English
Primarily Uses
RMVXA
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.
 

seita

Donn_M
Veteran
Joined
Feb 6, 2013
Messages
2,254
Reaction score
611
First Language
English
Primarily Uses
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)
 

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
31,367
Reaction score
7,676
First Language
German
Primarily Uses
RMMV
I commented it out and tested, and still got Null.
I suggest you give us a screenshot of the skill that results in null damage.
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.
 

Sarlecc

Veteran
Veteran
Joined
Sep 16, 2012
Messages
453
Reaction score
211
First Language
English
Primarily Uses
RMMV
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.
 
Last edited by a moderator:

Warpmind

Twisted Genius
Veteran
Joined
Mar 13, 2012
Messages
936
Reaction score
578
First Language
Norwegian
Primarily Uses
...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.
 
 

Espon

Lazy Creator
Veteran
Joined
Mar 20, 2012
Messages
1,810
Reaction score
192
First Language
Gibberish
Primarily Uses
RMMV
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.

240 - 96 + 58
=

240 - 154 = 86
You can't add 58 to -96 and get -154.  It would be -38.
 
Last edited by a moderator:

Sarlecc

Veteran
Veteran
Joined
Sep 16, 2012
Messages
453
Reaction score
211
First Language
English
Primarily Uses
RMMV
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.
 
Last edited by a moderator:

Tsukihime

Veteran
Veteran
Joined
Jun 30, 2012
Messages
8,564
Reaction score
3,846
First Language
English
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.
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.
Here's some code. I copied the original formula and took out the dots.

Code:
aatk = 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
Here are the results
Code:
"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"
Hp down, damage up
 
Last edited by a moderator:

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Profile Posts

People3_5 and People3_8 added!

so hopefully tomorrow i get to go home from the hospital i've been here for 5 days already and it's driving me mad. I miss my family like crazy but at least I get to use my own toiletries and my own clothes. My mom is coming to visit soon i can't wait to see her cause i miss her the most. :kaojoy:
Couple hours of work. Might use in my game as a secret find or something. Not sure. Fancy though no? :D
Holy stink, where have I been? Well, I started my temporary job this week. So less time to spend on game design... :(
Cartoonier cloud cover that better fits the art style, as well as (slightly) improved blending/fading... fading clouds when there are larger patterns is still somewhat abrupt for some reason.

Forum statistics

Threads
105,868
Messages
1,017,083
Members
137,583
Latest member
write2dgray
Top