1. #1

    Custom Lua Tag StUF

    I don't know if it's possible to do with just the infotags that come with StUF, but what I want is for my HP/MP to have the current value without decimals. I've looked just about everywhere for info on this and couldn't find anything, so I figure I probably need a custom lua tag to do it. So, if anyone knows how to do it, I would be in your debt.

    Thanks in advance.

  2. #2
    Code:
    function(unit, cache, textframe) 
    return UnitPower("Player")
    end
    Should work for resources (Change the unitID to whatever one matches the frame it's in it doesn't have to be player).

    Code:
    function(unit, cache, textframe)
    return UnitHealth("Player") 
    end
    For health, again change as needed.

    If I misinterpreted what you want and you actually wanted a bit more formatting than that let me know but I think this should cover what you described.

    Alternatively there is a number shortening section under global if you don't want to use the "K"/"M" syntax for anything (you can set a minimum number to shorten and syntax to do so) however changing it will affect any numbers in stuf not just mana/health.
    Last edited by Zulandia; 2015-12-26 at 10:58 PM.

  3. #3
    Well, this is somewhat right :P

    Originally it would be "160.0k" and now its "160000". What I actually wanted was it to be was "160k". Also, tried the number shortening, didn't seem to do anything :c

  4. #4
    Okay. Do you want 'M' syntax too or just 1000k? What about small numbers? I'll write you something up once I hear back

  5. #5
    Yea M and K are good. What do you mean by small numbers?

  6. #6
    Quote Originally Posted by slothington View Post
    Yea M and K are good. What do you mean by small numbers?
    Less than 1,000. If you're wanting numbers abbreviated as 160k, or 0.16m, a number such as 560 would be 0.00056m, which is rather absurd, and would be left as 560.

    Most implementations simply do something like

    if num > 1e6 then return ("%.2fm"):format(num/1e6)
    elseif num > 1e3 then return ("%.2fk"):format(num/1e3)
    else return ("%.2f"):format(num) end

    so that may be what Zalundia is looking to do here as well.

    edit to keep decimals, kind of forgot about them lol
    Last edited by Xundir; 2015-12-29 at 01:33 AM.

  7. #7
    Ya pretty much. If you drop the decimal and still use k/m syntax you get some weird looking cases when dealing with small numbers. Think about if you were levelling an alt; at very low levels it probably only has a few thousand health (let's call it 1000 for simplicity). That means the number on your unit frame will only ever read 1k or 0 which isn't very helpful for telling you what you actually have.

    So basically what I was asking if there is some threshold that you would drop the k/m syntax as Xundir described.

  8. #8
    Thats what I was thinking he was talking about, but that seemed a bit...too much lol. But yes, if its less than 1k, than just the whole number and if its a million or more than I would like the M.

  9. #9
    Something like this should work for you then. Let me know if something doesn't work/not quite what you wanted still.
    Resource:
    Code:
    function(unit, cache, textframe) 
    power=tonumber(UnitPower("Player"))
    if power>=1000000 then
    return tostring(floor(power/1000000)) .. "M"
    elseif power>=1000 then
    return tostring(floor(power/1000)) .. "K"
    else
    return power
    end
    end
    Health:
    Code:
    function(unit, cache, textframe) 
    health=tonumber(UnitHealth("Player"))
    if health>=1000000 then
    return tostring(floor(health/1000000)) .. "M"
    elseif health>=1000 then
    return tostring(floor(health/1000)) .. "K"
    else
    return health
    end
    end
    Last edited by Zulandia; 2015-12-29 at 04:17 AM.

  10. #10
    Works perfectly, Thanks a ton for your time and patience

  11. #11
    Hey, sorry to revive this thread, but I just noticed this. The health doesn't update unless I switch targets. I guess I should've noticed something like this from the beginning, but I guess I was less focused on the actual hp on the things I was killing (lol). Any way of fixing this?

Posting Permissions

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