Jump to content
ℹ️ Intermittent Download History issues ×

How to get percent of health


Ranokoa

Recommended Posts

I tried looking at the list of functions, and I know there is a way to... I think I'm over complicating things (or actually, not looking at the simple but more complicated way.. if that makes sense.) but anyways.

 

I need to have the script get the health of the referenced called upon, and then do something when that health is 50%.

 

I looked at every function there is and couldn't find a single thing that did exactly this. I wish there was a GetAV**Percent or something, or even GetPercent [set Short Reference] or something... I'm a bit confused.

 

The script I'm working on is rather simple. It sets a short to the base health of the NPC it's attached to, and what I need is for it to read when it is at half health, at which point it disables a referenced object, which a whole big lot of items are Opposite Parent Enable State. (mostly lights) I don't want to, but if absolutely impossible otherwise I can simply put a timer on it. The only problem is if the player is either cheating or using god like items it really will destroy the realism even worse than the fact they would be cheating, because the event has potential to not happen (or if it does anyways it's extremely screwed up) if the NPC dies too quickly.

 

No.. A timer wouldn't work... I suppose if all else fails I can just use DoOnce to resurrect the NPC only one time, start the event, then add the item he is supposed to drop via script on the off chance the player somehow loots him before he returns. (I'd need it to be a realistically timed resurrection, not just OOPS he's alive again and didn't even stand up but is standing)

 

Wow... My head is truly lacking the ability to communicate properly today. idk. I gots problems I suppose this day.

 

Be well, sleep well, fight well, live long.

~Ranokoa

Link to comment
Share on other sites

Here's an OBSE function that'll return a short containing the current health percentage, including anyy fortify health effects that are boosting the player's stats:

Scn GetHealthPercentage

Short HealthPerc

Begin Function {}

Let HealthPerc := GetAV Health / GetBaseAV Health * 100
SetFunctionValue HealthPerc

End

 

Using it is easy:

If eval(Ref.Call GetHealthPercentage <= 50)
;code
EndIf

 

 

Or non OBSE:

If (Ref.GetAV Health / Ref.GetBaseAV Health * 100) <= 50
;code
EndIf

Link to comment
Share on other sites

Thank god of that last segment. I don't know if this particular mod that I'm working on, which is not for myself, is allowed OBSE, so as a general rule I avoid it.

 

I am no master scripter by any means, but I have no idea why I couldn't think of this. I'm just brain blocked today. Bleh.

 

Anyways, thank you very much my good friend.

 

Be well, sleep well, fight well, live long.

~Ranokoa

 

EDIT: Post number 1,111. How often do people catch that? lol

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...