WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   oUF (Otravi Unit Frames) (https://www.wowinterface.com/forums/forumdisplay.php?f=87)
-   -   Aura string tag, how to use frequentUpdates ? (https://www.wowinterface.com/forums/showthread.php?t=48709)

Musca 12-22-13 08:28 PM

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)

MoonWitch 12-22-13 10:36 PM

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.

Phanx 12-23-13 01:42 AM

Quote:

Originally Posted by MoonWitch (Post 288675)
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.

Quote:

Originally Posted by MoonWitch (Post 288675)
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. :p

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!)

MoonWitch 12-23-13 08:23 AM

Quote:

Originally Posted by Phanx (Post 288678)
That might work, but conceptually I find it very disturbing. :p

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

Musca 12-23-13 05:22 PM

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)

haste 12-24-13 07:17 AM

Quote:

Originally Posted by Musca (Post 288669)
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.

MoonWitch 12-24-13 07:34 AM

Quote:

Originally Posted by haste (Post 288752)
Tags support frequentUpdates, but you have to set the variable before calling :Tag(). Swap the order and it will work.

So we all learn...

Musca 12-24-13 11:52 PM

Even better! Thanks, haste :D


All times are GMT -6. The time now is 12:58 PM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI