How do I make this formula work in the battle formula

● ARCHIVED · READ-ONLY
Started by Mahoken 6 posts View original ↗
  1. I'm trying to make this basic attack formula work, but it keeps inflicting an insane amount of damage instead. I have the formula like this in RPG maker: a.atk * (100 / 100 + b.def)

    If the user's ATK was 30, and the enemies defense was 20, the enemy would take 25 damage.

    30 * (100 / 100 + 20) => 30 * (100 / 120) => 30 * (.83) = 25

    Instead, it just inflicted 630 damage. What am I doing wrong when it comes to this formula? 

    Here's the formula I'm trying to copy vvvvvvv

    Untitled.png
  2. I believe this is how the maker is reading your equation. Let me try to see if I can figure out a way to re-write it.

    math.png

    Try writing it like this:

    30 * (100/(100+15)) <---that netted me about 26-27 damage.

    math2.png
  3. Yep - it would do the 100/100 first, giving 1, then add 20, giving 21, and then multiply by 30, giving 630, because of the order of mathematical operations.

    If you want it to do the 100 + b.def first, you need to put that in brackets.  In fact, since b.def is probably an integer, you likely will also need to convert to a float or (100 / (100 + b.def)) will end up as 0.  And THEN you'll need to convert back to an integer at the end.

    So try the following, in order, until it gives a value you're expecting:

    a.atk * (100 / (100 + b.def))

    if that gives you 0, try this:

    a.atk * (100.0 / (100 + b.def))

    if that gives you a number with a decimal part, try this:

    (a.atk * (100.0 / (100 + b.def))).to_i
  4. Thank you so much, both of you. The first kept giving me, "Null". I tried the second formula that was recommended, and it worked. It gave the right damage for both the enemy and the user. Thank you :)

    This is what worked: a.atk * (100.0 / (100 + b.def))
  5. You could also try:

    damage = [a.atk * (100.0 / (100 + b.def)), x].max 

    Where "x" = the minimum damage you want that attack to ever do.

    For example, instead of "null" or "zero" damage, you can put a "1" there. :]

    Glad we could help.
  6. This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.