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:
UIParent:HookScript("OnEvent",function(self,event,...)
if event=="PARTY_INVITE_REQUEST" then
ShowFriends()-- Update friends list
for i=1,GetNumFriends() do
if (GetFriendInfo(i))==(...) then
AcceptGroup();-- Accept invite
StaticPopup_Hide("PARTY_INVITE",(...));-- Hide popup
break;-- Stop scanning (we're done here)
end
end
end
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.