1. #1

    Question [Weak Auras] Question about Custom Text

    Ok, so first off, let me apologize in advance if this question has been asked and answered. I did use the search and I also tried googling it, but no help.

    Second, let me also apologize for my total lack of LUA and coding knowledge.


    Ok, so I'm looking to set up a custom Weakauras Text Display. I want to use the "%c" function so I can input my own LUA code, but I want the text to show up as my name, and in my class color. (I also want to copy this to make it do the same thing for my target) I realize that "%n" with the trigger set to player will already output my name, and I have also figured out that there's a way to tell it to use class color, but I can't get it to do both at the same time.

    I have tried the below, and it works to do the class color, but it just returns a flat value of "0.78" no matter what else I add in.

    Code:
    function()
        local c = RAID_CLASS_COLORS[select(2,UnitClass("player"))]
        return c.r, c.g, c.b
    end

    Also, I realize that the above code can be applied in the custom animations section. I have tried setting the display text to "%n" and then setting the animations to the above code, but when I have no target, it causes a mass flood of errors.

  2. #2
    Deleted
    -Set your display to %n
    -Go to Animation, set the Main-Animation to Custom, give it a Duration of 1s or whatever (it needs a duration though)
    -Check the Box next to Color and choose Custom Function in the dropdown menu, expand the text editor and replace whatever you
    have in there with your function

    That works for me at least

    edit: it's giving me some errors when I try to change its position with the mouse tho, it works with changing the values X and Y Offset
    Last edited by mmocc631c4b798; 2015-01-15 at 03:00 AM.

  3. #3
    Yeah, I've done everything I can to make the animations angle work. The problem is that I'm already using a slide-in start animation (and slide-out finish animation) and adding the color to those animations PLUS having the main animation be a custom color isn't working. Causes errors and also, there's a small gap of time between the start-main-finish animations where the text turns back to the default color. This is why I'm looking for custom code to just pull the name of the unit and display it in class color.

  4. #4
    Deleted
    was trying to make a display function that gets the class and your name, basically
    Code:
    function()
    local unit_name = UnitName("player")
    local unit_class = select(2, UnitClass("player"))
    
         ...
    then maybe make if/elseif lines with every class and their color codes and in the end return the name in the color from the loop
    but I can't seem to figure out how to change the font color of a string that the function is supposed to return.
    Not experienced enough I guess, if it even works

    sorry
    bed now

    edit: I think I got it actually, use this in your custom display function:
    Code:
    function()
        local unit_name = UnitName("player")
        local color = ""
        
        if (select(2, UnitClass("player")) == "HUNTER") then
            color = "|cFFABD473"
        elseif (select(2, UnitClass("player")) == "DEATHKNIGHT") then
            color = "|cFFC41F3B"
        end
        return color..unit_name
    end
    I only did it with Hunter and DK now, the rest should be easy. Just google "wow class colors", first link should be from wowwiki.
    There you can see the HEX codes, you will notice that those have 6 digits while in the function above the color code has 8 digits.
    Just put the FF in front of the wowwiki color codes, that is the alpha value (transparency).
    Example for Mage:
    Code:
    elseif (select(2, UnitClass("player")) == "MAGE") then
    
    color = "|cFF69CCF0"
    okay?
    Last edited by mmocc631c4b798; 2015-01-15 at 06:08 AM.

  5. #5
    Wonderful. Thanks so much for the help! Just loaded it in and it works great!

    One last question-- I copied/pasted that over to my target frame and changed all the "player" calls to "target" instead. Here's what it ended up as:

    Code:
    function()
        local unit_name = UnitName("target")
        local color = ""
        
        if (select(2, UnitClass("target")) == "HUNTER") then
            color = "|cFFABD473"
        elseif (select(2, UnitClass("target")) == "DEATHKNIGHT") then
            color = "|cFFC41F3B"
        elseif (select(2, UnitClass("target")) == "MAGE") then
            color = "|cFF69CCF0"
        elseif (select(2, UnitClass("target")) == "DRUID") then
            color = "|cFFFF7D0A"
        elseif (select(2, UnitClass("target")) == "MONK") then
            color = "|cFF00FF96"
        elseif (select(2, UnitClass("target")) == "PALADIN") then
            color = "|cFFF58CBA"
        elseif (select(2, UnitClass("target")) == "PRIEST") then
            color = "|cFFFFFFFF"
        elseif (select(2, UnitClass("target")) == "ROGUE") then
            color = "|cFFFFF569"
        elseif (select(2, UnitClass("target")) == "SHAMAN") then
            color = "|cFF0070DE"
        elseif (select(2, UnitClass("target")) == "WARLOCK") then
            color = "|cFF9482C9"
        elseif (select(2, UnitClass("target")) == "WARRIOR") then
            color = "|cFFC79C6E"
        else color = "|CFFFFFFFF"
        end
        return color..unit_name
    end


    It works fine at first, but then it causes a massive error when I open the weakauras options. The error that pops up is:

    Message: [string "return function()..."]:29: attempt to concatenate local 'unit_name' (a nil value)
    Time: 01/15/15 03:00:46
    Count: 159
    Stack: [C]: ?
    [string "return function()..."]:29: in function <[string "return function()..."]:1>
    Interface\AddOns\WeakAuras\RegionTypes\text.lua:91: in function `UpdateCustomText'
    Interface\AddOns\WeakAuras\WeakAuras.lua:5019: in function <Interface\AddOns\WeakAuras\WeakAuras.lua:5015>

    I think it's trying to find my target's name, but since I don't have a target, it's coming back as an error. Is there a way to safeguard against this? Some way to return "..." or "Name Unknown" if it can't find the name?

  6. #6
    Deleted
    yeah I was sure it can be done in a cleaner way :P

  7. #7
    oneyoner, evn..... Thank you both for your help! I wasn't expecting to get so much assistance so quickly!

    One problem I'm having: From time to time, when I click on an NPC it will flood with errors again. I'm thinking this is happening because the target has no identifiable class. Is there a safeguard I can put in or an "else" clause that would tell it to return some sort of set color if no class can be found?

    Just tested it again- It seems to happen when I target a friendly NPC that's transitioning. For instance, at the WoD starter area, when you're following Khadgar around. If I target Khadgar when he's offering me a quest, no issues. His name shows up in mage-blue. But as soon as I initiate the next step of the chain, and Khadgar goes to run off, if I target him, it floods with an error.

    Same thing happens when I target an NPC that's trapped in a prison cage. When the cage is closed and the NPCs are still, no issues. They show up as Warrior-brown. But when I open the cage, if I have them targetted, or if I retarget them, errors.

    the error is:

    Code:
    Message: [string "return function()..."]:6: attempt to index field '?' (a nil value)
    Time: 01/15/15 14:25:19
    Count: 495
    Stack: [C]: ?
    [string "return function()..."]:6: in function <[string "return function()..."]:1>
    Interface\AddOns\WeakAuras\RegionTypes\text.lua:91: in function `UpdateCustomText'
    Interface\AddOns\WeakAuras\WeakAuras.lua:5019: in function <Interface\AddOns\WeakAuras\WeakAuras.lua:5015>
    
    Locals:
    Last edited by Cronah; 2015-01-15 at 07:25 PM. Reason: clarification

  8. #8
    Just posting a reply in case someone else ever tries to do the same thing and ends up here... Doubtful, I know....but stranger things have happened.

    So I went back and did more testing. Like I said in my earlier post, it seems to be caused by NPCs when they are transitioning from one area to another. Note: This doesn't mean when they are simply walking around. I think when an NPC is doing some scripted events, they return no class value. I've noticed that the my tooltip shows "unknown" as the type of mob (as opposed to "beast" or "humanoid") during this time as well.

    To fix this, I put in an elseif clause that checks to see if the unit has a class. If it does have a class, it returns that value. If there is no class available, then it goes to the next step (the next step simply ignores the class altogether and doesn't check for it.) The final custom code was:

    Code:
    function()
        local unit = 'target'
        if UnitExists(unit) and UnitClass(unit) then
            local name = UnitName(unit)
            local class, key = UnitClassBase(unit)
            local color = RAID_CLASS_COLORS[key].colorStr 
            unit = string.format("|c%s%s", color, name)
        elseif UnitExists(unit) then
            local name = UnitName(unit)
            unit = string.format (name)    
        end
        
        return unit
    end
    What that does is if you have a unit targeted, it will show up as the Unit's Name with the class color. If the unit doesn't have a class, it will show up as whatever color you have previously selected in the weakaura option (in my case, White).

  9. #9
    Deleted
    When targeting npcs, this causes errors.



    Any ideas how to fix this?

  10. #10
    Deleted
    Where would you put this untrigger function code?

  11. #11
    Deleted
    Sorry for being late to the party!


    Code:
    function()
        local color = 'FFFFFFFF'
        if UnitExists("target") then
            local name = UnitName("target")
            local class, key = UnitClassBase('target')
            if key then
                color = RAID_CLASS_COLORS[key].colorStr
                return string.format("|c%s%s", color, name)
            else
                return ""
            end
        end
        end

  12. #12

    Question

    How to set WeakAuras2 to show me when my target is an undead mob (not an undead-forsaken player characters). So i can try and take over control (as a death knight with "control undead" spell) on that certain mob. Thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •