ESOUI

ESOUI (https://www.esoui.com/forums/index.php)
-   Lua/XML Help (https://www.esoui.com/forums/forumdisplay.php?f=175)
-   -   Does OnPowerUpdate have an equivalent of 'OldValue'? (https://www.esoui.com/forums/showthread.php?t=10446)

Anumaril 02/08/23 10:14 AM

Does OnPowerUpdate have an equivalent of 'OldValue'?
 
As part of the addon I'm making, I want to detect when the player's health decreases if it's decreased by 15% or more. If it does, then I want to have a red overlay flash on the screen to let them know they were hit hard by an attack.

I have the following, but am lacking the critical piece because from all my searching I can't find an equivalent of 'oldValue' for the OnPowerUpdate function. Without a way to detect what the power value was before being hit, I don't see a way of getting this to work:

Code:

if oldValue > powerValue then
        healthLost = oldValue - powerValue
        healthLostPercent = healthLost / powerMax

        if healthLostPercent >= 0.15 then
                BloodUIHitCritical:SetAlpha(1.0)
        end
end

(I saw 'powerEffectiveMax' was connected to OnPowerUpdate, but have yet to find a description *anywhere* as to what it refers to)

Baertram 02/08/23 12:29 PM

GetUnitPower("player", power_type_health)
power_type must be of constants CombatMechanicFlags
h5. CombatMechanicFlags
* COMBAT_MECHANIC_FLAGS_DAEDRIC
* COMBAT_MECHANIC_FLAGS_HEALTH
* COMBAT_MECHANIC_FLAGS_MAGICKA
* COMBAT_MECHANIC_FLAGS_MOUNT_STAMINA
* COMBAT_MECHANIC_FLAGS_STAMINA
* COMBAT_MECHANIC_FLAGS_ULTIMATE
* COMBAT_MECHANIC_FLAGS_WEREWOLF


Just save it in a local variable which was defined outside of your callbackFunction for the event, each time the event fires.

Code:

local oldValues = {}
oldValues[COMBAT_MECHANIC_FLAGS_HEALTH] =  GetUnitPower("player", COMBAT_MECHANIC_FLAGS_HEALTH)
oldValues[COMBAT_MECHANIC_FLAGS_MAGICKA] = GetUnitPower("player", COMBAT_MECHANIC_FLAGS_MAGICKA)
oldValues[COMBAT_MECHANIC_FLAGS_STAMINA] = GetUnitPower("player", COMBAT_MECHANIC_FLAGS_STAMINA)


local function OnPowerUpdate(newValue, powertypeOrCombatMechanicFlag, etc......)
  --do your comparison here etc.
  oldValues[powertypeOrCombatMechanicFlag] = newValue
end


Anumaril 02/11/23 06:23 AM

Thanks Beartram! Works like a charm :)


All times are GMT -6. The time now is 05:20 AM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2014 - 2022 MMOUI