Thread Tools Display Modes
02/08/23, 10:14 AM   #1
Anumaril
AddOn Author - Click to view addons
Join Date: Sep 2018
Posts: 14
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)
  Reply With Quote
02/08/23, 12:29 PM   #2
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,912
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

Last edited by Baertram : 02/08/23 at 12:36 PM.
  Reply With Quote
02/11/23, 06:23 AM   #3
Anumaril
AddOn Author - Click to view addons
Join Date: Sep 2018
Posts: 14
Thanks Beartram! Works like a charm
  Reply With Quote

ESOUI » Developer Discussions » Lua/XML Help » Does OnPowerUpdate have an equivalent of 'OldValue'?

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off