WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   UnitHealth refresh (https://www.wowinterface.com/forums/showthread.php?t=58553)

doofus 01-18-21 06:54 PM

UnitHealth refresh
 
Every so often, sometimes as often as 3-4 times a second, I call UnitHealth(), and it seems it is "slow" to update, whereas the standard Blizzard raid frames are much more responsive. Looking at gamepedia it seems there used to be a UNIT_HEALTH_FREQUENT event that was remoived with 9.0.1 - but the point is that somehow the standard Blizz party/raid frames work very responsively.

Are there other API calls to retrieve the latest HP of a unit that I should be using?

Fizzlemizz 01-18-21 07:35 PM

UNIT_HEALTH and UNIT_HEALTH_FREQUENT were rolled into just UNIT_HEALTH.

kurapica.igas 01-18-21 09:16 PM

Normally what your see is just a smooth effect, no other events for the UNIT Health

doofus 01-19-21 07:27 AM

Unfortunately, calling UnitHealth still shows some "old" value when in fact the party/raid frames have already updated fully after a damage or heal, by eye it is even one second delay with just 25ms latency to server, and it happens very often, and not at busy times or places.

That means (to me) that the party frames must be using a different API function to retrieve a unit's HP and update their bars. And I would like to have access to it to if possible?

Oh one more thing. In a party, some players die, and UnitHealth() (and UnitDeadorGhost()) still shows some random value they were at before they died!

Rilgamon 01-19-21 10:07 AM

I'm pretty sure there is an onupdate handler for them?
https://github.com/tomrus88/Blizzard...Frame.lua#L305

doofus 01-19-21 11:06 AM

Looking at this code you have posted:

Code:

function CompactUnitFrame_UpdateHealth(frame)
        local health = UnitHealth(frame.displayedUnit);
        if ( frame.optionTable.smoothHealthUpdates ) then
                if ( frame.newUnit ) then
                        frame.healthBar:ResetSmoothedValue(health);
                        frame.newUnit = false;
                else
                        frame.healthBar:SetSmoothedValue(health);
                end
        else
                PixelUtil.SetStatusBarValue(frame.healthBar, health);
        end
end

It seems the "frame" has some "smoothHealthUpdates" functionality (how is that even determined?), but the actual health value comes from "local health = UnitHealth(frame.displayedUnit);"

So he is calling the same function as I am. I only can suspect that addons have lower priority and UnitHealth behaves differently depending on who the caller is ?

Rilgamon 01-19-21 11:34 AM

There is no "hidden" magic. It's simply updating not on event but onupdate. So it redraws with every single frame.
https://github.com/tomrus88/Blizzard...Frame.lua#L199

doofus 01-19-21 12:54 PM

That's precisely what I do. I am driven off of frame updates. I am at 75% HP, I cast a heal, the UI shows 100% HP, UnitHealth() reads 85% or some other random figure for a few seconds.

Xrystal 01-19-21 04:55 PM

Maybe there is similar situation that UnitLevel has.

https://wow.gamepedia.com/API_UnitLevel
'Note that the value returned by UnitLevel("player") will most likely be incorrect when called in a PLAYER_LEVEL_UP event handler, or shortly after leveling in general. Check the PLAYER_LEVEL_UP payload for the correct level.'

Maybe with UnitHealth you need to use the UNIT_HEALTH event and check the value at that point ? You've not confirmed if you are using UNIT_HEALTH to track health changes. It may be that if you call UnitHealth() and then the health is updated, the screen may show the new value but UnitHealth grabbed the previous value.

Taudier 01-19-21 05:07 PM

Quote:

Originally Posted by doofus (Post 338319)
That's precisely what I do. I am driven off of frame updates. I am at 75% HP, I cast a heal, the UI shows 100% HP, UnitHealth() reads 85% or some other random figure for a few seconds.

do you have SetCVar("predictedHealth",1) ?

doofus 01-19-21 06:53 PM

I do not use the event, my code runs off the screen update.

Definitely there is a timing issue, I call UnitHealth() too quick after casting heal or damage, and I get the wrong value.

But I have also observed the wrong value 3-4 seconds in, so this is not timing.

Unfortunately I tried again just now and could not reproduce it.

I have not knowingly messed with "predictedHealth", but I did mess with it just now and do not know what the proper value should be, 0 or 1?


All times are GMT -6. The time now is 05:24 PM.

vBulletin © 2021, Jelsoft Enterprises Ltd
© 2004 - 2020 MMOUI