Thread Tools Display Modes
12-11-10, 06:15 AM   #1
weasoug
A Flamescale Wyrmkin
 
weasoug's Avatar
AddOn Author - Click to view addons
Join Date: May 2010
Posts: 127
realid aiv

hey all i wanted to add a auto freind invite that supports realid. but with no luck, this is what i have. thanks for your time

Code:
	eventHandlers['PARTY_INVITE_REQUEST'] = function(name)
		local accept
		ShowFriends()
		for index = 1, GetNumFriends() do
			if GetFriendInfo(index) == name then
				accept = true
				break
			end
		end
		if not accept and IsInGuild() then
			GuildRoster()
			for index = 1, GetNumGuildMembers() do
				if GetGuildRosterInfo(index) == name then
					accept = true
					break
				end
			end
		end
		if not accept then
			for index = 1, BNGetFriendToonInfo() do
				if GetRealmName(index) == name then
					accept = true
					break
				end
			end
		end
		if accept then
			name = StaticPopup_Visible('PARTY_INVITE')
			if name then
				StaticPopup_OnClick(_G[name], 1)
				return
			end
		else
			SendWho('n-"' .. name .. '"')
		end
	en
__________________
wMmap :: Is a lightweight Minimap, with a sleek look & custom imagery.
wIn1 :: In one addon. and is very lightweight & simple to use.
wChat :: Is a lightweight chat mod.
wBroker :: Is A simple broker add-on.
wPetXPBar :: Is A simple lightweight Pet XP Bar.
wBuffs :: Is A simple Buffs Bar.
  Reply With Quote
12-11-10, 08:38 AM   #2
Haleth
This Space For Rent
 
Haleth's Avatar
Featured
Join Date: Sep 2008
Posts: 1,173
Might be wrong here, but it seems like you're matching the realm name of your BN friend, rather than his actual char name, against the inviter's name.
  Reply With Quote
12-11-10, 08:44 AM   #3
weasoug
A Flamescale Wyrmkin
 
weasoug's Avatar
AddOn Author - Click to view addons
Join Date: May 2010
Posts: 127
Originally Posted by Haleth View Post
Might be wrong here, but it seems like you're matching the realm name of your BN friend, rather than his actual char name, against the inviter's name.
ah so somthing like

Code:
		if not accept then
			for index = 1, GetRealmName() do
				if BNGetFriendToonInfo(index) == name then
					accept = true
					break
				end
			end
		end
__________________
wMmap :: Is a lightweight Minimap, with a sleek look & custom imagery.
wIn1 :: In one addon. and is very lightweight & simple to use.
wChat :: Is a lightweight chat mod.
wBroker :: Is A simple broker add-on.
wPetXPBar :: Is A simple lightweight Pet XP Bar.
wBuffs :: Is A simple Buffs Bar.
  Reply With Quote
12-13-10, 06:13 AM   #4
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
weasoug, I think you need to bookmark wowpedia.org and wowprogramming.org, and refer to them frequently for information about WoW API functions. This is at least the third thread I've seen today where you posted code that just made me go .

Originally Posted by weasoug View Post
Code:
		if not accept then
			for index = 1, GetRealmName() do
				if BNGetFriendToonInfo(index) == name then
					accept = true
					break
				end
			end
		end
GetRealmName() returns a string value, not a number, and will trigger a Lua error in the context you're using it. I'm not even sure why you're checking the realm name anyway; if someone invites you to a party, they are obviously on your realm.

BNGetFriendToonInfo requires two arguments, one of which you don't have without calling some other functions. BNGetFriendInfo is the function you want.

Try this:

Code:
		if not accept then
			for index = 1, BNGetNumFriends() do
				local _, _, _, toonName = BNGetFriendInfo(index)
				if toonName == name then
					accept = true
					break
				end
			end
		end
  Reply With Quote
12-13-10, 07:33 AM   #5
weasoug
A Flamescale Wyrmkin
 
weasoug's Avatar
AddOn Author - Click to view addons
Join Date: May 2010
Posts: 127
i have been trying to cut it down. and this is what i have. no errors. but not tested.

any help would be good.

Code:
local function IsFriend(name)
	for i=1,GetNumFriends() do if GetFriendInfo(i) == name then return true end end
        for i=1,GetRealmName() do if BNGetFriendToonInfo(i) == name then return true end end
	if IsInGuild() then for i=1, GetNumGuildMembers() do if GetGuildRosterInfo(i) == name then return true end end end
end


local f = CreateFrame("Frame")
f:RegisterEvent("PARTY_INVITE_REQUEST")
f:SetScript("OnEvent", function(frame, event, name)
	if IsFriend(name) then
		for i=1,STATICPOPUP_NUMDIALOGS do
			local frame = getglobal("StaticPopup"..i)
			if frame:IsVisible() and frame.which == "PARTY_INVITE" then StaticPopup_OnClick(frame, 1) end
		end
	else SendWho(string.join("", "n-\"", name, "\"")) end
end)
__________________
wMmap :: Is a lightweight Minimap, with a sleek look & custom imagery.
wIn1 :: In one addon. and is very lightweight & simple to use.
wChat :: Is a lightweight chat mod.
wBroker :: Is A simple broker add-on.
wPetXPBar :: Is A simple lightweight Pet XP Bar.
wBuffs :: Is A simple Buffs Bar.
  Reply With Quote
12-13-10, 08:18 AM   #6
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
The code you just posted still contains all of the errors I corrected in my last post. Did you even read what I wrote? >_<

Here is the code I've been successfully using for years to auto-accept party invites from friends and guildmates. Note that I just added the Battle.net friend support, and haven't actively tested it since I don't use Real ID, but the basic syntax and API usage is at least error-free.

Code:
local function IsFriend(name)
	if UnitIsInMyGuild(name) then
		return true
	end

	for i = 1, GetNumFriends() do
		if GetFriendInfo(i) == name then
			return true
		end
	end

	for i = 1, select(2, BNGetNumFriends()) do
		for j = 1, BNGetNumFriendToons(i) do
			local _, toonName, client, realm = BNGetFriendToonInfo(i, j)
			if toonName == name and client == "WoW" and realm == GetRealmName() then
				return true
			end
		end
	end
end

local f = CreateFrame("Frame")
f:RegisterEvent("PARTY_INVITE_REQUEST")
f:SetScript("OnEvent", function(self, event, sender)
	if IsFriend(sender) then
		AcceptGroup()
	else
		SendWho("n-\"" .. sender .. "\"")
		StaticPopup_Show("PARTY_INVITE", sender)
	end
end

UIParent:UnregisterEvent("PARTY_INVITE_REQUEST")
If you don't want to run a /who on people who invite you but aren't in your guild or friends list, remove the SendWho line.

On a side note, putting everything on one line is not a good way to "cut it down". It makes your code a pain in the ass to read, and does not improve runtime performance at all.
  Reply With Quote
12-13-10, 09:12 AM   #7
weasoug
A Flamescale Wyrmkin
 
weasoug's Avatar
AddOn Author - Click to view addons
Join Date: May 2010
Posts: 127
Thumbs up

oh ok. it was just a moment thing., i will stay with the one i had. and had help with . thanks again for your time.

ps i like te /who. i will use that if ok.
__________________
wMmap :: Is a lightweight Minimap, with a sleek look & custom imagery.
wIn1 :: In one addon. and is very lightweight & simple to use.
wChat :: Is a lightweight chat mod.
wBroker :: Is A simple broker add-on.
wPetXPBar :: Is A simple lightweight Pet XP Bar.
wBuffs :: Is A simple Buffs Bar.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » realid aiv

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