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,929
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.
__________________


Characters:
Gwynedda - 70 - Demon Warlock
Galaviel - 65 - Resto Druid
Gamaliel - 61 - Disc Priest
Gwynytha - 60 - Survival Hunter
Lienae - 60 - Resto Shaman
Plus several others below level 60

Info Panel IDs : http://www.wowinterface.com/forums/s...818#post136818
 
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.
 
 

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


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