1. #1

    [Stuf Unit Frames] More Precise Current HP

    So I really like this unit frame addOn, the only problem is how the HP is displayed for level 110 characters. Our health is in the single millions, which with Stuf, tends to display a representation that isn't as precise as I'd like it to be.

    Example:

    Actual HP: 1766460
    HP Shown: 1.8m

    My goal: 1.77m

    I'd just like it to be a bit more precise. If it displays hundred thousandths, tens of millions, or hundreds of millions, it's exactly how I want it. Only the single millions category is the exception.



    I lot of the other unit frames do read it correctly as 1.77m, but this one doesn't. Would anyone know the correct LUA code to implement this? The addOn has its own dedicated LUA code box to do this in. I just don't know LUA.

  2. #2
    Code:
    function()
    			local v = UnitHealth(unit)
    		if abs(v) >= 1e9 then
    			return format("%.2fB", v / 1e9)
    		elseif abs(v) >= 1e6 then
    			return format("%.2fM", v / 1e6)
    		elseif abs(v) >= 1e3 then
    			return format("%.1fk", v / 1e3)
    			else
    				return format("%d", v)
    			end
    		end
    	end

    Not sure if stuf requires the code to name the unit if so just change unit to "player" or "target"

  3. #3
    Try this, check the frequent updates option, and use Lua:

    Player

    function()
    if UnitIsDead("player") then
    return "0"
    end

    local health = UnitHealth("player")
    if health >= 1000000 then
    health = string.format("%.1fm", health / 1000000) -- 2.4m
    elseif health >= 10000 then
    health = string.format("%dk", health / 1000) -- 24k, 240k
    elseif health >= 1000 then
    health = string.format("%.1fk", health / 1000) -- 2.4k
    end

    if UnitIsDead("player") then
    return "0"
    end

    local myhp = string.format("%.f", (UnitHealth("player")/UnitHealthMax("player"))*100)

    return string.format("%s", health)
    end



    Target

    function()
    if UnitIsDead("target") then
    return "0"
    end

    local health = UnitHealth("target")
    if health >= 1000000 then
    health = string.format("%.1fm", health / 1000000) -- 2.4m
    elseif health >= 10000 then
    health = string.format("%dk", health / 1000) -- 24k, 240k
    elseif health >= 1000 then
    health = string.format("%.1fk", health / 1000) -- 2.4k
    end

    if UnitIsDead("target") then
    return "0"
    end

    local targethp = string.format("%.f", (UnitHealth("target")/UnitHealthMax("target"))*100)

    return string.format("%s", health)
    end

  4. #4
    Thank you for trying guys. @Lastbreath unfortunately this didn't do the trick. Still showing up as 1.8M.

  5. #5
    Quote Originally Posted by Lord of Outland View Post
    Thank you for trying guys. @Lastbreath unfortunately this didn't do the trick. Still showing up as 1.8M.
    I'm at work atm, will check at home tonight, but what you can try is change this line's:

    local myhp = string.format("%.f", (UnitHealth("player")/UnitHealthMax("player"))*100)

    and

    local targethp = string.format("%.f", (UnitHealth("target")/UnitHealthMax("target"))*100)

    to

    local myhp = string.format("%.01fk", (UnitHealth("player")/UnitHealthMax("player"))*100)

    and

    local targethp = string.format("%.01fk", (UnitHealth("target")/UnitHealthMax("target"))*100)
    - - - Updated - - -

    ok this should work:

    function()
    local health = UnitHealth("target")
    local abbr = ""
    if health >= 1000 then
    health = health / 1000
    abbr = "k"
    end
    if health >= 1000 then
    health = health / 1000
    abbr = "m"
    end

    return ("%.2f%s"):format(health, abbr)
    end

  6. #6
    Perfect, it worked! Thank you, you are awesome.


Posting Permissions

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