Thread Tools Display Modes
08-15-12, 11:00 AM   #1
Aurorablade
A Deviate Faerie Dragon
 
Aurorablade's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2005
Posts: 16
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?
 
08-15-12, 01:16 PM   #2
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,877
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.
__________________
 
08-17-12, 12:17 PM   #3
semlar
A Pyroguard Emberseer
 
semlar's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 1,060
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.
 
08-17-12, 01:48 PM   #4
endx7
An Aku'mai Servant
 
endx7's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2005
Posts: 38
Fun thing, filters affect the results from C_PetJournal.GetPetInfoByIndex
 
08-17-12, 07:12 PM   #5
semlar
A Pyroguard Emberseer
 
semlar's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 1,060
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.
 
08-19-12, 11:50 AM   #6
Kharthus
A Fallenroot Satyr
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 26
You also need to reset the Type and Source filters.

C_PetJournal.AddAllPetTypesFilter()
C_PetJournal.AddAllPetSourcesFilter()

If these get unchecked, the search will return no results.
 
08-19-12, 01:35 PM   #7
endx7
An Aku'mai Servant
 
endx7's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2005
Posts: 38
And set the favorites filter to false.
 
08-19-12, 02:50 PM   #8
Kharthus
A Fallenroot Satyr
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 26
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)
C_PetJournal.AddAllPetTypesFilter()
C_PetJournal.AddAllPetSourcesFilter()
C_PetJournal.ClearSearchFilter()
 
08-19-12, 03:05 PM   #9
endx7
An Aku'mai Servant
 
endx7's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2005
Posts: 38
I really wish their filtering was done in Lua code. :P
 
08-19-12, 10:43 PM   #10
semlar
A Pyroguard Emberseer
 
semlar's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 1,060
Originally Posted by endx7 View Post
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.
 
08-20-12, 12:49 AM   #11
endx7
An Aku'mai Servant
 
endx7's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2005
Posts: 38
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.

Last edited by endx7 : 08-20-12 at 01:03 AM.
 
08-20-12, 01:44 AM   #12
semlar
A Pyroguard Emberseer
 
semlar's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 1,060
Oh, they must have fixed those very recently. Well it's good to know they're working on some of these issues.
 
08-21-12, 08:25 PM   #13
Kharthus
A Fallenroot Satyr
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 26
Does anyone know why this call sometimes fails to dismiss the active critter:

C_PetJournal.SummonPetByID(C_PetJournal.GetSummonedPetID())

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).
 
08-22-12, 12:31 AM   #14
endx7
An Aku'mai Servant
 
endx7's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2005
Posts: 38
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.

Last edited by endx7 : 08-22-12 at 12:46 AM.
 
08-22-12, 09:59 AM   #15
semlar
A Pyroguard Emberseer
 
semlar's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 1,060
This may be unintentional, but you can definitely still dismiss a non-combat pet during -and without causing- a global cooldown using DismissCompanion('CRITTER').
 
08-22-12, 12:05 PM   #16
endx7
An Aku'mai Servant
 
endx7's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2005
Posts: 38
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)

Last edited by endx7 : 08-22-12 at 12:08 PM.
 
08-22-12, 12:39 PM   #17
semlar
A Pyroguard Emberseer
 
semlar's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 1,060
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.
 
08-22-12, 12:48 PM   #18
endx7
An Aku'mai Servant
 
endx7's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2005
Posts: 38
Yeah.

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)
 
08-22-12, 07:31 PM   #19
Kharthus
A Fallenroot Satyr
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 26
Originally Posted by endx7 View Post
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.
 
 

WoWInterface » Site Forums » Archived Beta Forums » MoP Beta archived threads » Summoning Companions Via script

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off