Macro which cages pets from bank/guild bank

Discuss your favorite pet addons and macros.
Post Reply
User avatar
Caliban
Top Rater
Posts: 19
Joined: August 7th, 2014
Pet Score: 9946
Realm: Anachronos-EU
Contact:

Macro which cages pets from bank/guild bank

Post by Caliban » October 26th, 2020, 7:07 am

Does anyone know of a macro, or is anyone able to create a macro, which would cage any pets from either my bank or guild bank of which I have less than three of in my pet collection.

Being a pet seller with banks and guild banks full of pets, I now have to manually hover over all these pets every time to see if any are cageable. With a macro as described above, I would save LOTS of time. Hope this is possible.

Thanks in advance!

Kris

User avatar
Jerebear
Posts: 1183
Joined: September 15th, 2013
Pet Score: 9957
Realm: Llane-US
Contact:

Re: Macro which cages pets from bank/guild bank

Post by Jerebear » October 30th, 2020, 2:47 pm

I'm not sure I understand. If they are in a bank, they are already caged, so they must all be cageable. Can you maybe elaborate some more?
Carry Pet Experience Reference Guide:
http://www.warcraftpets.com/community/forum/viewtopic.php?f=10&t=8829

User avatar
Caliban
Top Rater
Posts: 19
Joined: August 7th, 2014
Pet Score: 9946
Realm: Anachronos-EU
Contact:

Re: Macro which cages pets from bank/guild bank

Post by Caliban » November 6th, 2020, 1:34 pm

Yup. Let's say I have 100 pets in my bank, out of which 50 I have 3/3 in my pet collection. Then those 50 are 'not cageable' at the moment, since I can only add 3 of each pet. If the other 50 ones I have I either have 1/3 or 2/3 of in my pet journal, they ARE cageable.

So the macro I'd love to have would automatically, one by one, cage all those pets that I have 1/3 or 2/3 of in my pet journal. The alterenative I am doing now is hover over all 100 pets, which shows me which I can add to my pet journal, and then I add them. But with HUNDREDS of pets in bank and guildbank, spread over 7 realms, this is very time consuming, so a macro (or addon) would save me an incredible amount of time.

Hope that explains it :)

Kris

User avatar
Jerebear
Posts: 1183
Joined: September 15th, 2013
Pet Score: 9957
Realm: Llane-US
Contact:

Re: Macro which cages pets from bank/guild bank

Post by Jerebear » November 7th, 2020, 10:02 am

I think I understand, but I think you are using "cageable" when you mean "learnable"? Cageable means that you can cage something, but adding pets to your collection is actually uncaging/learning, not caging.

Now if I understand what you are asking, you want an addon that will scan through your already caged pets in your bank and learn the ones that you have room in your pet journal to learn. I believe the WoW API can iterate through all your bank slots, so that isn't an issue. I would guess that WoW's API can also tell you if you have 3/3 or 1/3 since Rematch has the ability to filter on that. I think the outstanding question is how "automated" can the "learning" step be automated. I feel like this might be rough for a macro to do (only somewhere near 256 chars allowed in a macro), but maybe a small addon? Honestly I don't think it matters if you have 1/3 or 2/3 or 3/3 if you can iterate over all of them. Trying to uncage a pet will just fail if you can't learn it, and you move onto the next.
Last edited by Jerebear on November 7th, 2020, 3:36 pm, edited 1 time in total.
Carry Pet Experience Reference Guide:
http://www.warcraftpets.com/community/forum/viewtopic.php?f=10&t=8829

Gello
Posts: 458
Joined: January 23rd, 2014
Pet Score: 6649
Realm: Hyjal-US
Contact:

Re: Macro which cages pets from bank/guild bank

Post by Gello » November 7th, 2020, 2:30 pm

Yeah the cageable usage made the question really difficult to understand.

Right click a pet in journal and Put In Cage -> leaves pet journal
Right click a pet in bags -> enters pet journal

The answer to which pets in bags or bank are not in the journal is...all the pets in your bags or bank?

That said, the following will put a green paw over all learnable pets in your bags, bank and guild bank; regardless whether they're an item that teaches a pet or a caged pet. Some pets are unique and it will consider 1/1 collected of those as unlearnable too. You can turn it into an addon by pasting it into https://addon.bool.no/

Code: Select all

-- returns true if the given link is of a pet that can be learned (less than max collected)
local function isLinkLearnable(link)
    if not link then
        return false
    end
    -- check for link being a caged pet first
    local speciesID = link:match("battlepet:(%d+)")
    if speciesID then
        local learned,maxLearned = C_PetJournal.GetNumCollectedInfo(speciesID)
        if learned<maxLearned then
            return true -- link is a caged pet that can be learned
        end
    end
    -- next check for an item that can learn a pet using awful tooltip scans
    if select(7,GetItemInfo(link))=="Companion Pets" then
        GameTooltip:SetOwner(UIParent,"ANCHOR_NONE")
        GameTooltip:SetHyperlink(link)
        for j=1,GameTooltip:NumLines() do
            local text = _G["GameTooltipTextLeft"..j]:GetText()
            local learned,maxLearned = (text or ""):match("^Collected %((%d)/(%d)%)")
            if learned and maxLearned and learned<maxLearned then
                GameTooltip:Hide()
                return true -- link is an item of a pet that can be learned
            end
        end
        GameTooltip:Hide()
    end
end

-- updates the badge on the given button to show or hide depending on whether the link
-- for that button's contents is a learnable pet
local function updateBadge(button,link)
    if not button then
        return
    end
    if not button.learnablePet then
        button.learnablePet = button:CreateTexture(nil,"OVERLAY")
        button.learnablePet:SetSize(16,16)
        button.learnablePet:SetPoint("TOPLEFT",2,-2)
        button.learnablePet:SetTexture("Interface\\Icons\\Tracking_WildPet")
    end
    button.learnablePet:SetShown(isLinkLearnable(link))
end

-- updates the main bank area
hooksecurefunc("BankFrameItemButton_Update",function(button)
    updateBadge(button,GetContainerItemLink(button:GetParent():GetID(),button:GetID()))
end)

-- updates bags (backpack, bags and bank bags)
hooksecurefunc("ContainerFrame_Update",function(frame)
    local bag = frame:GetID()
    for i=1,frame.size do
        local button = _G[frame:GetName().."Item"..i]
        updateBadge(button,GetContainerItemLink(bag,button:GetID()))
    end
end)

-- updates awfully-coded guild bank
local frame = CreateFrame("Frame")
frame:SetScript("OnEvent",function(self,event,addon)
    if IsAddOnLoaded("Blizzard_GuildBankUI") then
        self:UnregisterAllEvents()
        hooksecurefunc("GuildBankFrame_Update",function()
            local tab = GetCurrentGuildBankTab()
            for i=1,MAX_GUILDBANK_SLOTS_PER_TAB do
                local index = mod(i,NUM_SLOTS_PER_GUILDBANK_GROUP)
                if index==0 then
                    index = NUM_SLOTS_PER_GUILDBANK_GROUP
                end
                local column = ceil((i-0.5)/NUM_SLOTS_PER_GUILDBANK_GROUP) 
                local button = _G["GuildBankColumn"..column.."Button"..index] -- seriously, blizzard? wtf
                updateBadge(button,GetGuildBankItemLink(tab,i))
            end
        end)
    end
end)
frame:RegisterEvent("ADDON_LOADED")
frame:RegisterEvent("PLAYER_LOGIN")
(Note: this only works for default bags and banks and only on English clients that use "Collected (2/3)" on tooltips of items that teach pets. And as an aside, the guild bank UI code is hideously awful. I can't believe Blizzard hasn't totally refactored that ugly mess. And I say that as the unproud owner of thousands and thousands of lines of ugly code lol)

User avatar
Caliban
Top Rater
Posts: 19
Joined: August 7th, 2014
Pet Score: 9946
Realm: Anachronos-EU
Contact:

Re: Macro which cages pets from bank/guild bank

Post by Caliban » November 9th, 2020, 8:48 am

First of all, thank you Gello; this addon is EXACTLY what I meant and I really can't thank you enough. There's only one bug of sort with it in that in the guild banks, it only shows the green paw on pet cages with the text "use: teaches you how to summon this companion". It does NOT show on all the other pets, which is the vast majority. (both bank and bags work as intended by the way).

In the attachments (I can't for the life of me seem to put the screenshots straight into my message) below you can see this; the highlighted Chitterspine Devourer is learnable as I have 2/3 in my pet journal, yet it doesn't show the green paw, while the Mechanical Pandaren Dragonling to the left of it DOES show as learnable, but that's because it's an unused cage, so to speak.

I feel bad asking you to have another try at it, Gello, but this is SO close to being such a game changer for me, and I'm super excited for this. Thanks again for this, and thank you too, Jerebear, for clearing things up!
Jerebear wrote:
November 7th, 2020, 10:02 am
I think I understand, but I think you are using "cageable" when you mean "learnable"? Cageable means that you can cage something, but adding pets to your collection is actually uncaging/learning, not caging
You guys are absolutely right. Sorry about the unnecessary confusion!
Attachments
image0[952].jpeg
image0[952].jpeg (132.78 KiB) Viewed 460 times
image0[950].jpeg
image0[950].jpeg (164.43 KiB) Viewed 460 times

Gello
Posts: 458
Joined: January 23rd, 2014
Pet Score: 6649
Realm: Hyjal-US
Contact:

Re: Macro which cages pets from bank/guild bank

Post by Gello » November 9th, 2020, 12:22 pm

Funny enough, I wondered if it'd break the other way. I found a new api to do this without tooltip scans that's not locale-dependent. I can't guarantee I can look at it tonight but I'll update this in the next couple days.

User avatar
Caliban
Top Rater
Posts: 19
Joined: August 7th, 2014
Pet Score: 9946
Realm: Anachronos-EU
Contact:

Re: Macro which cages pets from bank/guild bank

Post by Caliban » November 9th, 2020, 12:47 pm

I really appreciate it and can't thank you enough :)

I'll be waiting here patiently!

Kris

Gello
Posts: 458
Joined: January 23rd, 2014
Pet Score: 6649
Realm: Hyjal-US
Contact:

Re: Macro which cages pets from bank/guild bank

Post by Gello » November 9th, 2020, 7:25 pm

Round two:

Code: Select all

-- returns true if the given link is of a pet that can be learned (less than max collected)
local function isLinkLearnable(link)
    if not link then
        return false
    end
    -- check for link being a caged pet first
    local speciesID = link:match("battlepet:(%d+)")
    if not speciesID then
        local itemID = link:match("item:(%d+)")
        if itemID then
            speciesID = select(13,C_PetJournal.GetPetInfoByItemID(itemID))
        end
    end
    if speciesID then
        local learned,maxLearned = C_PetJournal.GetNumCollectedInfo(speciesID)
        if learned<maxLearned then
            return true -- link is a caged pet that can be learned
        end
    end
end

-- updates the badge on the given button to show or hide depending on whether the link
-- for that button's contents is a learnable pet
local function updateBadge(button,link)
    if not button then
        return
    end
    if not button.learnablePet then
        button.learnablePet = button:CreateTexture(nil,"OVERLAY")
        button.learnablePet:SetSize(16,16)
        button.learnablePet:SetPoint("TOPLEFT",2,-2)
        button.learnablePet:SetTexture("Interface\\Icons\\Tracking_WildPet")
    end
    button.learnablePet:SetShown(isLinkLearnable(link))
end

-- updates the main bank area
hooksecurefunc("BankFrameItemButton_Update",function(button)
    updateBadge(button,GetContainerItemLink(button:GetParent():GetID(),button:GetID()))
end)

-- updates bags (backpack, bags and bank bags)
hooksecurefunc("ContainerFrame_Update",function(frame)
    local bag = frame:GetID()
    for i=1,frame.size do
        local button = _G[frame:GetName().."Item"..i]
        updateBadge(button,GetContainerItemLink(bag,button:GetID()))
    end
end)

-- updates awfully-coded guild bank
local frame = CreateFrame("Frame")
frame:SetScript("OnEvent",function(self,event,addon)
    if IsAddOnLoaded("Blizzard_GuildBankUI") then
        self:UnregisterAllEvents()
        hooksecurefunc("GuildBankFrame_Update",function()
            local tab = GetCurrentGuildBankTab()
            for i=1,MAX_GUILDBANK_SLOTS_PER_TAB do
                local index = mod(i,NUM_SLOTS_PER_GUILDBANK_GROUP)
                if index==0 then
                    index = NUM_SLOTS_PER_GUILDBANK_GROUP
                end
                local column = ceil((i-0.5)/NUM_SLOTS_PER_GUILDBANK_GROUP) 
                local button = _G["GuildBankColumn"..column.."Button"..index] -- seriously, blizzard? wtf
                GameTooltip:SetOwner(UIParent,"ANCHOR_NONE")
                local speciesID = GameTooltip:SetGuildBankItem(tab,button:GetID())
                updateBadge(button,speciesID and "battlepet:"..speciesID or GetGuildBankItemLink(tab,button:GetID()))
            end
            GameTooltip:Hide()
        end)
    end
end)
frame:RegisterEvent("ADDON_LOADED")
frame:RegisterEvent("PLAYER_LOGIN")
There's a minor "bug" where if you have the same pet in multiple bags, learning a pet will only update/hide paws in your current bag until you do something to refresh the bag, like close/open or moving something in that other bag. The workaround for this would require a bit more code than I can commit to right now so I'm letting the behavior remain.

User avatar
Caliban
Top Rater
Posts: 19
Joined: August 7th, 2014
Pet Score: 9946
Realm: Anachronos-EU
Contact:

Re: Macro which cages pets from bank/guild bank

Post by Caliban » November 10th, 2020, 5:11 am

It works! I am one extremely happy customer right now, thank you so much!

Kris

Post Reply