Good grief. Alright, well as far as I can tell "C_PetJournal.SummonPetByID" is the only function currently working that will actually summon a companion, and the ID it uses appears to only be obtainable through the pet journal functions.
However.. the pet journal itself isn't loaded until the frame is opened in-game (shift+p) and calling some of the pet journal functions before it loads has managed to fatally crash my client several times.
Apparently calling C_PetJournal.SetSearchFilter in a way that returns no results twice in a row like
Lua Code:
/run C_PetJournal.SetSearchFilter('xx');C_PetJournal.SetSearchFilter('xx')
will just immediately crash the game, but only if you haven't loaded the pet journal yet.
Calling C_PetJournal.ClearSearchFilter() in between seems to prevent this from happening, and even though setting the search filter isn't strictly necessary, it does leave fewer things to iterate over.
Here's my second crack at the function, and I haven't managed to break this one but you never know.
Lua Code:
function CallPetByName(petName)
C_PetJournal.SetFlagFilter(LE_PET_JOURNAL_FLAG_COLLECTED, true) -- displays pets we do have
C_PetJournal.SetFlagFilter(LE_PET_JOURNAL_FLAG_NOT_COLLECTED, false) -- ignores pets we don't have
C_PetJournal.ClearSearchFilter() -- prevents the game from crashing
C_PetJournal.SetSearchFilter(petName) -- filter by name
local numPets = C_PetJournal.GetNumPets(false)
for i=1,numPets do
local petID, _, _, _, _, _, _, name = C_PetJournal.GetPetInfoByIndex(i, false)
if name and name:lower() == petName:lower() and C_PetJournal.PetIsSummonable(petID) and petID ~= C_PetJournal.GetSummonedPetID() then
return C_PetJournal.SummonPetByID(petID)
end
end
print('Failed to summon '..petName)
end
I'm not really sure why you would need to summon a pet based on its name though, it seems like an odd request.