1. #1
    Deleted

    Weak Auras - Custom Text LUA

    Hey guys,

    I wish to use custom text on a healthbar, but I would like to enable the display of max health to be done like follows depending on the number:

    • 200 (3 digit)
    • 2k (4 digit)
    • 2m (9 digit)

    Can someone please help with the custom LUA required to achieve this?

    I would also like the custom LUA code to be able to change the name of a target to an abbreviated form, as in the below examples:

    Bloodtalon Raptor > B. Raptor
    Docile Island Boar > D. I. Boar And so on.

    Is this possible to do?

    Thanks!

  2. #2
    Quote Originally Posted by CtrlAltDenied View Post
    Hey guys,

    I wish to use custom text on a healthbar, but I would like to enable the display of max health to be done like follows depending on the number:

    • 200 (3 digit)
    • 2k (4 digit)
    • 2m (9 digit)

    Can someone please help with the custom LUA required to achieve this?
    Had this code already. Don't have anything for the other part of your post. I'll maybe have a look at it tomorrow, if I get the time.
    This is for current health. Just change to UnitHealthMax("player") if that was what you wanted.

    Code:
    function()
        hp = UnitHealth("player")
        abb = ""
        if hp >= 1000
        then hp = hp/1000
            abb = "K"
        end
        if hp >= 1000
        then hp = hp/1000
            abb = "M"
        end
        return ("%.1f%s"):format(hp, abb)    
    end


    Okay, so here is a function that splits the name the way you asked.
    Made it with up to four names.

    Fabioso the Fabulous -> F. t. Fabulous

    Code:
    function()
        name = {}
        
        for s in UnitName("target"):gmatch("%w+") 
        do 
            table.insert(name, s) 
        end
        
        if #name == 1 then
            return ("%s"):format(name[1])
        end   
        if #name == 2 then
            return ("%s. %s"):format(
                string.sub(name[1], 1, 1), 
                name[2])
        end  
        if #name == 3 then
            return ("%s. %s. %s"):format(
                string.sub(name[1], 1, 1),
                string.sub(name[2], 1, 1), 
                name[3])
        end 
        if #name == 4 then
            return ("%s. %s. %s. %s"):format(
                string.sub(name[1], 1, 1),
                string.sub(name[2], 1, 1), 
                string.sub(name[3], 1, 1), 
                name[4])
        end 
    end
    Last edited by Quibble; 2017-02-12 at 01:41 PM.
    "Everything always changes. The best plan lasts until the first arrow leaves the bow." - Matrim Cauthon

  3. #3
    Deleted
    Is it possible to set left and right text to %c and output a string to left text and a seperate string to right text by formatting the return only? Or would I need custom trigger to use something like %n (name info).

    I basically need the left text to show current health percentage and the right text to show max health.

    The current function being used is this:

    function()
    local percent = (UnitHealth("player")/UnitHealthMax("player"))*100
    return string.format("%1.0f",percent)
    end
    How does one modify the return string to output left and right text as this only seems to occupy the left text.

    - - - Updated - - -

    Additionally, my current unit frame lua text for name, is as below

    Code:
    local r,g,b = ClassColor(unit)
    return '               |cff%02x%02x%02x%s|r                     ',r,g,b,Name(unit),(AFK(unit) or DND(unit))
    I would like to strip out the AFK/DND stuff, keep the class colouring of the name, and then format it has per your name code. How would I go about altering the string.

    As you see I'm not up on the string manipulation parts, so help there would be great.

  4. #4
    Why not just use two auras?

    If this is for the same aura that you were working on in the other thread. Just make two new auras with the same triggers and drop them on top of the other one. Then make one of them show percentage and the other to show max health
    "Everything always changes. The best plan lasts until the first arrow leaves the bow." - Matrim Cauthon

  5. #5
    Deleted
    The name abbreviation is for Pitbull unit frame to show class coloured shortened names.

    The max health and percentage are for the WA healthbar. I just wanted to get them both into the one WA is all, I'll figure it out.

    Ok so class coloured name:

    Code:
    local r,g,b = ClassColor(unit)
    return '|cff%02x%02x%02x %s |r',r,g,b,Name(unit)
    The %s being the name as in your code.

    So in theory I should just need the local rgb definition, and modify the returns in each case of name abbreviation with the RGB code.
    Last edited by mmoc3be44ac5db; 2017-02-12 at 02:01 PM. Reason: Working it out.

  6. #6
    The code for the name just formats a string which in my case was returned to the custom text field in weakaura.

    I don't use pitbul, I don't know how they handle stuff and I don't plan on getting it to test it.

    However, assuming "Name(unit)" is just a string, you could probably just replace it with the string from my code:

    Code:
    string = ""
    name = {}
    
    for s in UnitName("target"):gmatch("%w+") 
    do 
        table.insert(name, s) 
    end
    
    if #name == 1 then
        string = ("%s"):format(name[1])
    end   
    if #name == 2 then
        string = ("%s. %s"):format(
            string.sub(name[1], 1, 1), 
            name[2])
    end  
    if #name == 3 then
        string = ("%s. %s. %s"):format(
            string.sub(name[1], 1, 1),
            string.sub(name[2], 1, 1), 
            name[3])
    end 
    if #name == 4 then
        string = ("%s. %s. %s. %s"):format(
            string.sub(name[1], 1, 1),
            string.sub(name[2], 1, 1), 
            string.sub(name[3], 1, 1), 
            name[4])
    end

    I don't know whether you can leave out the AFK / DND part, as I don't know if pitbull expects those and won't work without it. Maybe replace them with empty strings?

    Also I just found that the above code doesn't work well with special characters like åæø or éè.. because the %w+ only asks for alphanumeric and those are not seen as alphanumeric characters.
    Last edited by Quibble; 2017-02-12 at 02:15 PM.
    "Everything always changes. The best plan lasts until the first arrow leaves the bow." - Matrim Cauthon

  7. #7
    Deleted
    I noticed the part about special characters quite quickly, but it abbreviates others names quite well. As its a custom text being used in pitbull, its replicated across both player and target units, so I can't use that inside Pitbull without it detecting between them properly.

    Code:
    local r,g,b = ClassColor(unit)
    return '|cff%02x%02x%02x%s|r',r,g,b,Name(unit)
    That's the stripped down code, I managed to do that much myself and remove the AFK and other stuff I didn't need.

Posting Permissions

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