WoWInterface (
-   MoP Beta archived threads (
-   -   Summoning Companions Via script (

Aurorablade 08-15-12 11:00 AM

Summoning Companions Via script
Been using the tried and true
local numPets = GetNumCompanions("CRITTER")

for i=1,numPets do

_, cName, _, _, active,_ = GetCompanionInfo("CRITTER", i)

etc etc summon pet based on cName in a comparison.

Not working on mop beta, what has changed that i can't seem to figure out?

Xrystal 08-15-12 01:16 PM

Considering you can now fight other critters with them I would say a lot has changed. You might want to read through the beta thread as there are quite a few pet specific posts in there if I remember right.

semlar 08-17-12 12:17 PM

The CallCompanion function appears to throw the error "You do not have a pet" for critters, I don't know if this is just a bug or if you won't be able to use that function any more. In fact, it does the same thing if I try to summon it using /cast <Pet Name>.

I'm not sure exactly what you're trying to do, but I've written a function which will, for the moment, summon a pet by name on the beta. These functions seem like they might be subject to change.

Lua Code:
  1. function CallPetByName(petName)
  2.     local _,myPets = C_PetJournal.GetNumPets(false)
  3.     for i=1,myPets do
  4.         local petID, speciesID, isOwned, customName, level, favorite, isRevoked, name, icon, petType, creatureID, sourceText, description, isWildPet, canBattle, tradable, unique = C_PetJournal.GetPetInfoByIndex(i, false)
  5.         if name:lower() == petName:lower() then
  6.             return C_PetJournal.SummonPetByID(petID)
  7.         end
  8.     end
  9.     print('Pet "'..petName..'" not found')
  10. end

I've included what I believe to be an accurate list of the variables returned by GetPetInfoByIndex, even though you're only using 2 of them for this.

endx7 08-17-12 01:48 PM

Fun thing, filters affect the results from C_PetJournal.GetPetInfoByIndex

semlar 08-17-12 07:12 PM

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:
  1. /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:
  1. function CallPetByName(petName)
  2.     C_PetJournal.SetFlagFilter(LE_PET_JOURNAL_FLAG_COLLECTED, true) -- displays pets we do have
  3.     C_PetJournal.SetFlagFilter(LE_PET_JOURNAL_FLAG_NOT_COLLECTED, false) -- ignores pets we don't have
  4.     C_PetJournal.ClearSearchFilter() -- prevents the game from crashing
  5.     C_PetJournal.SetSearchFilter(petName) -- filter by name
  6.     local numPets = C_PetJournal.GetNumPets(false)
  7.     for i=1,numPets do
  8.         local petID, _, _, _, _, _, _, name = C_PetJournal.GetPetInfoByIndex(i, false)
  9.         if name and name:lower() == petName:lower() and C_PetJournal.PetIsSummonable(petID) and petID ~= C_PetJournal.GetSummonedPetID() then
  10.             return C_PetJournal.SummonPetByID(petID)
  11.         end
  12.     end
  13.     print('Failed to summon '..petName)
  14. 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.

Kharthus 08-19-12 11:50 AM

You also need to reset the Type and Source filters.


If these get unchecked, the search will return no results.

endx7 08-19-12 01:35 PM

And set the favorites filter to false.

Kharthus 08-19-12 02:50 PM

Good call on the favorites flag too. Here's the whole code chunk I use (thanks Blizz, this isn't pretty):

C_PetJournal.SetFlagFilter(LE_PET_JOURNAL_FLAG_COLLECTED, true)
C_PetJournal.SetFlagFilter(LE_PET_JOURNAL_FLAG_NOT_COLLECTED, false)
C_PetJournal.SetFlagFilter(LE_PET_JOURNAL_FLAG_FAVORITES, false)

endx7 08-19-12 03:05 PM

I really wish their filtering was done in Lua code. :P

semlar 08-19-12 10:43 PM


Originally Posted by endx7 (Post 259964)
I really wish their filtering was done in Lua code. :P

Yeah, the function really shouldn't be serving filtered results in the first place. I guess they figured it was only going to be used by the pet journal.

After poking around it looks like all non-combat pets that are considered "critters" summoned by any means (from an item, for a quest, whatever) have been rendered inoperable by the new system.

I dragged a pet onto my action bar to see what GetActionInfo looked like for it, and the old system returns "companion" for the type, the critter ID, and "CRITTER" for the subtype. While the new system returns "summonpet" as the type, the new unique pet ID, and no subtype.

Interestingly enough, you can still dismiss the critter after it's been summoned by using the old button (/run PickupCompanion('CRITTER',1)), and this bypasses the global cooldown caused by unsummoning the pet using the new method.

I'm expecting that they will fix the old companion methods because you can't currently use items like Don Carlos' Famous Hat or the Bloodsail Admiral's Hat to summon their pets and the quests for the venomhide raptor and winterspring frostsaber are broken.

endx7 08-20-12 12:49 AM

They were broken for a while, but as of the latest build, you can use don carlos's hat, the bloodsail hat, and the frostsaber cub again. (I didn't actually test the venomhide raptor)

At least, they work for me, and I've been periodically testing them as they are of interest to me.

I'm a bit sad that C_PetJournal.GetSummonedPetID() no longer returns a value of zero if you have any of those out, but for me this isn't too bad as GetSummonedPetID() instead doesn't realize your old pet was overridden at all, so my addon code doesn't think you suddenly don't have a pet.

semlar 08-20-12 01:44 AM

Oh, they must have fixed those very recently. Well it's good to know they're working on some of these issues.

Kharthus 08-21-12 08:25 PM

Does anyone know why this call sometimes fails to dismiss the active critter:


Works fine if I do this right after Feign Death, but if I try to do it right after Camouflage it doesn't do anything. (This is for the Livestock addon).

endx7 08-22-12 12:31 AM

It's being prevented by the global cooldown, since C_PetJournal.SummonPetByID() even when dismissing a pet is on the global cooldown (both invokes and affected by).

Stealth, Prowl and Feign Death are not on the global cooldown, so they don't prevent you from dismissing a pet immediately, unlike Camo.

semlar 08-22-12 09:59 AM

This may be unintentional, but you can definitely still dismiss a non-combat pet during -and without causing- a global cooldown using DismissCompanion('CRITTER').

endx7 08-22-12 12:05 PM

sometimes, it depends on whether you had the pet before the PetJournal merge.

If you had the pet before, DismissCompanion works. If you obtained it after, whether it was captured in battle or only now obtainable on that character due to it being on only another character previously or whatever, it doesn't seem to do anything at all.

Furthermore, GetCompanionInfo continues to blissfully unaware of new pets with the same restriction. Since dismissing seems to not care whether the pet is a duplicate or not, so you could possibly check for the pet's existence using GetCompanionInfo, and call DismissCompanion or the C_PetJournal function accordingly. (Probably DismissCompanion is doing its own check to make sure we "own" the pet, and it isn't from something else)

semlar 08-22-12 12:39 PM

Alright, so the only reason any of the old functions work is because we still know the spell used to summon the companion on that character, and instead of unlearning those spells they just disabled the ability to use them.

Mounts, on the other hand, appear to have actually been taught to all of your characters, so the functions should still work for them.

endx7 08-22-12 12:48 PM


I think pets are probably weird behind the scenes since each pet has to unique, even if it has the same creature id (since it'll have different level, health, etc)

Kharthus 08-22-12 07:31 PM


Originally Posted by endx7 (Post 260062)
It's being prevented by the global cooldown, since C_PetJournal.SummonPetByID() even when dismissing a pet is on the global cooldown (both invokes and affected by).

Stealth, Prowl and Feign Death are not on the global cooldown, so they don't prevent you from dismissing a pet immediately, unlike Camo.

Looks like only Invisibility and Camouflage invoke the GCD. Managed to code up a workaround with UNIT_AURA. Not ideal, but it works.

All times are GMT -6. The time now is 03:02 PM.

vBulletin © 2020, Jelsoft Enterprises Ltd
© 2004 - 2019 MMOUI