Quantcast
WoWInterface - View Single Post - Get pet summon spell ID
View Single Post
09-16-21, 03:53 AM   #6
Ketho
A Molten Giant
 
Ketho's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 994
Originally Posted by Walkerbo View Post
I wish to be able to add a pet to a table, and when a UNIT_SPELLCAST_SUCCEEDED event fires if the pet is listed it will send a customisable emote to chat.
[...]
If there is a better solution I would be grateful for some direction.

Hook the summon pet API to get the GUID and map it to a speciesID. This is just a minimal example without e.g. formatting the pet name in the message with "%s"

This is why I keep telling you to always explain what you're trying to do for the bazillionth time

Lua Code:
  1. local messages = {
  2.     [40] = "pets the Bombay Cat", -- Bombay Cat
  3.     [379] = "hello world", -- Squirrel (from pet battles)
  4. }
  5. local guids = {}
  6.  
  7. local function OnEvent(self, event)
  8.     if not next(guids) then -- numOwnedPets is 0 at login
  9.         local _, numOwnedPets = C_PetJournal.GetNumPets()
  10.         for i = 1, numOwnedPets do
  11.             local guid, speciesID = C_PetJournal.GetPetInfoByIndex(i)
  12.             guids[guid] = speciesID
  13.         end
  14.     end
  15. end
  16.  
  17. local function SendPetEmoteMessage(petGUID)
  18.     local speciesID = guids[petGUID]
  19.     if messages[speciesID] then
  20.         SendChatMessage(messages[speciesID], "EMOTE")
  21.     end
  22. end
  23.  
  24. hooksecurefunc(C_PetJournal, "SummonPetByGUID", function(petGUID)
  25.     SendPetEmoteMessage(petGUID)
  26. end)
  27.  
  28. hooksecurefunc(C_PetJournal, "SummonRandomPet", function()
  29.     C_Timer.After(.3, function() -- does not return proper data yet
  30.         local petGUID = C_PetJournal.GetSummonedPetGUID()
  31.         SendPetEmoteMessage(petGUID)
  32.     end)
  33. end)
  34.  
  35. local f = CreateFrame("Frame")
  36. f:RegisterEvent("PET_JOURNAL_LIST_UPDATE")
  37. f:SetScript("OnEvent", OnEvent)


Last edited by Ketho : 09-16-21 at 02:13 PM.
  Reply With Quote