# How do I make this formula work in the battle formula

Status
Not open for further replies.

#### Mahoken

##### Veteran
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

#### Fernyfer775

##### Veteran
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.

Try writing it like this:

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

Last edited by a moderator:

#### Shaz

##### Global Moderators
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

#### Mahoken

##### Veteran
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))

#### Fernyfer775

##### Veteran
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. :]

#### Shaz

##### Global Moderators

Status
Not open for further replies.

### Latest Profile Posts

I think it's ready - Chapter Selection:
On another more gaming topic, I paid 20 bucks for a visual novel to emotionally destroy me. I may write an entry about that.
Reading about metaverses recently. I can totally imagine myself in the future, logging in with VR glasses to a virtual beach villa sitting in a virtual chair, with a virtual laptop facing the sea...coding 16-bit RM.
Mod name: "[Game name] Gameplay Overhaul"
What they actually mean: "Here is a mod that makes the game harder."