RMMV Damage Formula Issues. Math not mathing?

I'm playing around with different formulas until I settle on what I want, but I want to start with smaller numbers. I've been reading this is kind of difficult to do, but I don't understand why and I can't find a thread that makes it make sense?

Here's a formula I'm using:
Code:
(a.atk - b.def) + (a.atk + ((a.level + a.atk) / 8) + 1)

Here's an example of one enemy:
Attack: 30; Defense: 20

Player:
Level: 5; Attack: 24; Defense: 20; Weapon: 6 Attack

My quick math:
Step 1: (30 - 20) + (30 + ((5 + 30) / 8) + 1)
Step 2: 10 + (30 + (35 / 8) + 1)
Step 3: 10 + (30 + (4.375) + 1) <- I assume 4.375 rounds down to 4?
Step 4: 10 + 35 = 45 Damage with a 10% variance results in 40-50 Damage

Tested multiple times. Works!

Enemy 2:
Attack: 40; Defense: 40; (I've started exaggerating numbers for testing)

My quick math, from enemy perspective:
Step 1: (40 - 20) + (40 + ((0 + 40) / 8) + 1)
Step 2: 20 + (40 + (40 / 8) + 1)
Step 3: 20 + (40 + (5) + 1)
Step 4: 20 + 46 = 66 Damage with a 10% variance results in 60-73 Damage

RPG Maker MV Result: 0 damage????

How is this possible? The first enemy can deal damage, but the second can't. No weird traits.
Greetings!

I'm not seeing any issue with just the data you've offered, but assuming the damage formula is entered correctly for enemy #2 (may very well be you have a typo, but I can't tell without screenshots), then your issue doesn't have anything to do with the math or enemy stats.

It can be a variety of things though. Are your enemies using the same exact Skill to strike the player battler? If not, there may be an issue elsewhere in the Skill's setup. This is the first thing I would look at.

You say no weird traits, but that could mean anything. Does your player battler have an elemental resistance of 100%, for example? That would reduce damage dealt to 0. If not the battler itself, what about their equipment?

Of course, if you are using plugins, there could be some sort of conflict. I would first check your Skills in the database, however.

Hope this helps,
-Niniann
It appears to be an issue with a.level, as soon as I remove it their damage comes back. Curiously though, one enemy did work and then suddenly stopped working.

Just tried a simple a.level + 1, and sure enough, 0 damage. As soon as a.level is removed, it will do 1 damage consistently. Why a.level wouldn't just default to 0 instead of forcing the entire value to read 0 is beyond me.

Solution:
Code:
(a.atk - b.def) + (a.atk + ((a.isActor() ? a.level : 0 + a.atk) / a.isActor() ? 8 : 4) + 1)

It's possible to check for an actor, if an actor is using this skill, use level, if not, 0. Tested and working.
Why a.level wouldn't just default to 0 instead of forcing the entire value to read 0 is beyond me.
that is because a.level does not exist for enemies (NIL error).

and the RM's are programmed that any programming error like a NIL-result will cause zero damage in the damage evel, just to prevent a crash (which would normally happen on an NIL value)

Original thread: https://forums.rpgmakerweb.com/threads/rmmv-damage-formula-issues-math-not-mathing.179029/