Status
Not open for further replies.

Mahoken

Veteran
Veteran
Joined
Nov 24, 2013
Messages
41
Reaction score
3
First Language
English
Primarily Uses
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
 

Fernyfer775

Veteran
Veteran
Joined
Oct 6, 2013
Messages
1,318
Reaction score
825
First Language
English
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
 
Last edited by a moderator:

Shaz

Global Moderators
Global Mod
Joined
Mar 2, 2012
Messages
44,160
Reaction score
15,541
First Language
English
Primarily Uses
RMMV
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
Veteran
Joined
Nov 24, 2013
Messages
41
Reaction score
3
First Language
English
Primarily Uses
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
Veteran
Joined
Oct 6, 2013
Messages
1,318
Reaction score
825
First Language
English
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.
 

Shaz

Global Moderators
Global Mod
Joined
Mar 2, 2012
Messages
44,160
Reaction score
15,541
First Language
English
Primarily Uses
RMMV
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.
 
Status
Not open for further replies.

Latest Threads

Latest Posts

Latest Profile Posts

Finally showing some updates again
I think it's ready - Chapter Selection:
unknown.png
On another more gaming topic, I paid 20 bucks for a visual novel to emotionally destroy me. I may write an entry about that.
1638611395177.png
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."

Forum statistics

Threads
117,176
Messages
1,105,169
Members
153,292
Latest member
Drekex
Top