Originally Posted by
CtrlAltDenied
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