Get an Epic Experience with Premium

LibPetJournal-2.0

Libraries Login to Add Favorites
  • 0 Likes
  • World of Warcraft
  • 1,047 Monthly Downloads
  • Supports: 5.2.0
  • 7,627 Total Downloads
  • Updated 05/04/2013
  • Created 09/03/2012
  • 5 Favorites
  • Project Site
  • Release Type: Release
  • License: MIT License
  • Newest File: 2.0.26
or

About LibPetJournal-2.0

Requires: LibStub, CallbackHandler-1.0

With 5.0 a new C_PetJournal API was introduced, and unfortunately the old GetCompanionInfo API no longer works properly (it does not, for example, know anything about non-combat pets obtained before the account-wide merge, and you also can no longer summon non-combat pets using it).

This library provides the list of player owned pet ids and all species ids, which can be used with C_PetJournal.GetPetInfoByPetID() and C_PetJournal.GetPetInfoBySpeciesID().

It primarily deals with two problems with scanning the pet journal:

  • Filters: The Pet Journal filters are cleared and then restored, as they affect the return values given from C_PetJournal.GetPetInfoByIndex()
  • Updating in response to event: Manipulating the Pet Journal filters causes PET_JOURNAL_LIST_UPDATE to fire, which is also the only event that always fires when you lose or gain a pet. Filter manipulation is detected and we never try to rescan pets in response. When this is not the case, a CallbackHandler event is fired which can be used to safely detect changes to the pet list.

Getting Started
API Documentation
WoWAce Thread

Example

local LibPetJournal = LibStub("LibPetJournal-2.0")
local function ScanPets()
    for _,petid in LibPetJournal:IteratePetIDs() do 
        local speciesID, customName, level, xp, maxXp, displayID, isFavorite, 
               name, icon, petType, creatureID, sourceText, description, isWild,
               canBattle, tradable, unique = C_PetJournal.GetPetInfoByPetID(petid)
        if name == "Feline Familiar" then
            print("Player has a cat in a hat.")
        end
    end
end
ScanPets()

If you wanted to automatically scan for little cats in hats when the pet list changes, you could register a callback, such as:

LibPetJournal.RegisterCallback(addon, "PetListUpdated", ScanPets)

Obviously you would normally use the speciesID or creatureID return values from C_PetJournal.GetPetInfoByPetID() to find a particular pet, but this is just a silly example.

2013-05-04  Robin Schoonover  <robin@cornhooves.org>

[b741c809b7bd] [2.0.26]
* LibPetJournal-2.0.lua

Bump minor.

Login to Curse

Don't have an account? Create One.

Get an epic experience with Curse Premium
  • Faster addon downloads
  • Premium-Only Beta Giveaways
  • Ad-Free Curse experience
  • Premium Curse Client
  • and many More Features
  • Learn More »

Infinite Crisis NA

Get Your Preferred Access Code!