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

Global Moderators
Global Mod
Joined
Mar 2, 2012
Messages
43,647
Reaction score
15,279
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:

Latest Threads

Latest Posts

Latest Profile Posts

I really need to buy a new mouse. Mine's keeps double-clicking and makes me waste A LOT of time eventing
How come there's no spooktober game jam? I thought horror maker games were some of the most popular genre out there...
"I didn't know X song was about that!" Uh... why? Do you not listen to the lyrics? I mean, I guess that makes sense. We live in a world where nobody listens, but everyone wants to be heard.
Coding class: Python
Game dev work: Javascript
Result: AHHH!!! Writing program for an assignment and having it crash and burn because I used Javascript syntax or format. Or having my game die on me because of a python call :yswt:
Can we make it so whenever a banned user tries to use their account whilst banned, the forum should redirect to this

Forum statistics

Threads
115,835
Messages
1,093,330
Members
151,027
Latest member
Mansfield40matt
Top