Thread Tools Display Modes
11-14-10, 02:01 PM   #1
Dajova
A Wyrmkin Dreamwalker
 
Dajova's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2007
Posts: 58
Short names on nameplates

I know i saw this somewhere in dNameplates for some months ago or something, a way to shorten down the names on the nameplates, but i forgot how it was done.

Example:
Sunreaver Guardian Mage
->
S. G. Mage

Anyone remembers how to make this possible?
__________________
Livestream | Twitter | YouTube
  Reply With Quote
11-14-10, 02:08 PM   #2
Ither
A Firelord
 
Ither's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2009
Posts: 497
Originally Posted by Dajova View Post
I know i saw this somewhere in dNameplates for some months ago or something, a way to shorten down the names on the nameplates, but i forgot how it was done.

Example:
Sunreaver Guardian Mage
->
S. G. Mage

Anyone remembers how to make this possible?
Look at caelNameplates-- he does it in one of his libraries.

I'm not at home so I can't pull the code and show you.
__________________
  Reply With Quote
11-14-10, 02:16 PM   #3
Dajova
A Wyrmkin Dreamwalker
 
Dajova's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2007
Posts: 58
Originally Posted by StormCalai View Post
Look at caelNameplates-- he does it in one of his libraries.

I'm not at home so I can't pull the code and show you.
All i could find was this string:
Code:
	local newName = (string.len(oldName) > 20) and string.gsub(oldName, "%s?(.[\128-\191]*)%S+%s", "%1. ") or oldName -- "%s?(.)%S+%s"


edit: can't seem to get it to work :/ always says that a string is missing, even tho i have that function in my code. must be something else missing
__________________
Livestream | Twitter | YouTube

Last edited by Dajova : 11-14-10 at 03:08 PM.
  Reply With Quote
11-14-10, 03:48 PM   #4
Ither
A Firelord
 
Ither's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2009
Posts: 497
Originally Posted by Dajova View Post
All i could find was this string:
Code:
	local newName = (string.len(oldName) > 20) and string.gsub(oldName, "%s?(.[\128-\191]*)%S+%s", "%1. ") or oldName -- "%s?(.)%S+%s"


edit: can't seem to get it to work :/ always says that a string is missing, even tho i have that function in my code. must be something else missing
Post the error if you can.

And your code.
__________________
  Reply With Quote
11-14-10, 07:32 PM   #5
Dajova
A Wyrmkin Dreamwalker
 
Dajova's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2007
Posts: 58
Originally Posted by StormCalai View Post
Post the error if you can.

And your code.
I am pretty much certain that ive done it wrong, but...

function:
http://www.pastey.net/142876

code:
Code:
	--Set the name text
	frame.name:SetText(frame.oldname:GetText())
	local newname = (string.len(oldname) > 20) and string.gsub(oldname, "%s?(.[\128-\191]*)%S+%s", "%1. ") or oldname -- "%s?(.)%S+%s"
if you can point me in the right direction, it would be nice pretty much lost here...

edit: i dont have a error report atm, cause im just about to turn off the comp, but it said that string.len returned nil
__________________
Livestream | Twitter | YouTube
  Reply With Quote
11-14-10, 07:49 PM   #6
Ither
A Firelord
 
Ither's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2009
Posts: 497
Originally Posted by Dajova View Post
I am pretty much certain that ive done it wrong, but...

function:
http://www.pastey.net/142876

code:
Code:
	--Set the name text
	frame.name:SetText(frame.oldname:GetText())
	local newname = (string.len(oldname) > 20) and string.gsub(oldname, "%s?(.[\128-\191]*)%S+%s", "%1. ") or oldname -- "%s?(.)%S+%s"
if you can point me in the right direction, it would be nice pretty much lost here...

edit: i dont have a error report atm, cause im just about to turn off the comp, but it said that string.len returned nil
How is the function declared in your files? All in the same file or separate?

I see that you renamed caelLibs.utf8sub, which still requires a proper name in order to execute. The error is returned because the shorten function is not properly declared.

Can you post your files? or link them to pastey and describe your file layout?
__________________
  Reply With Quote
11-14-10, 08:06 PM   #7
Dawn
A Molten Giant
 
Dawn's Avatar
AddOn Author - Click to view addons
Join Date: May 2006
Posts: 918
You need to include this function

Code:
-- string format
local utf8sub = function(string, i, dots)
	local bytes = string:len()
	if (bytes <= i) then
		return string
	else
		local len, pos = 0, 1
		while(pos <= bytes) do
			len = len + 1
			local c = string:byte(pos)
			if (c > 0 and c <= 127) then
				pos = pos + 1
			elseif (c >= 192 and c <= 223) then
				pos = pos + 2
			elseif (c >= 224 and c <= 239) then
				pos = pos + 3
			elseif (c >= 240 and c <= 247) then
				pos = pos + 4
			end
			if (len == i) then break end
		end

		if (len == i and pos <= bytes) then
			return string:sub(1, pos - 1)..(dots and '...' or '')
		else
			return string
		end
	end
end

And put this in your nameplate's update function ...
Code:
	local oldName = self.oldname:GetText()
	local newName = (string.len(oldName) > 14) and string.gsub(oldName, "%s?(.[\128-\191]*)%S+%s", "%1. ") or oldName 
	self.name:SetText(newName)
The red number defines the maximum length of a name before it gets abbreviated.
__________________
Rock: "We're sub-standard DPS. Nerf Paper, Scissors are fine."
Paper: "OMG, WTF, Scissors!"
Scissors: "Rock is OP and Paper are QQers. We need PvP buffs."

"neeh the game wont be remembered as the game who made blizz the most money, it will be remembered as the game who had the most QQ'ers that just couldnt quit the game for some reason..."

  Reply With Quote
11-14-10, 08:24 PM   #8
Dajova
A Wyrmkin Dreamwalker
 
Dajova's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2007
Posts: 58
Originally Posted by Dawn View Post
You need to include this function
Ah, thx for the help i knew i did something wrong, but i wasn't that far away

Works flawlessly now
http://screenshot.xfire.com/s/106868825-4.jpg
__________________
Livestream | Twitter | YouTube
  Reply With Quote
11-14-10, 09:43 PM   #9
Ither
A Firelord
 
Ither's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2009
Posts: 497
Looks good--

I was hoping to help "you" figure out the problem instead of giving you the solution. It's the natural teacher in me, why I'm in education LOL.
__________________
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Short names on nameplates


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off