Thread Tools Display Modes
08-13-10, 10:46 AM   #1
weasoug
A Flamescale Wyrmkin
 
weasoug's Avatar
AddOn Author - Click to view addons
Join Date: May 2010
Posts: 127
Post Auto Invite help

Hi there all. after a few days of edit and changing i got this working. but it still shows the invite window. howw can i hide it.

i also have been trying to as a if. in guild to it. so guild members could invite you.


Code:
AutoInvite = true

if AutoInvite then
local afi = CreateFrame("Frame")
afi:RegisterEvent("PARTY_INVITE_REQUEST")
afi:RegisterEvent("PARTY_MEMBERS_CHANGED")
afi:SetScript("OnEvent", function()
         if event == "PARTY_INVITE_REQUEST" then
		ShowFriends() -- Update Friends List
		for friendnum = 1, GetNumFriends() do
			myFriend = select(1, GetFriendInfo(friendnum))
			if(arg1 == myFriend) then
				AcceptGroup()
			end
		end
	end
end)
end
any help would be good.


edit-
StaticPopup_Hide i might be able to use there. umm.
  Reply With Quote
08-16-10, 02:24 PM   #2
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,327
When dealing with StaticPopupFrame, it's best to hook into the event that calls it so it'll reliably run AFTER the code that shows the popup. In this case, UIParent processes the event, so that's the frame we want to hook.

lua Code:
  1. UIParent:HookScript("OnEvent",function(self,event,...)
  2.     if event=="PARTY_INVITE_REQUEST" then
  3.         ShowFriends()-- Update friends list
  4.         for i=1,GetNumFriends() do
  5.             if (GetFriendInfo(i))==(...) then
  6.                 AcceptGroup();--        Accept invite
  7.                 StaticPopup_Hide("PARTY_INVITE",(...));--   Hide popup
  8.                 break;--    Stop scanning (we're done here)
  9.             end
  10.         end
  11.     end
  12. end);

Note: the only extra arg passed to the function is the name of the player inviting you. This is initially passed to StaticPopup_Show(), which assigns it as the popup's ID. You'll need to pass it to StaticPopup_Hide() hide the frame.
__________________
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 : 08-16-10 at 02:29 PM.
  Reply With Quote
08-16-10, 02:41 PM   #3
weasoug
A Flamescale Wyrmkin
 
weasoug's Avatar
AddOn Author - Click to view addons
Join Date: May 2010
Posts: 127
Post

Originally Posted by SDPhantom View Post
When dealing with StaticPopupFrame, it's best to hook into the event that calls it so it'll reliably run AFTER the code that shows the popup. In this case, UIParent processes the event, so that's the frame we want to hook.

lua Code:
  1. UIParent:HookScript("OnEvent",function(self,event,...)
  2.     if event=="PARTY_INVITE_REQUEST" then
  3.         ShowFriends()-- Update friends list
  4.         for i=1,GetNumFriends() do
  5.             if (GetFriendInfo(i))==(...) then
  6.                 AcceptGroup();--        Accept invite
  7.                 StaticPopup_Hide("PARTY_INVITE",(...));--   Hide popup
  8.                 break;--    Stop scanning (we're done here)
  9.             end
  10.         end
  11.     end
  12. end);

Note: the only extra arg passed to the function is the name of the player inviting you. This is initially passed to StaticPopup_Show(), which assigns it as the popup's ID. You'll need to pass it to StaticPopup_Hide() hide the frame.
thanks for that. i new there had to be something to do with StaticPopup but could not work out how and where. as no matter where i added it it would hide but not take the invite.

but i did find with your update i got an error to do with
Code:
for 1=1,GetNumFriends() do
it seemed to want a name. where the 2nd 1 is.
  Reply With Quote
08-16-10, 03:20 PM   #4
Haleth
This Space For Rent
 
Haleth's Avatar
Featured
Join Date: Sep 2008
Posts: 1,173
Code:
for i=1, GetNumFriends() do if(GetFriendInfo(i)==name) then
Something like this perhaps?
  Reply With Quote
08-16-10, 03:45 PM   #5
weasoug
A Flamescale Wyrmkin
 
weasoug's Avatar
AddOn Author - Click to view addons
Join Date: May 2010
Posts: 127
Post

Originally Posted by Haleth View Post
Code:
for i=1, GetNumFriends() do if(GetFriendInfo(i)==name) then
Something like this perhaps?
that seems to have it now.

just cant work out this one

Code:
AutoAcceptInvites = true
if AutoAcceptInvites then
local afi = CreateFrame("Frame")
afi:RegisterEvent("PARTY_INVITE_REQUEST")
afi:RegisterEvent("PARTY_MEMBERS_CHANGED")
afi:SetScript("OnEvent", function()
UIParent:HookScript("OnEvent",function(self,event,...)
    if event=="PARTY_INVITE_REQUEST" then
        ShowFriends()-- Update friends list
        for i=1, GetNumFriends() do 
                if(GetFriendInfo(i)==name) then
                AcceptGroup();--        Accept invite
                StaticPopup_Hide("PARTY_INVITE",(...));--   Hide popup
                break;--    Stop scanning (we're done here)
            end
        end
    end
end);
end
its mainly to do with afi:SetScript("OnEvent", function()
where before i just added a ) one but last of the end ive remove the ; on this one and messed about with the end and i cant work it out.
  Reply With Quote
08-17-10, 02:44 AM   #6
Haleth
This Space For Rent
 
Haleth's Avatar
Featured
Join Date: Sep 2008
Posts: 1,173
You don't need Afi anymore if you're going to hook a script to the UIParent.

Code:
UIParent:HookScript("OnEvent",function(self,event,...)
    if event=="PARTY_INVITE_REQUEST" then
        ShowFriends()-- Update friends list
        for i=1, GetNumFriends() do 
                if(GetFriendInfo(i)==name) then
                AcceptGroup();--        Accept invite
                StaticPopup_Hide("PARTY_INVITE",(...));--   Hide popup
                break;--    Stop scanning (we're done here)
            end
        end
    end
end)
  Reply With Quote
08-17-10, 09:40 AM   #7
weasoug
A Flamescale Wyrmkin
 
weasoug's Avatar
AddOn Author - Click to view addons
Join Date: May 2010
Posts: 127
Post

yes i did try that to start with. but it dont seem to work

Code:
AutoAcceptInvites = true

if AutoAcceptInvites then
UIParent:HookScript("OnEvent",function(self,event,...)
    if event=="PARTY_INVITE_REQUEST" then
        ShowFriends()-- Update friends list
        for i=1, GetNumFriends() do 
                if(GetFriendInfo(i)==name) then
                AcceptGroup();--        Accept invite
                StaticPopup_Hide("PARTY_INVITE",(...));--   Hide popup
                break;--    Stop scanning (we're done here)
            end
        end
    end
end)
end
the invite window still comes up. and it dont auto take the invite.
  Reply With Quote
08-17-10, 03:21 PM   #8
Dainton
A Flamescale Wyrmkin
 
Dainton's Avatar
AddOn Author - Click to view addons
Join Date: Jun 2008
Posts: 115
Code:
local function IsFriend(name)
	ShowFriends()
	for i = 1, GetNumFriends() do
		if GetFriendInfo(i) == name then return true end
	end
	if IsInGuild() then
		GuildRoster()
		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(self, event, name)
	if IsFriend(name) then
		for i = 1, STATICPOPUP_NUMDIALOGS do
			local frame = _G["StaticPopup"..i]
			if frame:IsVisible() and frame.which == "PARTY_INVITE" then StaticPopup_OnClick(frame, 1) end
		end
	else SendWho("n-\""..name.."\"") end
end)
This is what I use. It's basically tekAccept with a few updates.
  Reply With Quote
08-17-10, 04:29 PM   #9
weasoug
A Flamescale Wyrmkin
 
weasoug's Avatar
AddOn Author - Click to view addons
Join Date: May 2010
Posts: 127
Post

@ Dainton

thanks for that. wow. its what i have been trying to do for so long. i will put a credit in for you and tek. ty ty
  Reply With Quote
08-17-10, 04:41 PM   #10
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Not to discourage you from learning to write addons, but why are you spending time reinventing a wheel that's already been reinvented dozens of times? There are so many "auto accept invite, auto decline duels, auto repair, auto sell junk, auto this, auto that" addons out there. I just don't understand why people keep writing the same thing over and over.
  Reply With Quote
08-18-10, 01:34 PM   #11
mentalnutsy
A Cyclonian
AddOn Author - Click to view addons
Join Date: Apr 2008
Posts: 47
Originally Posted by Phanx View Post
Not to discourage you from learning to write addons, but why are you spending time reinventing a wheel that's already been reinvented dozens of times? There are so many "auto accept invite, auto decline duels, auto repair, auto sell junk, auto this, auto that" addons out there. I just don't understand why people keep writing the same thing over and over.
Well for someone new to writing addons starting with things that have been done before is not a bad idea, as this would give them more resources to learn from.
I learned to code via looking at other peoples addons and ripping them apart so see how they work. Once people have learned to code or have better understanding of how things work then they can branch out and try new things.

Altho everyone learns differently. I find the secret to learning how to code is be patient as it is a long process and you will have good times and bad times.
  Reply With Quote
08-18-10, 02:02 PM   #12
Mischback
A Cobalt Mageweaver
 
Mischback's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2009
Posts: 221
One of the people I learned most about coding (C in this case) is giving a tip: "Steal code!".

It's sort of "OpenSource-fanboy-like", but his credo is: Look at code which has improved for years and learn from it. Then develop your own style of programming with that base.

It's like mentalnutsy said: You can learn by the (good) code of other people. But I guess what was Phanx pointing out is: This has already be done, don't invite the wheel again, but look at how it was done!
__________________
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Auto Invite help


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