Originally Posted by Walkerbo
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:
local messages = {
[40] = "pets the Bombay Cat", -- Bombay Cat
[379] = "hello world", -- Squirrel (from pet battles)
}
local guids = {}
local function OnEvent(self, event)
if not next(guids) then -- numOwnedPets is 0 at login
local _, numOwnedPets = C_PetJournal.GetNumPets()
for i = 1, numOwnedPets do
local guid, speciesID = C_PetJournal.GetPetInfoByIndex(i)
guids[guid] = speciesID
end
end
end
local function SendPetEmoteMessage(petGUID)
local speciesID = guids[petGUID]
if messages[speciesID] then
SendChatMessage(messages[speciesID], "EMOTE")
end
end
hooksecurefunc(C_PetJournal, "SummonPetByGUID", function(petGUID)
SendPetEmoteMessage(petGUID)
end)
hooksecurefunc(C_PetJournal, "SummonRandomPet", function()
C_Timer.After(.3, function() -- does not return proper data yet
local petGUID = C_PetJournal.GetSummonedPetGUID()
SendPetEmoteMessage(petGUID)
end)
end)
local f = CreateFrame("Frame")
f:RegisterEvent("PET_JOURNAL_LIST_UPDATE")
f:SetScript("OnEvent", OnEvent)