As you've seen "unit" can't accept names like "Carl". "unit" expects "player", "party1", "party3", etc.
The simplest way is to search for someone named Carl in the raid or party:
Code:
local function NameIsGrouped(name)
local inGroup
if GetNumPartyMembers()>0 then
for i=1,4 do
inGroup = inGroup or (UnitName("party"..i)==name)
end
end
if not inGroup and GetNumRaidMembers()>0 then
for i=1,40 do
inGroup = inGroup or (UnitName("raid"..i)==name)
end
end
return inGroup
end
Then in your code:
Code:
OnEvent:
if event=="CHAT_MSG_WHISPER" and NameIsGrouped(arg2 or "") then
--[[ someone in party/raid sent you that whisper ]]
end
Many balk at doing a loop like that on a whisper fearing it will be some performance hit, but the reality is it would take *a lot* of whispers for that to happen, much more than someone can reasonably expect to get.
If you really do plan on receiving *a lot* of whispers (like hundreds a second), you can set up a lookup table:
Code:
NamesInGroup = {}
local function PopulateNamesInGroup()
for i in NamesInGroup do
NamesInGroup[i] = nil
end
for i=1,4 do
if UnitExists("party"..i) then NamesInGroup[UnitName("party"..i)]=1 end
end
for i=1,40 do
if UnitExists("raid"..i) then NamesInGroup[UnitName("raid"..i)]=1 end
end
end
OnLoad:
this:RegisterEvent("CHAT_MSG_WHISPER")
this:RegisterEvent("PARTY_ROSTER_CHANGED")
this:RegisterEvent("RAID_ROSTER_CHANGED")
this:RegisterEvent("PLAYER_LOGIN")
OnEvent:
if event=="CHAT_MSG_WHISPER" and NamesInGroup[arg2 or ""] then
--[[ someone in raid or party sent a whisper]]
else
PopulateNamesInGroup()
end
But if you're doing this because you're concerned about performance, don't stop there. The above will contribute to the mini lockup most experience when a party turns into a raid or when the raid changes. (Again I don't think performance is critical in reacting to whispers. In OnUpdates sure, in UNIT_HEALTH definitely, but something that happens infrequently, simplicity is good. I would prefer the first method at the top instead of contributing to the mini lockups.) To avoid the mini lockups, you'll want to only react to changes after a spasm of changes are done:
Code:
XML:
<Frame name="MyModFrame" ... hidden="true">
<Scripts>
...
<OnUpdate>
MyMod_OnUpdate()
</OnUpdate>
</Scripts>
</Frame>
NamesInGroup = {}
local function PopulateNamesInGroup()
for i in NamesInGroup do
NamesInGroup[i] = nil
end
for i=1,4 do
if UnitExists("party"..i) then NamesInGroup[UnitName("party"..i)]=1 end
end
for i=1,40 do
if UnitExists("raid"..i) then NamesInGroup[UnitName("raid"..i)]=1 end
end
end
OnLoad:
this:RegisterEvent("CHAT_MSG_WHISPER")
this:RegisterEvent("PARTY_ROSTER_CHANGED")
this:RegisterEvent("RAID_ROSTER_CHANGED")
this:RegisterEvent("PLAYER_LOGIN")
OnEvent:
if event=="CHAT_MSG_WHISPER" and NamesInGroup[arg2 or ""] then
--[[ someone in raid or party sent a whisper]]
else
this.timer = 0
this:Show()
end
function MyMod_OnUpdate()
this.timer = this.timer + arg1
if this.timer > .5 then
this:Hide()
PopulateNamesInGroup()
end
end
That will react to roster changes .5 seconds after the last of a roster spasm happens. So if you join a full raid of 39 people, PopulateNamesInGroup only runs once. If you join a group with one person in it, PopulateNamesInGroup only runs once.
But I'd ignore most of this post and do the first method.