Damage Formula Request (Damage Based On HP Situation)

Vardoger

Warper
Member
Joined
Sep 12, 2015
Messages
1
Reaction score
0
First Language
Portuguese
Primarily Uses
Hi, guys...

I was trying to make a skill that deals more damage according to the target's HP situation, the lower its current HP, the higher is the skill's damage. The problem is that the formula isnt workin. Here's what I'm using (the whole code):

((b.hp / b.mhp) + 1) * a.atk * 3 - b.def * 2The reason I've used that:

"(b.hp / b.mhp)" is where I should get the health situation (ranging from 0.0000... to 1, the later being full HP). Then I add the valor 1 to it. So I can boost the a.atk.
 

So "((b.hp / b.mhp) + 1) * a.atk" means that the maximum boost is something near 100% of that damage.

The problem is that it is not working. In fact the first hit on an enemy is doing way more damage than the subsequent hits on the same enemy. Right after the first hit on the same target, the subsequent hits keep doing the same damage, like a bug.

Where am I doing wrong?
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,098
Reaction score
13,704
First Language
English
Primarily Uses
RMMV
b.hp / b.mhp will always evaluate to 0 because two integer operands will always result in an integer.  And it truncates, rather than rounding.


Try

((b.hp.to_f / b.mhp) + 1).to_i * a.atk * 3 - b.def * 2 
It also follows the mathematical order of operations so it'll do all the multiplications, and then the subtraction.  That may or may not be what you want.  If it's not, you'll need to add some more brackets to force it to do the subtraction at the right point.


Edit: I'm surprised nobody picked up my mistake. Putting the .to_i where I did will pretty much give you what you originally had. Just wrap the whole lot in brackets and add .to_i at the end:

Code:
((b.hp.to_f / b.mhp) + 1 * a.atk * 3 - b.def * 2).to_i
 
Last edited by a moderator:

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

Holy stink, where have I been? Well, I started my temporary job this week. So less time to spend on game design... :(
Cartoonier cloud cover that better fits the art style, as well as (slightly) improved blending/fading... fading clouds when there are larger patterns is still somewhat abrupt for some reason.
Do you Find Tilesetting or Looking for Tilesets/Plugins more fun? Personally I like making my tileset for my Game (Cretaceous Park TM) xD
How many parameters is 'too many'??
Yay, now back in action Happy Christmas time, coming back!






Back in action to develop the indie game that has been long overdue... Final Fallacy. A game that keeps on giving! The development never ends as the developer thinks to be the smart cookie by coming back and beginning by saying... "Oh bother, this indie game has been long overdue..." How could one resist such? No-one c

Forum statistics

Threads
105,857
Messages
1,017,019
Members
137,564
Latest member
McFinnaPants
Top