1. #1

    WA: Help with adding classcolors to a custom display.

    I found a useful weakauras for convulsive shadows target on Iron Maidens and I wonder if someone could make the name appear in appropriate class colors?

    Here's the trigger:
    Code:
    function(event, unit)
        if GetUnitName(unit) == "Enforcer Sorka" and UnitCastingInfo(unit) == "Convulsive Shadows" then
            WA_contarget = GetUnitName(unit .. "target")
                return true
            end
        end

    And the current display:
    Code:
    function()
        return "Convulsive: " .. WA_contarget
    end

    Something including this maybe?
    Code:
    local name = string.format("|c%s%s|r", RAID_CLASS_COLORS[select(2, UnitClass(WA_contarget))].colorStr, UnitName(WA_contarget))
    Result = string.format("%s%s, name)
    (I just copied some parts including class colors of a WA Hamsda made for me. I really don't know what I'm doing.)

  2. #2
    Deleted
    If I recall correctly you should be able to replace the unitids with the name of partymembers, so what you did pretty much does the trick. Just change the display code to:
    Code:
    function()
       return string.format("Convulsive: |c%s%s|r", RAID_CLASS_COLORS[select(2, UnitClass(WA_contarget))].colorStr, UnitName(WA_contarget))
    end

  3. #3
    Quote Originally Posted by Hamsda View Post
    If I recall correctly you should be able to replace the unitids with the name of partymembers, so what you did pretty much does the trick. Just change the display code to:
    Code:
    function()
       return string.format("Convulsive: |c%s%s|r", RAID_CLASS_COLORS[select(2, UnitClass(WA_contarget))].colorStr, UnitName(WA_contarget))
    end
    Cheers! That worked.

  4. #4
    I found an even better aura, could you apply class colors it to this as well please? ^^

    Code:
    function()
        for i=1,3 do
            local unitId = ('boss%s'):format(i)
            if UnitExists(unitId) and UnitName(unitId) == 'Enforcer Sorka' then
                return UnitName(('%starget'):format(unitId)) or ''
            end
        end
    end

  5. #5
    Deleted
    Let me try to explain the snippet from before a bit, because changing it isn't that complicated:
    Code:
    function()
       return string.format("Convulsive: |c%s%s|r", RAID_CLASS_COLORS[select(2, UnitClass(WA_contarget))].colorStr, UnitName(WA_contarget))
    end
    string.format(formatstring, ...) basically takes 2 arguments, the formatstring and a list of values that get put into the formatstring.
    The formatstring contains certain placeholders and those get replaced by the values in the list afterwards.

    In this example it starts with a bit of text "Convulsive: ".
    Followed by "|c%s". "|c" starts the color-coding and requires the actual color code afterwards. This is where the first %s comes into play. It will be replaced by the first argument (which we will have to set up with the color code).
    Then another %s, accepting another string, in this case the actual name of the unit.
    the last bit "|r" just ends the color-coding.

    This leaves us with having to provide 2 arguments: the color code and the units name.
    1) RAID_CLASS_COLORS[select(2, UnitClass(WA_contarget))].colorStr
    I put multiple things in there to make the whole thing a bit shorter. The innermost term "WA_contarget" can be any UnitID (or the name of a unit in your party/raid). UnitClass(WA_contarget) will give us the class of that unit. If you have a look at the api, it gives a localized name, a standardized name and a number. We need the standardized name, so with "select(2, UnitClass(X))" we pick the 2nd argument of the return values. This can be used as an index to the table RAID_CLASS_COLORS to get us the color code of WA_contarget.
    2) UnitName(WA_contarget)
    Pretty simple this time. UnitName() gets us the name of WA_contarget.


    So if you just want to get a class-colored name of someone, you can get rid of the unused stuff in the formatstring and shorten it to "|c%s%s|r" and replace both occurences of WA_contarget with the unitid you have.
    In the case you posted, the unitid is put together with string.format aswell, so it would probably be the easiest to save it in a variable because we want to use it twice:
    Code:
    function()
        for i=1,3 do
            local unitId = ('boss%s'):format(i)
            if UnitExists(unitId) and UnitName(unitId) == 'Enforcer Sorka' then
                local targetUnitID = UnitName(('%starget'):format(unitId)) or ''
                return string.format("|c%s%s|r", RAID_CLASS_COLORS[select(2, UnitClass(targetUnitID))].colorStr, UnitName(targetUnitID))
            end
        end
    end

  6. #6
    Ahh, lovely. Thanks for the lesson . I think the largest issue was that I never understood how to decipher |c%s%s|r from the previous auras ^^-

  7. #7
    Deleted
    Yeah format strings are very common in programming languages as they are more readable than endless string concatenations once you understand the principle.
    Searching for "lua string format" on google will yield you with many more information regarding the topic

  8. #8
    Brewmaster Ogait's Avatar
    10+ Year Old Account
    Join Date
    Jul 2009
    Location
    Portugal
    Posts
    1,343
    Could you give the String from that Aura?
    I'm trying to replicate that but having too many errors on my Aura.
    | Realm First Monk | Dragonflight Beta Tester ( ty Blizzard! ) |

  9. #9
    Deleted
    I assume Overdispersion is using the one from vox immortalis, which can be found on this page: vox immortalis brf weakauras (at least the code looks familiar to what I saw over there on the forums ;P)
    Overdispersion can probably share his though, if you want the class coloring aswell.

Posting Permissions

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