HP and ATK correlation script/formula?

atimms00

Warper
Member
Joined
Nov 6, 2014
Messages
3
Reaction score
1
First Language
English
Primarily Uses
 I'm trying to find a way to have the percentage of HP that the user has correlate with how strong their attack is.

Ex.- Player A has 100% HP, so they use 100% of their ATK skill in the standard formula (a.atk * 4 - b.def * 2). However, if Player A has only 47% HP, they only use 47% of their ATK skill in the standard formula. 

I've been toying with it for two days, looking up different posts and articles, and I can't find a way to correlate the two. If this is too complicated, I would be completely okay with this: a.atk is 100% as long as a.hp is 51%+; a.atk is 50% as long as a.hp is 49%-. (I also have an idea for a skill that would inverse this, i.e.- skill that does more damage when HP is critical).

I hope this wasn't too much information. Can anyone help me out?
 

bgillisp

Global Moderators
Global Mod
Joined
Jul 2, 2014
Messages
13,522
Reaction score
14,255
First Language
English
Primarily Uses
RMVXA
((a.hp / a.mhp) * a.atk) * 4 - b.def * 2 should do it. The a.hp / a.mhp calculates the percent of HP you have, then takes that times your attack, then multiplies that number by 4.

Edit: There is a chance that might give you 0 when the HP is < 100%. If that happens let me know, we will need to convert the value from a.hp / a.mhp to a float to use it then.
 
Last edited by a moderator:

atimms00

Warper
Member
Joined
Nov 6, 2014
Messages
3
Reaction score
1
First Language
English
Primarily Uses
Thanks a ton for your help. I was testing it, and as soon as the HP< 100%, attacking didn't deal any damage, like you said.
 

whitesphere

Veteran
Veteran
Joined
Mar 14, 2014
Messages
1,688
Reaction score
784
First Language
English
Try this:

((a.hp.to_f / a.mhp.to_f) * a.atk.to_f) * 4- b.def* 2
 

bgillisp

Global Moderators
Global Mod
Joined
Jul 2, 2014
Messages
13,522
Reaction score
14,255
First Language
English
Primarily Uses
RMVXA
I thought that the .to_f might be needed, but wasn't sure. Thanks whitesphere for fixing that!
 

Tsukihime

Veteran
Veteran
Joined
Jun 30, 2012
Messages
8,564
Reaction score
3,846
First Language
English
to_f is only needed for the division. And only one of them
 

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
31,365
Reaction score
7,675
First Language
German
Primarily Uses
RMMV
Or you could simply have used the formula

Code:
a.hp*a.atk*4/a.mhp - b.def*2
The to-float is only needed if you need to carry values below 1.00 into the next part of the calculation - if you do the division last, it is not needed.
 

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

Latest Threads

Latest Posts

Latest Profile Posts

Couple hours of work. Might use in my game as a secret find or something. Not sure. Fancy though no? :D
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'??

Forum statistics

Threads
105,863
Messages
1,017,053
Members
137,571
Latest member
grr
Top