Quantcast
Beginner - Page 3 - WoWInterface
Thread Tools Display Modes
04-11-18, 01:20 PM   #41
GreyFox777
A Cliff Giant
Join Date: Jan 2017
Posts: 74
Hey guys, why my health color are not refreshing automatically if entering AFK?

local function UpdateHealthColor(health, unit, cur, max)
health:RegisterEvent('PLAYER_FLAGS_CHANGED')
local r, g, b, t
-- local afk = UnitIsAFK(unit)

if(health.disconnected and health.colorDisconnected or UnitIsDeadOrGhost(unit)) then
health:SetValue(max)
t = colors.disconnected
elseif(health.colorTapping and not UnitPlayerControlled(unit) and UnitIsTapDenied(unit)) then
t = colors.tapped

elseif UnitIsAFK(unit) then
r, g, b = 1, 0, 0
health:SetScript('OnEvent', UpdateHealthColor)

elseif(health.colorSmooth) then
r, g, b = health.__owner.ColorGradient(cur, max, unpack(colors.smooth))
else
t = colors.health
end

if(t) then
r, g, b = t[1], t[2], t[3]
end

if(b) then
health:SetStatusBarColor(r, g, b)
end
end
  Reply With Quote
04-11-18, 02:16 PM   #42
Kkthnx
A Cobalt Mageweaver
 
Kkthnx's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2011
Posts: 244
Originally Posted by GreyFox777 View Post
Hey guys, why my health color are not refreshing automatically if entering AFK?

local function UpdateHealthColor(health, unit, cur, max)
health:RegisterEvent('PLAYER_FLAGS_CHANGED')
local r, g, b, t
-- local afk = UnitIsAFK(unit)

if(health.disconnected and health.colorDisconnected or UnitIsDeadOrGhost(unit)) then
health:SetValue(max)
t = colors.disconnected
elseif(health.colorTapping and not UnitPlayerControlled(unit) and UnitIsTapDenied(unit)) then
t = colors.tapped

elseif UnitIsAFK(unit) then
r, g, b = 1, 0, 0
health:SetScript('OnEvent', UpdateHealthColor)

elseif(health.colorSmooth) then
r, g, b = health.__owner.ColorGradient(cur, max, unpack(colors.smooth))
else
t = colors.health
end

if(t) then
r, g, b = t[1], t[2], t[3]
end

if(b) then
health:SetStatusBarColor(r, g, b)
end
end
First off a really good practice is to keep your code clean and readable. Second, are you using frequentUpdates?

Here is your code in ghostbin
https://ghostbin.com/paste/ukhcu

Maybe you need to run Health.PostUpdate = UpdateHealthColor? I don't member really just assuming atm. Going to look into it when I get home though for you.
__________________
Success isn't what you've done compared to others. Success is what you've done compared to what you were made to do.
  Reply With Quote

WoWInterface » Featured Projects » oUF (Otravi Unit Frames) » Beginner

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