Thread Tools Display Modes
08-03-14, 11:43 PM   #1
Lybrial
A Flamescale Wyrmkin
AddOn Compiler - Click to view compilations
Join Date: Jan 2010
Posts: 120
Lua get Buff duration

Hi,

i want to return how much time left on my buff.

i startet with:

Code:
function()
    local value = select(15, UnitBuff("player", "Blood Shield")) or 0
    
end
But now i dont know how to go on.
Can somebody give a hint?
  Reply With Quote
08-04-14, 12:18 AM   #2
Rilgamon
Premium Member
 
Rilgamon's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Sep 2009
Posts: 822
Lua Code:
  1. local name, rank, icon, count, debuffType, duration, expirationTime, unitCaster, isStealable,
  2. shouldConsolidate, spellId, canApplyAura, isBossDebuff, value1, value2, value3 = UnitBuff("unit", index or "name"[, "rank"[, "filter"]])
You check on the 15th argument. The time left is the expirationTime value.

Take a look at the 2nd example
http://wowpedia.org/API_UnitBuff
__________________
The cataclysm broke the world ... and the pandas could not fix it!
  Reply With Quote
08-04-14, 04:22 AM   #3
Lybrial
A Flamescale Wyrmkin
AddOn Compiler - Click to view compilations
Join Date: Jan 2010
Posts: 120
Ok but i still get lua errors and a strange behaviour of my bar:

Code:
function()
    local value = select(8, UnitBuff("player", "Blutschild")) or 0
    return value;
end
So with this i get the expirationTime and i return it. My goal is
to have a bar which shows when the buff will expire.
With the above code i just get lua errors.

11x Interface\AddOns\WeakAuras\WeakAuras-2.0.7.lua:1864: attempt to compare number with string
44x Interface\AddOns\WeakAuras\RegionTypes\aurabar.lua:649: attempt to perform arithmetic on field 'expirationTime' (a nil value)
Interface\AddOns\WeakAuras\RegionTypes\aurabar.lua:649: in function <Interface\AddOns\WeakAuras\RegionTypes\aurabar.lua:647>
Interface\AddOns\WeakAuras\RegionTypes\aurabar.lua:1053: in functio

Last edited by Lybrial : 08-04-14 at 04:24 AM.
  Reply With Quote
08-04-14, 06:35 AM   #4
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Re-read the documentation. The 8th return value is a string identifying the unit that cast the buff; the expiration time is arg7. Also, there's really no reason to use select here; it's just slowing things down for no reason.

Code:
function()
     local _, _, _, _, _, duration, expirationTime = UnitBuff("player", "Blutschild")
     return expirationTime
end
Or, if your function needs to return the amount of time left (instead of the time at which it ends) do this:

Code:
function()
     local _, _, _, _, _, duration, expirationTime = UnitBuff("player", "Blutschild")
     return expirationTime - GetTime()
end
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
08-04-14, 07:00 AM   #5
Lybrial
A Flamescale Wyrmkin
AddOn Compiler - Click to view compilations
Join Date: Jan 2010
Posts: 120
Originally Posted by Phanx View Post
Code:
function()
     local _, _, _, _, _, duration, expirationTime = UnitBuff("player", "Blutschild")
     return expirationTime
end
4x Interface\AddOns\WeakAuras\WeakAuras-2.0.7.lua:1864: attempt to compare number with nil
Interface\AddOns\WeakAuras\WeakAuras-2.0.7.lua:1864: in function `SetEventDynamics'
Interface\AddOns\WeakAuras\WeakAuras-2.0.7.lua:1835: in function `ActivateEvent'
Interface\AddOns\WeakAuras\WeakAuras-2.0.7.lua:1816: in function `ScanEvents'
Interface\AddOns\WeakAuras\WeakAuras-2.0.7.lua:1730: in function `ForceEvents'
Interface\AddOns\WeakAuras\WeakAuras-2.0.7.lua:2144: in function `ScanForLoads'
Originally Posted by Phanx View Post
Code:
function()
     local _, _, _, _, _, duration, expirationTime = UnitBuff("player", "Blutschild")
     return expirationTime - GetTime()
end
9x [string "return function()..."]:3: attempt to perform arithmetic on local 'expirationTime' (a nil value)
[string "return function()..."]:3: in function `durationFunc'
Interface\AddOns\WeakAuras\WeakAuras-2.0.7.lua:1860: in function `SetEventDynamics'
Interface\AddOns\WeakAuras\WeakAuras-2.0.7.lua:1835: in function `ActivateEvent'
Interface\AddOns\WeakAuras\WeakAuras-2.0.7.lua:1816: in function `ScanEvents'
Interface\AddOns\WeakAuras\WeakAuras-2.0.7.lua:1730: in function `ForceEvents'
Interface\AddOns\WeakAuras\WeakAuras-2.0.7.lua:2144: in function `ScanForLoads'
Maybe i should describe my problem a little bit better.

Im working with WeakAuras 2 And i have a bar to observe my Blood Shield of my DK.

This is the function i use to show how much damage my shield can block:

Code:
function () 
    local shield_value = select(15, UnitBuff("player", "Blutschild")) or 0;
    shield_value = math.floor(shield_value/1000);
    
    local max_health = UnitHealthMax("player");
    max_health = math.floor(max_health/1000);
    
    return string.format("%uk/%uk", shield_value, max_health);
end
My Trigger Code:

Code:
function()
    return true
end
My Reverse Trigger Code:

Code:
function()
    local a = UnitBuff("player", "Blutschild")
    return a == nil
end
And now i need Code for the duration so that my bar
shows how much time is left until my shield expires.
If i use one of your codes posted above i get the
posted lua errors and the bar starts randomly in the
middle of the bar and decreases.
  Reply With Quote
08-04-14, 07:24 AM   #6
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
You're (probably) getting those errors because you don't currently have the buff active. I guess WeakAuras can't handle nil values itself (I don't actually use it) so just return a zero if UnitAura didn't return anything:
Code:
function()
     local _, _, _, _, _, duration, expirationTime = UnitBuff("player", "Blutschild")
     return expirationTime or 0
end
or:
Code:
function()
     local _, _, _, _, _, duration, expirationTime = UnitBuff("player", "Blutschild")
     return expirationTime and (expirationTime - GetTime()) or 0
end
Again, as I don't actually use WeakAuras, I don't know whether it needs the remaining time or the expiration time, but either of the above should make sure it doesn't receive any scary nil values.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Lua get Buff duration


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