Page 1 of 2
1
2
LastLast
  1. #1

    Question Lua code help for Stuf

    Hey.

    After switching to Stuf from Pitbull4 I need some help with a lua code. For pitbull I used a code that would easily shorten the name if it was too long, like Raider's Training Dummy would become R. T. Dummy. I tried decreasing the width of the text but it doesnt work.

    The Code:

    local abbr = Name(unit)
    if abbr:len() > 15 and abbr:find(" ") then
    abbr = abbr:gsub("([^ ]+) +",
    function(text)
    return text:sub(1,1) .. ". "
    end)
    end
    return "%s", abbr;

    I appreciate any help :)
    My knowledge and experience with .lua is limited.

  2. #2
    instead of code, i believe you can just use a certain tag that does the exact same thing within the options of stuf, but i cant remember what it was


    AddOn Author of: SpellNotReadyYet, Rune of Powa

  3. #3
    Quote Originally Posted by SpaceDuck View Post
    instead of code, i believe you can just use a certain tag that does the exact same thing within the options of stuf, but i cant remember what it was
    Yeah, using a tag might actually work. I have no clue how to, though.
    Heres the Pattern Tag Helper:

    Last edited by Treeston; 2012-06-29 at 10:29 PM.

  4. #4
    The Patient Ketho's Avatar
    Join Date
    Jan 2011
    Location
    The Netherlands
    Posts
    278
    (Wowhead crosspost for reference)

  5. #5
    Quote Originally Posted by Ketho View Post
    (Wowhead >link< for reference)
    Thank you extremely much!!

  6. #6
    The Patient Ketho's Avatar
    Join Date
    Jan 2011
    Location
    The Netherlands
    Posts
    278
    Quote Originally Posted by Jagsvarbrehh View Post
    Thank you extremely much!!
    ehhm I don't understand

  7. #7
    Quote Originally Posted by Ketho View Post
    ehhm I don't understand

    You posted a link that helped me.
    Whats hard to understand?

  8. #8
    The Patient Ketho's Avatar
    Join Date
    Jan 2011
    Location
    The Netherlands
    Posts
    278
    Okay np =)

  9. #9
    Old thread but i want the same thing, problem is that i have no clue what to do.
    I read some in the link at wowhead but it only made me more confused, i don't know anything about lua coding.
    Could anyone give me a hand with this? What text should i change/add in the lua?

  10. #10
    Scarab Lord Taryble's Avatar
    Join Date
    Aug 2008
    Location
    Texas
    Posts
    4,038
    This is the lua code I use in my StUF frames - it uses a shortened name, colored by class (Wild Wild West becomes W. W. West, for example), while at full HP.

    At lower HP levels, it shows both the HP percentage and how much HP the target has lost (I often heal, so HP lost was important to me).

    Code:
    function(unit, cache, textframe)
      local cc = RAID_CLASS_COLORS[select(2, UnitClass("player"))]
      if UnitExists(unit) then
        cc = RAID_CLASS_COLORS[select(2, UnitClass(unit))]
      end
      local curhp, maxhp = UnitHealth(unit), UnitHealthMax(unit)
      if curhp ~= maxhp then
        local perchp, diffhp = 100 * curhp / maxhp, maxhp - curhp
        return "|cff%02x%02x%02x%.0f|r%% | |cffc31d3a-%s|r",cc.r*255,cc.g*255,cc.b*255,perchp,diffhp
      else
        local name = UnitName("player")
        if UnitExists(unit) then
          name = UnitName(unit)
        end
        return "|cff%02x%02x%02x%s|r",cc.r*255,cc.g*255,cc.b*255,string.gsub(name, '%s?(.)%S+%s', '%1. ')
      end
    end
    If you JUST want the name shortener, use this (from the link posted by Ketho above)
    Code:
    function(unit)
    	local name = UnitName(unit) or unit
    	name = name:gsub('(%S+) ',function(t) return t:sub(1,1)..'.' end)
    	return name
    end
    If you want class-coloring in it, just ask, and I'll whip up class coloring with it for ya.
    We have done the impossible, and that makes us mighty. - Sgt. Malcolm "Mal" Reynolds, Battle of Serenity Valley

  11. #11
    Quote Originally Posted by Taryble View Post
    This is the lua code I use in my StUF frames - it uses a shortened name, colored by class (Wild Wild West becomes W. W. West, for example), while at full HP.

    At lower HP levels, it shows both the HP percentage and how much HP the target has lost (I often heal, so HP lost was important to me).

    Code:
    function(unit, cache, textframe)
      local cc = RAID_CLASS_COLORS[select(2, UnitClass("player"))]
      if UnitExists(unit) then
        cc = RAID_CLASS_COLORS[select(2, UnitClass(unit))]
      end
      local curhp, maxhp = UnitHealth(unit), UnitHealthMax(unit)
      if curhp ~= maxhp then
        local perchp, diffhp = 100 * curhp / maxhp, maxhp - curhp
        return "|cff%02x%02x%02x%.0f|r%% | |cffc31d3a-%s|r",cc.r*255,cc.g*255,cc.b*255,perchp,diffhp
      else
        local name = UnitName("player")
        if UnitExists(unit) then
          name = UnitName(unit)
        end
        return "|cff%02x%02x%02x%s|r",cc.r*255,cc.g*255,cc.b*255,string.gsub(name, '%s?(.)%S+%s', '%1. ')
      end
    end
    If you JUST want the name shortener, use this (from the link posted by Ketho above)
    Code:
    function(unit)
    	local name = UnitName(unit) or unit
    	name = name:gsub('(%S+) ',function(t) return t:sub(1,1)..'.' end)
    	return name
    end
    If you want class-coloring in it, just ask, and I'll whip up class coloring with it for ya.
    Thanks mate, but what do i do with this text? Where do i paste it?
    And yes, i would love if it could be class colored<3

    ---------- Post added 2013-01-06 at 05:10 PM ----------

    Quote Originally Posted by Rusk View Post
    Thanks mate, but what do i do with this text? Where do i paste it?
    And yes, i would love if it could be class colored<3
    Anyone? Desperate here lols
    Last edited by Rusk; 2013-01-06 at 12:17 PM.

  12. #12
    Nvm about the "where to put it" question, totaly forgot about the custom lua option.
    But how do i make it class colored? And is there any way to make it look like this? ->

    Name | Perchp

  13. #13
    Scarab Lord Taryble's Avatar
    Join Date
    Aug 2008
    Location
    Texas
    Posts
    4,038
    This is the second (simpler) code, modified for class color and adding " | perchp%" to the end. SHOULD work, but untested.

    Code:
    function(unit)
            local classcolor = RAID_CLASS_COLORS[select(2, UnitClass(unit))]
    	local name = UnitName(unit) or unit
            local perchp = 100 * UnitHealth(unit) / UnitHealthMax(unit)
    	name = name:gsub('(%S+) ',function(t) return t:sub(1,1)..'.' end)
    	return "|cff%02x%02x%02x%s|r || %.0f%%",classcolor.r*255,classcolor.g*255,classcolor.b*255,name,perchp
    end
    We have done the impossible, and that makes us mighty. - Sgt. Malcolm "Mal" Reynolds, Battle of Serenity Valley

  14. #14
    Quote Originally Posted by Taryble View Post
    This is the second (simpler) code, modified for class color and adding " | perchp%" to the end. SHOULD work, but untested.

    Code:
    function(unit)
            local classcolor = RAID_CLASS_COLORS[select(2, UnitClass(unit))]
    	local name = UnitName(unit) or unit
            local perchp = 100 * UnitHealth(unit) / UnitHealthMax(unit)
    	name = name:gsub('(%S+) ',function(t) return t:sub(1,1)..'.' end)
    	return "|cff%02x%02x%02x%s|r || %.0f%%",classcolor.r*255,classcolor.g*255,classcolor.b*255,name,perchp
    end
    Thanks alot mate, i did however change my mind about the class color so how should it look without the class color and with the "name | perchp"?
    Im quessing this is wrong because it didn't work ->

    Code:
    function(unit)
    	local name = UnitName(unit) or unit
            local perchp = 100 * UnitHealth(unit) / UnitHealthMax(unit)
    	name = name:gsub('(%S+) ',function(t) return t:sub(1,1)..'.' end)
    	return name,perchp
    end

  15. #15
    Almost.
    Code:
    return "%s || %.0f%%",name,perchp
    UI & AddOns expert | Interface & Macros moderator - My work

  16. #16
    Dreadlord shanthi's Avatar
    Join Date
    Oct 2011
    Location
    California
    Posts
    821
    Quote Originally Posted by Taryble View Post
    If you JUST want the name shortener, use this (from the link posted by Ketho above)
    Code:
    function(unit)
    	local name = UnitName(unit) or unit
    	name = name:gsub('(%S+) ',function(t) return t:sub(1,1)..'.' end)
    	return name
    end
    How would one preserve the final space? This code, for example, abbreviates "Raider's Training Dummy" into "R.T.Dummy". How would one adjust the code so it returned "R.T. Dummy" (space between the final "." and "Dummy")?

    I apologize for necroing this thread, I was doing a Google search and figured it would be better to extend this thread, since it's on the same subject, than to start a new one.
    That is not dead which can eternal lie.
    And with strange aeons even death may die.

  17. #17
    in this part of the code:

    Code:
    return t:sub(1,1)..'.' end)
    add a space after the .

    Code:
    return t:sub(1,1)..'. ' end)


    AddOn Author of: SpellNotReadyYet, Rune of Powa

  18. #18
    Dreadlord shanthi's Avatar
    Join Date
    Oct 2011
    Location
    California
    Posts
    821
    Quote Originally Posted by SpaceDuck View Post
    in this part of the code:

    Code:
    return t:sub(1,1)..'.' end)
    add a space after the .

    Code:
    return t:sub(1,1)..'. ' end)
    Thanks, but that adds a space after every dot; I just want a space after the final dot. ("R.T. Dummy" not "R. T. Dummy"). I've seen that sort of abbreviation in other UIs, and I think SUF has it as a built-in option. I just prefer STUF for other reasons and wondered if anyone knew how to do this in LUA.
    That is not dead which can eternal lie.
    And with strange aeons even death may die.

  19. #19
    Something like this?

    Code:
    function(unit)
    	local name = UnitName(unit) or unit
    	name = name:gsub('(%S+) ',function(t) return t:sub(1,1)..'.' end)
    	return name:gsub("(%S+)%.(%S+)$","%1. %2")
    end
    UI & AddOns expert | Interface & Macros moderator - My work

  20. #20
    Dreadlord shanthi's Avatar
    Join Date
    Oct 2011
    Location
    California
    Posts
    821
    Quote Originally Posted by Treeston View Post
    Something like this?

    Code:
    function(unit)
    	local name = UnitName(unit) or unit
    	name = name:gsub('(%S+) ',function(t) return t:sub(1,1)..'.' end)
    	return name:gsub("(%S+)%.(%S+)$","%1. %2")
    end
    Perfect, thank you!
    That is not dead which can eternal lie.
    And with strange aeons even death may die.

Posting Permissions

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