HP and ATK correlation script/formula?

● ARCHIVED · READ-ONLY
Started by atimms00 8 posts View original ↗
  1.  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?
  2. ((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.
  3. 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.
  4. Try this:

    ((a.hp.to_f / a.mhp.to_f) * a.atk.to_f) * 4- b.def* 2
  5. whitesphere said:
    Try this:

    ((a.hp.to_f / a.mhp.to_f) * a.atk.to_f) * 4- b.def* 2
    This worked perfectly. Thanks a ton to both of you for your help!
  6. I thought that the .to_f might be needed, but wasn't sure. Thanks whitesphere for fixing that!
  7. to_f is only needed for the division. And only one of them
  8. 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.