This site makes extensive use of JavaScript.
Please enable JavaScript in your browser.
Live
PTR
10.2.7
PTR
10.2.6
Beta
Lua code limit name characters
Post Reply
Return to board index
Post by
funside
Could anyone create a lua code for me that limits the characters in the target's name to 5?
The lua format must apparently follow this:
function(unit, cache, textframe) return 'text' end
Any help is appreciated!
Post by
Ketho
Not sure what you mean with "lua format", but .. can you try this?/run hooksecurefunc("UnitFrame_Update",function(self)if self:GetName()=="TargetFrame"then self.name:SetText(strsub(GetUnitName(self.unit),1,5))end end)
Post by
funside
Uhm it's for Stuf UF addon, to limit the characters of my target's name so that it will fit in my health bar.
Can't log in to test that atm since the servers are down but I'm pretty sure it's not what I'm looking for, thanks though.
Edit: it says in the config lua box that "it must follow this lua format: ..." now I don't know anything about lua coding but guessing you must write it in that order.
Post by
550132
This post was from a user who has deleted their account.
Post by
HighFive
Obligatory note about multibyte characters.
Post by
funside
Thanks a lot! Will test it out as soon as servers come online :)
Post by
funside
Logged in to test it and it doesn't work as expected. It makes the name start at the 5th letter and then continue to the full one, I want it to start at letter 1 and end at 5th.
Post by
22686
This post was from a user who has deleted their account.
Post by
funside
Thanks, both worked just fine now :)
Also I'd love to learn lua but I haven't found a good beginner's guide that doesn't make my face go ಠ__ಠ (as did your comment btw).
I have come up with another request though (if it's possible in lua even). In Shadowed UF there was a name option that was like:
(abbreviate name) and it made things shortened in a different way.
Raider's Training Dummy > R.T. Dummy
Master Wood > M. Wood
Training Dummy > T. Dummy
etc.
Is this possible with lua coding?
Post by
550132
This post was from a user who has deleted their account.
Post by
funside
Heh.. well as I said I don't know sh!t :p
Thanks a bunch even for the effort! That code didn't work though, getting the error message
Message: :3: attempt to index global 'text' (a nil value)
Time: 06/27/12 21:32:27
Count: 3
Stack: :3: in function <:3>
: in function `gsub'
:3: in function `textcode'
Interface\AddOns\Stuf\text.lua:116: in function `func'
Interface\AddOns\Stuf\core.lua:812: in function <Interface\AddOns\Stuf\core.lua:782>
Interface\AddOns\Stuf\core.lua:821: in function `?'
Interface\AddOns\Stuf\core.lua:109: in function <Interface\AddOns\Stuf\core.lua:108>
: in function `CameraOrSelectOrMoveStop'
:4: in function <:1>
Locals: t = "Training"
(*temporary) = nil
(*temporary) = nil
(*temporary) = nil
(*temporary) = nil
(*temporary) = "attempt to index global 'text' (a nil value)"
Post by
550132
This post was from a user who has deleted their account.
Post by
funside
Hmm doesn't seem to work for me.. nothing shows up :(
Post by
550132
This post was from a user who has deleted their account.
Post by
funside
Cheers it works :D thank you very much kind sir!
oooh actually can you make it so that it limits to 7 letters as well? <3
Post by
550132
This post was from a user who has deleted their account.
Post by
funside
Works superb, thanks!
Post by
HighFive
Captain Planet:
function(unit)
local name = UnitName(unit) or unit
name = name:gsub('(*)%S* ', '%1. '))
local shortname=""
name:gsub("(*)",function(a)shortname=shortname..a end,7)
return shortname
end
Post by
Conditioned
function(unit)
local name = UnitName(unit) or unit
name = name:gsub('(%S+) ',function(t) return t:sub(1,1)..'.' end)
return name
end
This shortens the name automatically. Ie "Dragonmaw Peon" becomes "Dragon. P."
Post by
Neffi
I wish somebody would make me a mod so I could rid the forums of these types of redundancies.
Post Reply
You are not logged in. Please
log in
to post a reply or
register
if you don't already have an account.