Thread Tools Display Modes
12-22-13, 08:28 PM   #1
Musca
A Murloc Raider
AddOn Author - Click to view addons
Join Date: Nov 2013
Posts: 8
Aura string tag, how to use frequentUpdates ?

Hi all,

I'm trying to create a tag to show the pet's name. As I main a hunter, I would like it to show the remaining duration on Mend Pet if it's active, and go back to showing the pet name when it's not. Here is the code for the tag:

Code:
oUF.Tags.Methods['mu:petname'] = function(unit)
  local name = string.sub(UnitName(unit), 1, 5)
  local mendpet, _,_,_,_,_, expirationTime, source = UnitAura(unit, GetSpellInfo(136))
  if mendpet and source == 'player' then
    local t = floor(expirationTime - GetTime())
    return toHex(0.37, 0.81, 0.56) .. t .. '|r'
  elseif UnitIsDead(unit) then
    return toHex(0.6, 0.6, 0.6) .. '[RIP]|r'
  else
    return toHex(0.6, 0.6, 0.6) .. name .. '|r'
  end
end
oUF.Tags.Events['mu:petname'] = 'UNIT_AURA UNIT_NAME_UPDATE'
Now, I realise that this will only update the duration when the UNIT_AURA event fires, so it's not going to display the countdown in the way I want. So, borrowing from Quse (which hasn't been updated for a while but it's the only one I could find with aura strings), I used this code to create the name string on the pet frame:

Code:
  if pClass == 'HUNTER' then
    self:Tag(self.Name, '[mu:shortname]')
    self.Name.frequentUpdates = 0.25
  else
    other name tag
This ends up updating the string every few seconds, so I get '10' when I first cast Mend Pet, and then it might update again at '7', then again at '5', then at '2', and when it falls off it'll go back to showing the pet name.

I'm a bit flummoxed. How do I make it update more frequently than that ? I've tried changing the number, anything from 0.05 to 2, or just setting it to true, but it does not seem to make a difference to how quickly the string updates.

Sorry if this question is really noobish, this is my first go at trying to make a layout from scratch (and really first go at any programming at all)

Last edited by Musca : 12-22-13 at 08:37 PM.
  Reply With Quote
12-22-13, 10:36 PM   #2
MoonWitch
A Firelord
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 455
Might be completely wrong, I am sure someone will correct me. But I've hooked into missing as event when I need frequent updates on a custom tag. (Also I think .frequentUpdates is only for statusbars)

Like so :
Lua Code:
  1. oUF.Tags.Events['mu:petname'] = oUF.Tags.Events.missingpp

Admittedly, it's also for power - but in your case I think it may work fine.
  Reply With Quote
12-23-13, 01:42 AM   #3
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by MoonWitch View Post
Also I think .frequentUpdates is only for statusbars
More specifically, frequentUpdates is only for the Health and Power elements. oUF expects those elements to be statusbars, but with a little creativity you can make them anything you want.

Originally Posted by MoonWitch View Post
Might be completely wrong, I am sure someone will correct me. But I've hooked into missing as event when I need frequent updates on a custom tag.
That might work, but conceptually I find it very disturbing.

A "better" solution would be to just update the fontstring yourself, since oUF's tagging system is not designed for polling like that:

Code:
local petName = CreateFrame("Frame", nil, self)
petName:SetPoint("BOTTOMLEFT", self, "TOPLEFT")
petName:SetSize(1, 1)

petName.text = petName:CreateFontString(nil, "OVERLAY", "GameFontNormal")
petName.text:SetPoint("BOTTOMLEFT")

petName:RegisterUnitEvent("UNIT_NAME_UPDATE", "pet")
petName:SetScript("OnEvent", function(self, event, unit)
    self.shortName = strsub(UnitName(unit), 1, 5)
end)

petName.spellName = GetSpellInfo(136)
petName:SetScript("OnUpdate", function(self, elapsed)
    if UnitIsDead(unit) then
        return self.text:SetText("|cff999999[RIP]|r")
    end
    local _, _, _, _, _, _, expires, caster = UnitAura(unit, self.spellName)
    if caster == "player" then
        return self.text:SetFormattedText("|cff5ecf8f%.0f|r", expirationTime - GetTime())
    end
    return self.text:SetFormattedText("|cff999999%s|r", self.shortName)
end)

self.PetName = petName
(Also, calling GetSpellInfo and converting the same values to the same hex code over and over again, as in your original tag code, is really wasteful. Don't do that!)
__________________
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
12-23-13, 08:23 AM   #4
MoonWitch
A Firelord
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 455
Originally Posted by Phanx View Post
That might work, but conceptually I find it very disturbing.
I only do it myself for druid power But it was the best I could think of. I said someone would correct me. Now I learned something new too
  Reply With Quote
12-23-13, 05:22 PM   #5
Musca
A Murloc Raider
AddOn Author - Click to view addons
Join Date: Nov 2013
Posts: 8
Thanks guys. Managed to get it working in a jiffy using Phanx's suggested method. (ty also on the efficiency note, looks like I need to do some editing on the other tags)
  Reply With Quote
12-24-13, 07:17 AM   #6
haste
Featured Artist
 
haste's Avatar
Premium Member
Featured
Join Date: Dec 2005
Posts: 1,027
Originally Posted by Musca View Post
Code:
  if pClass == 'HUNTER' then
    self:Tag(self.Name, '[mu:shortname]')
    self.Name.frequentUpdates = 0.25
  else
    other name tag
Tags support frequentUpdates, but you have to set the variable before calling :Tag(). Swap the order and it will work.
__________________
「貴方は1人じゃないよ」
  Reply With Quote
12-24-13, 07:34 AM   #7
MoonWitch
A Firelord
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 455
Originally Posted by haste View Post
Tags support frequentUpdates, but you have to set the variable before calling :Tag(). Swap the order and it will work.
So we all learn...
  Reply With Quote
12-24-13, 11:52 PM   #8
Musca
A Murloc Raider
AddOn Author - Click to view addons
Join Date: Nov 2013
Posts: 8
Even better! Thanks, haste
  Reply With Quote

WoWInterface » Featured Projects » oUF (Otravi Unit Frames) » Aura string tag, how to use frequentUpdates ?


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