View Single Post
07-28-18, 02:21 PM   #12
Chokobo
A Murloc Raider
Join Date: Jul 2018
Posts: 9
Ok, PhoenixPower. You win. that did the trick.

So, the take aways from this lesson, for me, we're incomplete understanding of how and when data was being returned. A less than ideal mock up of the code for testing. And, chasing down the wrong issue to solve the problem.

Below, I have corrected the issues and all is working as intended. Thanks so much for all the help. I really appreciate it.

FWIW this button is what helps me escape long dungeons without running back to the entrance (Transmog Farmer Here). Not a new concept, but I like to be in control of my own tools.

Find the code here: https://pastebin.com/zr0WqzPP

Code:
ChokoTools.SearchResults = {}
ChokoTools.FilteredIDs = {}
ChokoTools.HopFSM = "Search"
 
--Standard Basic Button
ChokoTools.RandHop = CreateFrame("Button",nil,UIParent)
ChokoTools.RandHop:SetSize(50,18)
ChokoTools.RandHop:SetPoint("BOTTOMLEFT",0,0)
ChokoTools.RandHop:SetText("HOP")
ChokoTools.RandHop:RegisterEvent("LFG_LIST_SEARCH_RESULTS_RECEIVED")
ChokoTools.RandHop:RegisterEvent("LFG_LIST_SEARCH_FAILED")
ChokoTools.RandHop.bg = ChokoTools.RandHop:CreateTexture("ARTWORK")
ChokoTools.RandHop.bg:SetColorTexture(0.2,0.2,0.2,1)
ChokoTools.RandHop.bg:SetAllPoints(ChokoTools.RandHop)
ChokoTools.RandHop.txt = ChokoTools.RandHop:CreateFontString(nil,"ARTWORK")
ChokoTools.RandHop.txt:SetFont("Interface\\AddOns\\ChokoTools\\fonts\\Exo2.ttf", 12)
ChokoTools.RandHop.txt:SetTextColor(0.8,0.8,0.8)
ChokoTools.RandHop.txt:SetText("HOP")
ChokoTools.RandHop.txt:SetPoint("CENTER")
 
 
 
ChokoTools.RandHop:SetScript("OnClick", function(self, event, ...)
    if IsInGroup() or IsInRaid() then
        LeaveParty()
        ChokoTools.SearchResults = {}
        ChokoTools.FilteredIDs = {}
        ChokoTools.HopFSM = "Search"
        ChokoTools.RandHop.txt:SetText("HOP")
        return
    end
    ChokoTools:RandomGroup()
end)
 
ChokoTools.RandHop:SetScript("OnEvent", function(self, event, ...)
    if event == "LFG_LIST_SEARCH_RESULTS_RECEIVED" then
        --Get Search Results
        c, ChokoTools.SearchResults = C_LFGList.GetSearchResults()
       
        --Iterate through search results
        for i=1,#ChokoTools.SearchResults do
            local id, _, _, _, _, _, _, _, _, _, _, _, _, _, autoinv = C_LFGList.GetSearchResultInfo(ChokoTools.SearchResults[i])
           
            if autoinv == true then
                table.insert(ChokoTools.FilteredIDs,id)
            end
        end
        ChokoTools.HopFSM = "Join"
        ChokoTools.RandHop.txt:SetText("JOIN")
       
    elseif event == "LFG_LIST_SEARCH_FAILED" then
   
        ChokoTools.SearchResults = {}
        ChokoTools.FilteredIDs = {}
        ChokoTools.HopFSM = "Search"
    end
end)
 
--Function: Search for groups with Auto Accept on. Join if we have data.
function ChokoTools:RandomGroup()
   
    if ChokoTools.HopFSM == "Join" then
        if (ChokoTools.FilteredIDs) and (#ChokoTools.FilteredIDs >= 1) then
            print("Joining...")
            C_LFGList.ApplyToGroup(ChokoTools.FilteredIDs[1], "", false, false, true)
            ChokoTools.FilteredIDs = {} --Reset table to empty
        end
    end
   
    if ChokoTools.HopFSM == "Search" then
        print("Searching...")
        ChokoTools.SearchResults = {}
        ChokoTools.FilteredIDs = {}
 
        --Search Groups (Taken and modified from "ServerHop" Addon)
        local lang = {}
        for k,v in pairs(C_LFGList.GetAvailableLanguageSearchFilter()) do lang[v]=true end
        C_LFGList.Search(6,LFGListSearchPanel_ParseSearchTerms(""),0,0,lang) --Search "Custom" groups
       
    end
end





Thanks again for all the help, everyone. I sincerely do appreciate it.

Last edited by Chokobo : 07-28-18 at 02:46 PM.
  Reply With Quote