Thread Tools Display Modes
07-14-15, 08:01 AM   #1
LiNK2088
A Deviate Faerie Dragon
AddOn Compiler - Click to view compilations
Join Date: Aug 2009
Posts: 10
Removing realm name

I've got this addon which shows when a player in the raid uses an important cooldown, but I can't seem to manage to remove the realm from the users name.
Heres a part of the code:

Code:
local function spellUsed(spell, sourceGUID, targetGUID, sourceName, targetName, duration)

	local duration = duration or spell.len
	local descriptor = spell.id .. sourceGUID;

	local label;
	local soundfile;

	raidN = GetNumGroupMembers()
	local i = 0
	local isingroup = 0
	
	if (raidN == 0) then 
		member = getgroupUnitInfo(1)
	
		if member == sourceName then isingroup = 1; end
	else
		for i = 0,raidN do
			member = getgroupUnitInfo(i)
			if member == sourceName then isingroup = 1; end
			i = i + 1
		end
	end

	if isingroup == 0 then return; end
	
	if(spell.mt) then 
		label = spell.name .. " (" .. sourceName .. ")"
	else
		label = spell.name .. " (" .. sourceName .. " -> " .. targetName .. ")"
	end
end
After some googling I tried adding this to the code

Code:
	--sourceName = sourceName:match("^([^-]+)")
	--targetName = targetName:match("^([^-]+)")
It does remove the realm from the name, but it seems to completely hide the event when the user is from my realm.
  Reply With Quote
07-14-15, 10:16 AM   #2
Banknorris
A Chromatic Dragonspawn
 
Banknorris's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2014
Posts: 153
just change the label code

Code:
if(spell.mt) then 
		label = spell.name .. " (" .. sourceName:match("[^-]+") .. ")"
	else
		label = spell.name .. " (" .. sourceName:match("[^-]+").. " -> " .. targetName:match("[^-]+") .. ")"
	end
__________________
"In this world nothing can be said to be certain, except that fractional reserve banking is a Ponzi scheme and that you won't believe it." - Mandrill

Last edited by Banknorris : 07-14-15 at 10:19 AM.
  Reply With Quote
07-14-15, 12:29 PM   #3
LiNK2088
A Deviate Faerie Dragon
AddOn Compiler - Click to view compilations
Join Date: Aug 2009
Posts: 10
Originally Posted by Banknorris View Post
just change the label code

Code:
if(spell.mt) then 
		label = spell.name .. " (" .. sourceName:match("[^-]+") .. ")"
	else
		label = spell.name .. " (" .. sourceName:match("[^-]+").. " -> " .. targetName:match("[^-]+") .. ")"
	end
Works, ty
  Reply With Quote
07-14-15, 02:13 PM   #4
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,326
You should check the GUID to see if it's a player before parsing the name. There are a few NPCs that have hyphenated names and I've seen addons glitch when these are encountered.

Code:
if(spell.mt) then 
	label = spell.name .. " (" .. (sourceGUID:find("^Player") and sourceName:match("[^-]+") or sourceName) .. ")"
else
	label = spell.name .. " (" .. (sourceGUID:find("^Player") and sourceName:match("[^-]+") or sourceName) .. " -> " .. (targetGUID:find("^Player") and targetName:match("[^-]+") or targetName) .. ")"
end
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)

Last edited by SDPhantom : 07-14-15 at 02:19 PM.
  Reply With Quote
07-15-15, 01:46 PM   #5
Gethe
RealUI Developer
 
Gethe's Avatar
Premium Member
Featured
Join Date: Sep 2008
Posts: 942
You could also use Ambiguate:

Code:
if (spell.mt) then 
	label = spell.name .. " (" .. Ambiguate(sourceName, "short") .. ")"
else
	label = spell.name .. " (" .. Ambiguate(sourceName, "short") .. " -> " .. Ambiguate(targetName, "short") .. ")"
end
Not sure how this would work with NPC names though.
__________________
Knowledge = Power; Be OP

  Reply With Quote
07-15-15, 03:44 PM   #6
Lombra
A Molten Giant
 
Lombra's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 554
Originally Posted by Gethe View Post
You could also use Ambiguate:

Code:
if (spell.mt) then 
	label = spell.name .. " (" .. Ambiguate(sourceName, "short") .. ")"
else
	label = spell.name .. " (" .. Ambiguate(sourceName, "short") .. " -> " .. Ambiguate(targetName, "short") .. ")"
end
Not sure how this would work with NPC names though.
Ambiguate is pretty smart; it should not remove NPC names. Didn't know about "short" option. Is that new?
__________________
Grab your sword and fight the Horde!
  Reply With Quote
07-15-15, 04:38 PM   #7
Gethe
RealUI Developer
 
Gethe's Avatar
Premium Member
Featured
Join Date: Sep 2008
Posts: 942
Originally Posted by Lombra View Post
Didn't know about "short" option. Is that new?
They might have added it in 6.0. The only place in Blizz's code where "short" is used is in the LFGList, which was added as part of the new Premade Group Finder
__________________
Knowledge = Power; Be OP

  Reply With Quote
07-15-15, 05:18 PM   #8
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,326
Originally Posted by Lombra View Post
Ambiguate is pretty smart; it should not remove NPC names.
From the table of effects, I don't see it being that smart with the decision on whether or not to remove the realm name. I highly doubt it would do a lookup to match a name to GUID and see if it's a player. What's likely for it to do is split the name into character and realm, then for the various output types, compare the realm to your current one and the character to your guild roster.

You can probably test it running the following command and see what it prints out.
Code:
/dump Ambiguate("abcd-efgh","short")
This shouldn't match any characters or realms. If it returns only "abcd", then I wouldn't use this function.
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)
  Reply With Quote
07-15-15, 06:52 PM   #9
Lombra
A Molten Giant
 
Lombra's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 554
It's smart from my experience so far, I should say. Using the "guild" option for example, it removes the realm as long as no one else with the same name on a different realm is in the guild.

I just tried short though, and it does just remove stupidly.
__________________
Grab your sword and fight the Horde!
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Removing realm name


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