• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

SetUnitLifePercentBJ to Natives or a Formula?

Status
Not open for further replies.
Level 14
Joined
Jul 26, 2008
Messages
1,009
So using the SetUnitLifePercentBJ is really simple to use, but it's a BJ and it likely causes leaks from the natives I've been looking at.

JASS:
    call SetUnitLifePercentBJ( GetTriggerUnit(), ( GetUnitLifePercent(GetSpellTargetUnit()) - 1 ) )

However, just to set it to natives seems like a huge chore. I'm looking at the coding and my head hurts. First I need to turn it into a native, which requires turning RMaxBJ into a native, which requires an if, though since it uses reals it shouldn't leak and I might just be able to use it leak free.

Then I have to turn GetUnitLifePercent into a native because it's part of the percent I need to input for RJMaxBJ, which means turning GetUnitStatePercent into a native, which requires the use of some locals and ifs and whatnot, which is a lot of thinking and rearranging.

There's gotta be an easier way! I'm not a math buff, so maybe someone could tell me how you would decrease an enemies life by a percentage. Like -1%.

I got this far in before realizing how convoluted it would make my coding to do all this, and I knew I wasn't the only one who needed an easier way.

JASS:
SetUnitState(target, UNIT_STATE_LIFE, GetUnitState(target, UNIT_STATE_MAX_LIFE) * RMaxBJ(0,) * 0.01)
 
It's a rule of three:

MaxLife = 100%
Life = x%

If you want to calculate how much is x% of the unit's max life:
Life = MaxLife*x/100

But the life-setting native can only SET. So if you want to remove life you'll have to do like this:

call SetUnitState( <unit>, UNIT_STATE_LIFE, GetUnitState(<unit>, UNIT_STATE_LIFE) - <amount> )
 
Status
Not open for further replies.
Top