Thread Tools Display Modes
05-01-09, 01:19 PM   #21
jadakren
A Flamescale Wyrmkin
 
jadakren's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2007
Posts: 103
try this :

Code:
local name = "Lightning Charged Iron Dwarf"
local output = ""
local count = 0
local nameCount = 0;string.gsub(name,"(%w+)", function(w) nameCount = nameCount+1 end)


for token in name:gmatch("%a+") do
 count=count+1;
 output = output .. ((count<nameCount) and string.sub(token,1,1)..". " or token)
end

print(output)
I'm sure there is a better/shorter way of returning an integer that represents the amount of words in a string.

possibly even a better way to do this overall, but this outputs :

L. C. I. Dwarf

Last edited by jadakren : 05-01-09 at 01:43 PM.
  Reply With Quote
05-01-09, 01:57 PM   #22
Druidicbeast
A Fallenroot Satyr
Join Date: Feb 2008
Posts: 24
Originally Posted by jadakren View Post
try this :

Code:
local name = "Lightning Charged Iron Dwarf"
local output = ""
local count = 0
local nameCount = 0;string.gsub(name,"(%w+)", function(w) nameCount = nameCount+1 end)


for token in name:gmatch("%a+") do
 count=count+1;
 output = output .. ((count<nameCount) and string.sub(token,1,1)..". " or token)
end

print(output)
I'm sure there is a better/shorter way of returning an integer that represents the amount of words in a string.

possibly even a better way to do this overall, but this outputs :
I will give it a shot when I get home from work tonight. The approach that p3lim was attempting seemed right to me, but I couldn't fix the error message it was giving me.

After testing this though if all works well, what would I be replacing the below with. Certainly this isn't the only mob I want abbreviated, or is that just used as a reference point for length?
Code:
local name = "Lightning Charged Iron Dwarf"
  Reply With Quote
05-01-09, 02:46 PM   #23
Tekkub
A Molten Giant
 
Tekkub's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2005
Posts: 960
Try this:

Code:
for _,v in pairs{"Joereallylongnamewithoutspaces", "Billy Bob", "Green Naked Oversized Mechanical Elf Punter"} do
	 local n = string.gsub(v, "%s?(.)%S+%s", "%1. ")
	 print(n)
end
Also, try to simplify down your logic in the tag, and string together multiple tags when you set up the string:

Code:
oUF.Tags['[afk]'] = function(unit) if UnitIsAFK(unit) then return "AFK" end end

oUF.TagEvents['[abbrevname]'] = 'UNIT_HEALTH UNIT_MAXHEALTH PLAYER_FLAGS_CHANGED'
oUF.Tags['[abbrevname]'] = function(unit)
	if UnitIsDead(unit) or not UnitIsConnected(unit) or UnitIsAFK(unit) or UnitIsGhost(unit) then return end

	local name = UnitName(unit)
	return (string.len(name) > 10) and string.gsub(name, "%s?(.)%S+%s", "%1. ") or name
end
Then you just register your fontstring with something like "[status][afk][raidcolor][abbrevname]"

Note that I don't know what event fires for AFK changes, so you'll have to figure that one out on your own.

Lastly, you don't need to manually truncate your string if it's too long. Set up anchors for both ends of the fontstring and the game will truncate it automatically if needed.
__________________
I have reached enlightment.
Thank you bacon!

Last edited by Tekkub : 05-01-09 at 02:52 PM.
  Reply With Quote
05-01-09, 03:02 PM   #24
Druidicbeast
A Fallenroot Satyr
Join Date: Feb 2008
Posts: 24
Originally Posted by Tekkub View Post
Try this:

Code:
for _,v in pairs{"Joereallylongnamewithoutspaces", "Billy Bob", "Green Naked Oversized Mechanical Elf Punter"} do
	 local n = string.gsub(v, "%s?(.)%S+%s", "%1. ")
	 print(n)
end
Also, try to simplify down your logic in the tag, and string together multiple tags when you set up the string:

Code:
oUF.Tags['[afk]'] = function(unit) if UnitIsAFK(unit) then return "AFK" end end

oUF.TagEvents['[abbrevname]'] = 'UNIT_HEALTH UNIT_MAXHEALTH PLAYER_FLAGS_CHANGED'
oUF.Tags['[abbrevname]'] = function(unit)
	if UnitIsDead(unit) or not UnitIsConnected(unit) or UnitIsAFK(unit) or UnitIsGhost(unit) then return end

	local name = UnitName(unit)
	return (string.len(name) > 10) and string.gsub(name, "%s?(.)%S+%s", "%1. ") or name
end
Then you just register your fontstring with something like "[status][afk][raidcolor][abbrevname]"

Note that I don't know what event fires for AFK changes, so you'll have to figure that one out on your own.

Lastly, you don't need to manually truncate your string if it's too long. Set up anchors for both ends of the fontstring and the game will truncate it automatically if needed.
Your reply is greatly appreciated. I will be trying this as soon as I get home. Also you were quite right, after reading through and trying to make sense of what I could. The previous posted code just seems to be so much more complicated then it needs to be.

Also thanks for the tip on pulling out the other conditionals in another effort to simplify the tag yet again. I will be working on redoing all of this later tonight.

On a side note, does this "Green Naked Oversized Mechanical Elf Punter" come with the infamous bacon button? If so, this machine has me quite interested.
  Reply With Quote
05-01-09, 05:56 PM   #25
Druidicbeast
A Fallenroot Satyr
Join Date: Feb 2008
Posts: 24
You sir are simply amazing, thank you VERY much for your help with this. It works perfect.


I added you to the credits for the tag, let me know if you need me to add anything else.

Last edited by Druidicbeast : 05-01-09 at 06:04 PM.
  Reply With Quote
05-01-09, 06:07 PM   #26
Tekkub
A Molten Giant
 
Tekkub's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2005
Posts: 960
Should make a patch and put it in oUF proper, I could see others wanting it.

Did you find an event for AFK changes? That's something else that should go into oUF directly.
__________________
I have reached enlightment.
Thank you bacon!
  Reply With Quote
05-01-09, 06:27 PM   #27
Druidicbeast
A Fallenroot Satyr
Join Date: Feb 2008
Posts: 24
Originally Posted by Tekkub View Post
Did you find an event for AFK changes? That's something else that should go into oUF directly.
I have not just yet, tbh with you I havn't looked. Although the code appears to be working.....kinda. Under my Tags section I have only this:
Code:
oUF.Tags['[afk]'] = function(unit) if UnitIsAFK(unit) then return "AFK" end end


oUF.TagEvents['[abbrevname]'] = 'UNIT_HEALTH UNIT_MAXHEALTH PLAYER_FLAGS_CHANGED'
oUF.Tags['[abbrevname]'] = function(unit)
	if UnitIsDead(unit) or not UnitIsConnected(unit) or UnitIsAFK(unit) or UnitIsGhost(unit) then 
		return 
	end
	
	local name = UnitName(unit)
	return (string.len(name) > 10) and string.gsub(name, "%s?(.)%S+%s", "%1. ") or name
end
I then added this further down in the code under my layout section
Code:
self.Name = MakeFS(self)
    self:Tag(self.Name, "[difficulty][smartlevel]|r [raidcolor][abbrevname]|r [afk]")
After doing some testing it picks up when I go AFK and when I come back; however, it replaces the name. I have not take an indepth look at the code to find out exactly why. But I am sure it's something small
  Reply With Quote
05-01-09, 07:01 PM   #28
p3lim
A Pyroguard Emberseer
 
p3lim's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2007
Posts: 1,710
Originally Posted by Tekkub View Post
Did you find an event for AFK changes? That's something else that should go into oUF directly.
http://www.wowwiki.com/Events_A-Z_(f..._FLAGS_CHANGED
  Reply With Quote
05-01-09, 07:02 PM   #29
Tekkub
A Molten Giant
 
Tekkub's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2005
Posts: 960
PLAYER_* events usually only fire for the player, UNIT_* is more likely to be what we want, if there even is one.
__________________
I have reached enlightment.
Thank you bacon!
  Reply With Quote
05-01-09, 07:17 PM   #30
Druidicbeast
A Fallenroot Satyr
Join Date: Feb 2008
Posts: 24
Originally Posted by Tekkub View Post
PLAYER_* events usually only fire for the player, UNIT_* is more likely to be what we want, if there even is one.
I guess that would explain why when I had myself targeted it worked. I will get a guild mate later on to test somethings out with.

Edit 1: I knew I saw this someplace, assuming this hasn't changed at all that is. Posted in the massive layout thread here:
Originally Posted by P3lim
PLAYER_FLAGS_CHANGED is the event

(dont be fooled by the name of the event, it works for any unit)

Last edited by Druidicbeast : 05-01-09 at 07:31 PM.
  Reply With Quote
05-01-09, 08:11 PM   #31
p3lim
A Pyroguard Emberseer
 
p3lim's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2007
Posts: 1,710
Originally Posted by Tekkub View Post
PLAYER_* events usually only fire for the player, UNIT_* is more likely to be what we want, if there even is one.
The event is named wrong, thats all, it works for all units, ive tested this quite alot.
arg1 is the unit in question. (no other arguments)
  Reply With Quote
06-10-09, 04:11 PM   #32
Qupe
A Warpwood Thunder Caller
 
Qupe's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 92
I also used this DogTag when I was using Pitbull. I'm not anywhere near a master of lua at all so I was wondering where in the layout (or wherever) I would put this code to produce the abbreviated name.
  Reply With Quote
07-28-09, 05:24 AM   #33
ckaotik
A Fallenroot Satyr
 
ckaotik's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2008
Posts: 29
This works like a miracle if just ...
special characters such as the German ä,ö,ü,ß etc. don't show up correctly and mess the whole thing up any ideas how to fix this?
  Reply With Quote
07-28-09, 10:03 AM   #34
Fuzzywuzzy
A Black Drake
 
Fuzzywuzzy's Avatar
Join Date: Oct 2007
Posts: 84
maybe use:

Ä = \195\132
ä = \195\164
Ö = \195\150
ö = \195\182
Ü = \195\156
ü = \195\188
ß = \195\159

instead of the letters.
  Reply With Quote
07-28-09, 01:31 PM   #35
jadakren
A Flamescale Wyrmkin
 
jadakren's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2007
Posts: 103
Originally Posted by Qupe View Post
I also used this DogTag when I was using Pitbull. I'm not anywhere near a master of lua at all so I was wondering where in the layout (or wherever) I would put this code to produce the abbreviated name.
Code:
--this part goes near the top of your layout, before the style function

oUF.Tags["[abbreviatedname]"] = [[function(u)
 local name = UnitName(u)
 return (string.len(name) > 10) and string.gsub(name, "%s?(.)%S+%s", "%1. ") or name
end
	]]
oUF.TagEvents["[abbreviatedname]"] = "UNIT_NAME_UPDATE"


-- snip, next part is inside your style function.

local name = self.Health:CreateFontString(nil, 'OVERLAY', 'GameFontHighlightSmallLeft')
name:SetPoint('LEFT',self.Health) --replace this line with your own positioning code
name:SetPoint('RIGHT',self.Health) --replace this line with your own positioning code
self:Tag(name, '[abbreviatedname]')
self.Name = name
  Reply With Quote
07-28-09, 05:09 PM   #36
ckaotik
A Fallenroot Satyr
 
ckaotik's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2008
Posts: 29
Originally Posted by Fuzzywuzzy View Post
maybe use:

Ä = \195\132
ä = \195\164
Ö = \195\150
ö = \195\182
Ü = \195\156
ü = \195\188
ß = \195\159

instead of the letters.
Well, the problem is rather that it's regular expressions but with some help I/we came up with
Code:
local name = UnitName(unit)
name = (string.len(name) > 10) and string.gsub(name, "%s?([\128-\196].)%S+%s", "%1. ") or name
return (string.len(name) > 10) and string.gsub(name, "(%s?)([^\128-\196])%S+%s", "%1%2. ") or name
So basically adding a second gsub to check once for non-standard letters and once for standard ones. So what happens?
Überlebender der Draenei (\195\156berlebender der Draenei) turns into "Ü. der Draenei" (\195\156. der Draenei) as "Ü" is a non-standard character.
Then it matches the remaining partial words starting with standard characters and finally we get "Ü. d. Draenei" (\195\156. d. Draenei)
  Reply With Quote

WoWInterface » Featured Projects » oUF (Otravi Unit Frames) » Converting DogTag for use with oUF

Thread Tools
Display Modes

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