Difference between revisions of "GetActorValuePercentage - Actor"

From the CreationKit Wiki
Jump to navigation Jump to search
imported>Terra Nova2
m
imported>Terra Nova2
m (Add another version for percentage, but doesn't take in account for buffs.)
Line 20: Line 20:


== Examples ==
== Examples ==
<source lang="papyrus">
; Obtain the AV percentage of either health, stamina or magicka. This version does not take in account for buffed stats.
Float Function GetActorValuePercentageEX(Actor akActor, String asValueName)
Float CurrentHealth = akActor.GetActorValue("asValue")
Float BaseHealth = akActor.GetBaseActorValue("asValue")
Float HealthPercent = (CurrentHealth / BaseHealth) * 100
return HealthPercent
EndFunction
GetActorValuePercentageEX(Game.GetPlayer(), "health")
; A health value of 930/930 will come out as 100.0 %
; A health value of 53/930 will come out to be about 5.6 %
</source>
Get the total (max) VALUE of a stat AFTER buffs are calculated:
Get the total (max) VALUE of a stat AFTER buffs are calculated:
<source lang="papyrus">
<source lang="papyrus">

Revision as of 17:29, 27 August 2014

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)
  return GetActorValuePercentage(asValueName)
EndFunction

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

; Obtain the AV percentage of either health, stamina or magicka. This version does not take in account for buffed stats.
Float Function GetActorValuePercentageEX(Actor akActor, String asValueName)
Float CurrentHealth = akActor.GetActorValue("asValue")
Float BaseHealth = akActor.GetBaseActorValue("asValue")

Float HealthPercent = (CurrentHealth / BaseHealth) * 100

return HealthPercent
EndFunction 

GetActorValuePercentageEX(Game.GetPlayer(), "health")
; A health value of 930/930 will come out as 100.0 %
; A health value of 53/930 will come out to be about 5.6 %


Get the total (max) VALUE of a stat AFTER buffs are calculated:

; 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)


Get a percent of the total (max) value of a stat AFTER buffs are calculated:

; 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 = TStatPV(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

Notes

  • The examples concerning calculations after buffs maybe off. The second one with getting the percents is definitely not right. More testing needed.
  • Upon further testing, this function doesn't return the correct value under certain conditions. It is therefor not reliable.

See Also