SetModDamageRestoreForceAV

Post » Fri Apr 18, 2014 11:25 am

I think I understand how all the Actor Value functions work in terms of their effects on the current and maximum values, but I still have a problem with practical use.

I want to apply a short-term buff to the player's health.

Damage/Restore/ForceActorValue aren't useful here, as there's only a benefit if the maximum health is increased.

SetActorValue will fill the health when used, which is a bit more generous than I'd like.

ModActorValue is fine for the increase, but if I remove the same amount at the effect's expiry, it might kill the player. This is only an issue with Health, as Magicka and Stamina can fall to zero without the same negative consequences. If the amount subtracted is reduced to keep the player alive, then the maximum health retains the difference, and the temporary boost just became permanent (or part of it, at least).

It looks like I need to use ForceActorValue to establish a minimum level of health that's high enough for a subsequent ModAV to leave some in the pool, or is there a better way?
User avatar
Chenae Butler
 
Posts: 3485
Joined: Sat Feb 17, 2007 3:54 pm

Post » Fri Apr 18, 2014 1:39 pm

Assuming ModActorValue using a negative number lowers both the current and maximum health by the same amount (as you suggest), this approach should work -- it will maintain the same percentage of health the actor currently has, while reducing it by the same amount you originally increased it by:

property float healthModifier = 60.0 auto ;example value (say you buffed health by 60 points)int currentVal = target.GetActorValue("Health")int currentPct = target.GetActorValuePercentage("Health")int currentMax = (currentVal / currentPct)  ;get max value including any current buffsint newMax = currentMax - healthModifierint newVal = newMax * currentPct ;new target value (to maintain the same percent health as current)SetActorValue("Health", newVal + healthModifier)ModActorValue("Health", -healthModifier)

Example:

You modified actor's health by 60, raising their max health to 160.

They now only have 40 health left.

CurrentVal = 40

CurrentPct = 0.25

CurrentMax = 160

NewMax = 100 (160 - original modifier of 60)

NewVal = 25 (100 * 0.25)

SetActorValue( 25 + original modifier [60] ) ==> 85 health

ModActorValue( -60 ) ==> 100 max health restored, actor now has 25 health, which maintains same percent (25%) as before the change

User avatar
Devin Sluis
 
Posts: 3389
Joined: Wed Oct 24, 2007 4:22 am

Post » Fri Apr 18, 2014 7:28 am

I like that method. It only removes the original amount if the health remains at the maximum, but on the other hand, you're losing the same percentage you gained (assuming it was maxed at that point, too). I can't see users complaining about it.
User avatar
Tikarma Vodicka-McPherson
 
Posts: 3426
Joined: Fri Feb 02, 2007 9:15 am


Return to V - Skyrim