Thread Tools Display Modes
01-16-07, 02:08 PM   #1
yssaril
A Warpwood Thunder Caller
 
yssaril's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2007
Posts: 96
Question UnitInRaid

i am trying to use UnitInRaid to check that my trade partner is in the raid but the function always returns nil

when i use UnitInParty it works for partymembers

is there something i need to do different with UnitInRaid?
  Reply With Quote
01-18-07, 05:28 PM   #2
naaokth
A Kobold Labourer
Join Date: Jan 2006
Posts: 1
Hi,

you can try this ...


if (GetNumRaidMembers() > 0) then
local MyTarget = UnitName("target")
for i=1, MAX_RAID_MEMBERS do
local name, _, _, _, _, _, _, _, _ = GetRaidRosterInfo(i); --[[name, rank, subgroup, level, class, fileName, zone, online, isDead]]--
if name and (MyTarget :lower() == name:lower() ) then
--Then your target is in the RAIDGROUP
end
end
end
  Reply With Quote
01-19-07, 10:54 PM   #3
yssaril
A Warpwood Thunder Caller
 
yssaril's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2007
Posts: 96
thanks for your post but i actually just figured it out by studying other code

i was using

if UnitInParty("NPC") == 1 then
-- do some stuff
end
if UnitInRaid("NPC") == 1 then
-- do some stuff
end

the problem here was that even though u might think both functions work the same they do not UnitInParty will return either 1 or nil
while UnitInRaid will return True of False

as such my code now looks like this
if UnitInParty("NPC") == 1 then
-- do some stuff
end
if UnitInRaid("NPC") then
-- do some stuff
end
  Reply With Quote
03-06-09, 10:06 PM   #4
eliljey
A Deviate Faerie Dragon
Join Date: Feb 2009
Posts: 14
Pardon me for resurrecting an old thread, but I'm trying to figure out how to use UnitInRaid/UnitInParty to see if a name is in my current raid. My addon has a text box that I type a name into and I just want a simple check to see if it's a valid name of someone in my group/raid.

I can pass UnitInParty a specific name:
UnitInParty("eliljey")

But I can't pass it the text string from a text box.
UnitInParty(TextBox:GetText())

The only thing I can think is that UnitInParty requires a text string encompassed in quotes and that doing the TextBox get produces a raw string variable with no quotes.

Any tips on how to do this?
  Reply With Quote
03-06-09, 10:28 PM   #5
Dridzt
A Pyroguard Emberseer
 
Dridzt's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2005
Posts: 1,360
Make sure your editbox:GetText() actually returns a string.

There's no difference between passing it a literal string like "eliljey"
and the return from GetText().
(assuming you haven't inadvertently typed in an extra space or some such)

Maybe assign the return from GetText() to a string variable
and test that it doesn't contain blank characters before passing it to UnitInParty()?

You can use a lua pattern to test for the presence of space characters.
(or just run cleanstring = strtrim(mystring) on it)

Last edited by Dridzt : 03-06-09 at 10:37 PM.
  Reply With Quote
03-07-09, 04:18 AM   #6
Mera
Retired of WoW, In ESO :)
 
Mera's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Apr 2008
Posts: 331
you can do that way too I prefer second method me

Code:
local function IsIn()
	if select(2, IsInInstance()) == "raid" or select(2, IsInInstance()) == "party" then return "Instance"
	elseif select(2, IsInInstance()) == "pvp" or select(2, IsInInstance()) == "arena" then return "BG"
	elseif select(2, IsInInstance()) == "none" then return "none" end
	return false
end
if IsIn() == "BG"/"Instance"/"none"

just one api used to check that unlike your method
__________________
If you need to reach me I'm in ESO, @class101 or "Fathis Ules i"
addons: SpamBayes, BrokerCPU
projects: ThunderBayes
Mera[xeh]? - La CroisadeEcarlate (wow)
  Reply With Quote
03-07-09, 04:37 AM   #7
Shirik
Blasphemer!
Premium Member
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2007
Posts: 818
Not only should select() not be used for a trivial purpose like this, your repeated calls of IsInInstance() scares me.

Your code performance could be improved about 10-fold if you would just get rid of all those calls.

local _, type = IsInInstance();

if type == "raid" then ...


select() should never be used for a purpose like that; it is not what it was designed for, and detracts from performance with no other benefit other than satisfying laziness in such a case. In addition, the repeated calls is again both lazy and unnecessary.
__________________
たしかにひとつのじだいがおわるのお
ぼくはこのめでみたよ
だけどつぎがじぶんおばんだってことわ
しりたくなかったんだ
It's my turn next.

Shakespeare liked regexes too!
/(bb|[^b]{2})/
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » UnitInRaid


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