Is my damage formula not working?

Hiya. I'm creating a simple community engine so that people can create Pokémon JRPGs in which you play as Pokémon instead of trainers. I've gotten most of the skills down, but for some reason I don't seem to do damage to enemies in testing.


Here is the damage formula according to Bulbapedia:

Spoiler
36a22deaa0.png



So, for example here is what I have for the move "Tacke":

Spoiler
125eb05cf5.png



The damage formula for "Tackle" is:


(((2 * level + 10)/250) * (a.atk/b.def) * 50 + 2) * a.element_rate(20) * (93/100)


"Level" is level 30. User's attack is 43. Enemy's defense was modified to be 1 (and I still can't do damage). The "50" is the move's base power. "a.element_rate(20)" is for the element "Normal STAB", which is 150% for the class the user is. This accounts for STAB (same-type attack bonus), meaning damage should be 150% of normal if applicable (but not for "Tackle" here). The last part is coupled with the move's Variance of 7% to account for "random ∈ [0.86, 1]", which is close enough to the official thing.


My user's class HIT is + 100%, too. And I thought we didn't have to list EVA for anyone.


The result is, every time I use any move, it always says "Enemy X took no damage!" What am I doing wrong?
You need a.level, not level. As it is, level doesn't exist, so it is treating it as 0, and 0 times anything is 0. Hence the no damage.


Also, note that enemies don't have levels by default, so this formula will not do any damage if used by enemies! You'll need an enemy level script to fix that.
You need a.level, not level. As it is, level doesn't exist, so it is treating it as 0, and 0 times anything is 0. Hence the no damage.



I knew it would be something stupid to miss, like that. 😛 Thanks!


Update: I went as far as to replace all variables with numbers, and I'm still doing no damage. I did the math on a calculator and I should be doing about 22 damage. I'm consistently doing zero.


-----


Update 2: It seems like there's some rounding going on BEFORE the final damage output, because before I multiply STAB or the "93/100" Variance adjustment, I'm getting a damage of "2" when I should be getting a "9". (Tested Skill "Twineedle" for this, not "Tackle".) I did the math over and over and played around with syntax.


Between things like rounding issues and especially the 100-character damage formula limit, it's no wonder nobody ever makes a Pokémon game-- or especially does anything at all without scripts. Sheesh!


If I'm getting any scripts, it's to fix rounding and to make the 100-character cap bigger. Nothing else. I want future users of this engine to be able to modify the details for moves without knowing ANYTHING about modifying scripts. User-friendliness and flexibility is the right way.
RM uses integer numbers, which means that unless you specifically order it not to all partials are dropped.


So the calculation goes like 5/4 = 1 (dropping the .25)


You need to reorder the formula in a way that the divisions, especially the /250, happens as late as possible. Because for any level below 120 the first part of the formula will return zero, making the base damage the +2


try


((2*a.level+10)*a.atk/b.def /5 +2) * a.element_rate and so on


Mathematically that is exactly the same formula as you used, it just combines the needles fixed operations and reorders them to cause as few drops as possible (multiplying by 50 and dividing by 250 is the same as dividing by 5)
try


((2*a.level+10)*a.atk/b.def /5 +2) * a.element_rate and so on


Mathematically that is exactly the same formula as you used, it just combines the needles fixed operations and reorders them to cause as few drops as possible (multiplying by 50 and dividing by 250 is the same as dividing by 5)



Sounds like something I can try, but I think damage is still likely to be at least a little less than it should be for some Skills.

RM uses integer numbers, which means that unless you specifically order it not to all partials are dropped.



Is there a way to make RM not round down until the final result? That's what I'm going to spend my time looking for today...
Check the attack and defense values of your characters in the database. You may have to readjust the formula to take high defense into account. If your characters default defense values are high and the attack value is lower, regardless of how you have it set up, your going to get that 0 damage being done. 


At least that's been my issue in the past. 


Not sure how to do this in XP, but use a comparison formula that checks the value of both characters attack and defense based on that formula. If defense is higher than the attack value,

  1. be okay with it (sometimes, weaker characters, should not be allowed to do damage depending on how you set up your world)
  2. readjust your characters attack value, or lower the opponents defense in the database
  3. give a default value (ie. the opponent just takes the attack value and ignoring defense)
  4. use a new formula altogether
Is there a way to make RM not round down until the final result? That's what I'm going to spend my time looking for today...



You can prevent the rounding by making at least one of the operands a floating point number. You can do that by writing static numbers with a decimal point (e.g. 1/5 would be 0 while 1.0/5 would be 0.2) or by using .to_f.


For example:


(((2 * a.level + 10) / 250.0) * (a.atk / b.def.to_f) * 50 + 2) * a.element_rate(20) * 0.93
You can prevent the rounding by making at least one of the operands a floating point number. You can do that by writing static numbers with a decimal point (e.g. 1/5 would be 0 while 1.0/5 would be 0.2) or by using .to_f.


For example:


(((2 * a.level + 10) / 250.0) * (a.atk / b.def.to_f) * 50 + 2) * a.element_rate(20) * 0.93



Thanks a bunch! So then here is my resulting formula: ((2*a.level+10)*a.atk*50/b.def.to_f/250.to_f+2)*a.element_rate(20)*0.93


Is there any way I can cut down characters further? I'm at 71 of 100 and sometimes I need to use the result of this formula in a separate formula to calculate a percentage of HP drainage.

Original thread: https://forums.rpgmakerweb.com/threads/is-my-damage-formula-not-working.59861/