WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   realid aiv (https://www.wowinterface.com/forums/showthread.php?t=37508)

weasoug 12-11-10 06:15 AM

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


Haleth 12-11-10 08:38 AM

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.

weasoug 12-11-10 08:44 AM

Quote:

Originally Posted by Haleth (Post 222399)
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


Phanx 12-13-10 06:13 AM

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 :confused:.

Quote:

Originally Posted by weasoug (Post 222402)
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


weasoug 12-13-10 07:33 AM

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)


Phanx 12-13-10 08:18 AM

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.

weasoug 12-13-10 09:12 AM

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.


All times are GMT -6. The time now is 08:53 AM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI