Editing overlay text of miniwindow gauges

Posted by Xinefus on Tue 10 Nov 2020 09:30 PM — 6 posts, 23,618 views.

#0
Hey folks,

I have been working with Fiendish's health_bars_gmcp plugin and modified it for my own mud. I'm coding/working on that rare breed dragonball mud (based on smaug) and they have some pretty large numbers in some of their attributes.

The problem I am trying to get around is that when I show the overlay numbers it many times just runs off into the next or previous gauge unless I make the whole set of gauges wider. Not an ideal solution.

I was wondering if there is a way for me to 'truncate' the numbers from lets say 10000 to 10K or 10.0K? I assume I could use something like string.format but I'm not sure how this would work in the case of this plugin while using DoNextSimpleBar().

Any bit of help in this would be appreciated.

Thanks!
#1
I just realised I put this in the wrong sub-forum. It probably should be in the miniwindows sub-forum. Sorry guys. :(
#2
Well, I was a bit premature in asking this question!

I was able to figure it out quite easily once I actually started to read more about DoNextSimpleBar()

I added this
function shorten(val)
    if val >= 10^18 then
      return string.format("%.2fQt", val / 1000000000000000000 )
    elseif val >= 10^15 then
      return string.format("%.2fQu", val / 1000000000000000 )
    elseif val >= 10^12 then
      return string.format("%.2fT", val / 1000000000000 )
    elseif val >= 10^9 then
      return string.format("%.2fB", val / 1000000000 )
    elseif val >= 10^6 then
      return string.format("%.2fM", val / 1000000 )
    elseif val >= 10^3 then
      return string.format("%.2fK", val / 1000 )
    else
      return tostring(val)
    end
end

I then just changed the line in DoNextSimpleBar() to this:
            txt = string.lpad(shorten(num_val), maxlen, ' ').."/"..string.rpad(shorten(num_maxval),maxlen,' ')
USA Global Moderator #3
You could also just string.format the number into scientific notation with %e without looking at it.
Australia Forum Administrator #4
Lua probably pre-calculates constants, but you could change:


if val >= 10^18 then


to


if val >= 10E18 then
#5
Thank you!

It's working so far the way I intend it.

Have a great week.