GetActorValuePercentage - Actor

From the CreationKit Wiki
Revision as of 00:16, 24 June 2013 by imported>Phinix (→‎See Also)
Jump to navigation Jump to search

Member of: Actor Script

Gets the specified actor value from the actor as a percentage of its maximum value (from 0 to 1).

Syntax

float Function GetActorValuePercentage(string asValueName) native
float Function GetAVPercentage(string asValueName)

Parameters

Return Value

The value of the requested actor value as a percentage of its maximum value. If 0, then the actor value is at its minimum. If 1, then the actor value is at its maximum.

Examples

; returns Actor's total possible stat value (after buffs)
; stat 1 = health, stat 2 = magicka, stat 3 = stamina
float Function GetBuffedActorValue(Actor starget, int stat)
  if stat == 1
    return (starget.GetActorValue("Health") / starget.GetActorValuePercentage("Health"))
  elseif stat == 2
    return (starget.GetActorValue("Magicka") / starget.GetActorValuePercentage("Magicka"))
  elseif stat == 3
    return (starget.GetActorValue("Stamina") / starget.GetActorValuePercentage("Stamina"))
  endif
EndFunction

; add the above function to your script then call it on an actor,
; for example to get the player's max health value after buffs:

float thbuffed = GetBuffedActorValue(Game.GetPlayer(),1)
Debug.Notification("Players max buffed health = "+thbuffed)


; returns requested percent of Actor's total possible stat value after buffs.
; stat 1 = health, stat 2 = magicka, stat 3 = stamina
; percent must be in decimal form, ie 25%: percent = 0.25, 100%: percent = 1, etc.
float Function TStatPV(Actor starget, float percent, int stat)
  if stat == 1
    return ((starget.GetActorValue("Health") / starget.GetActorValuePercentage("Health")) * percent)
  elseif stat == 2
    return ((starget.GetActorValue("Magicka") / starget.GetActorValuePercentage("Magicka")) * percent)
  elseif stat == 3
    return ((starget.GetActorValue("Stamina") / starget.GetActorValuePercentage("Stamina")) * percent)
  endif
EndFunction

; add the above function to your script then call it on an actor,
; for example to get 20% of the player's max health value after buffs:

float phbuffed = TStatPercent(Game.GetPlayer(),0.20,1)
Debug.Notification("20% of players max buffed health = "+phbuffed)


; Obtain the player's current health percentage value
float playersHealth = Game.GetPlayer().GetActorValuePercentage("health")
if (playersHealth > 0.5)
  Debug.Trace("The player has over half their health left")
endIf


; Obtain Bob's current health actor value
float bobsHealth = Bob.GetAVPercentage("Health")
if (bobsHealth < 0.1)
  Debug.Trace("Bob has less then 10% health remaining")
endIf

See Also