I can't actually answer your question as I don't use WeakAuras, but you'll want to be careful about leaking your
variables into the global environment:
Code:
-- Function for Custom Text
function()
local buff_name = "Broadsides"
if UnitBuff("PLAYER", buff_name) then
dur, exptime = select(6, UnitBuff("PLAYER", buff_name))
end
return string.format("%.1f", max(0, dur + exptime - GetTime())), max(36, dur), true
end
You're leaking both "dur" and "exptime" as globals. Also, your function as written is raising an error any time you don't have the buff active; if you don't see the error, either you don't have anything to show error messages, or WeakAuras is wrapping your function in a
pcall so it's getting hidden. I'd rewrite it like so:
lua Code:
function()
local name = "Broadsides"
local _, _, _, _, _, dur, exptime = UnitBuff("player", name)
-- ^ avoid "select" if you can, function calls are expensive
if not dur or not exptime then
-- buff is not active, nothing to show
return 0, 0, true
end
-- buff is active, do your thing
return string.format("%.1f", max(0, dur + exptime - GetTime())), max(36, dur), true
end
edit: Actually, on the original topic, you may not be able to do what you want inside WeakAuras, but there's nothing stopping you from doing it outside of WeakAuras. Just
create an addon whose name comes before "WeakAuras" in alphabetical order, and put your function in there as a global, with a nice unique name appropriate for a global:
lua Code:
function GetMyWABuff(name)
local _, _, _, _, _, dur, exptime = UnitBuff("player", name)
if not dur or not exptime then
-- buff is not active, nothing to show
return 0, 0, true
end
-- buff is active, do your thing
return string.format("%.1f", max(0, dur + exptime - GetTime())), max(36, dur), true
end
...and then call it in your WeakAuras function:
lua Code:
function()
return GetMyWABuff("Broadsides")
end