WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   AddOn Help/Support (https://www.wowinterface.com/forums/forumdisplay.php?f=3)
-   -   Sound when pet dies (https://www.wowinterface.com/forums/showthread.php?t=58712)

Yukka 04-30-21 09:31 AM

Sound when pet dies
 
Hello world, I play BM hunter and sometimes (especially Ashran) my pet dies and I'm too distracted to see it... Can someone share the code to create an addon that play a sound when pet dies? Thanks in advance.

DahkCeles 04-30-21 10:00 AM

I don't play hunter, so I'm not quite sure if a dead pet is a 'corpse' (zero health, would trigger UNIT_HEALTH) or despawns (no longer exists, would trigger UNIT_PET).

This code is just a guess -- I haven't tested it -- to cover both possible cases.

Lua Code:
  1. local f = CreateFrame("Frame")
  2. f:RegisterUnitEvent("UNIT_HEALTH", "pet")
  3. f:RegisterUnitEvent("UNIT_PET", "player")
  4. f:SetScript("OnEvent", function()
  5.   if not UnitExists("pet") or UnitHealth("pet") == 0 then
  6.     PlaySound(SOUNDKIT.LOOT_WINDOW_COIN_SOUND)
  7.   end
  8. end)

Change the soundkit for something on this list (I just took the first one):
https://github.com/Gethe/wow-ui-sour...tConstants.lua

Xrystal 04-30-21 10:38 AM

I play a hunter so will take a look see.

Yukka 04-30-21 11:32 AM

Nice, it works amazing :)

But where can I see the list of all sounds to choose another one?

Xrystal 04-30-21 11:34 AM

Quote:

Originally Posted by Yukka (Post 338998)
Nice, it works amazing :)

But where can I see the list of all sounds to choose another one?


Glad you got it working for you. My everyday fighting that didn't kill the pet didn't trigger any of the events for me rofl. So maybe it only triggers on death after combat.

To get the other sounds, the link under the code that was provided will give you the different sounds the game uses.

Yukka 04-30-21 11:43 AM

Oh nice I didnt saw it, thanks.
My pet was killed by the dummy at Boralus and there was a coin sound.
UI_LEGENDARY_LOOT_TOAST is a nice sound.

Edit: I changed the sound and deleted f:RegisterUnitEvent("UNIT_PET", "player") because this part plays the sound a second time when I use the Revive Pet ability. Just f:RegisterUnitEvent("UNIT_HEALTH", "pet") is enough.

Quote:

local f = CreateFrame("Frame")
f:RegisterUnitEvent("UNIT_HEALTH", "pet")
f:SetScript("OnEvent", function()
if not UnitExists("pet") or UnitHealth("pet") == 0 then
PlaySound(SOUNDKIT.UI_LEGENDARY_LOOT_TOAST)
end
end)

Kanegasi 04-30-21 12:36 PM

Quote:

Originally Posted by Yukka (Post 339000)
Oh nice I didnt saw it, thanks.
My pet was killed by the dummy at Boralus and there was a coin sound.
UI_LEGENDARY_LOOT_TOAST is a nice sound.

Edit: I changed the sound and deleted f:RegisterUnitEvent("UNIT_PET", "player") because this part plays the sound a second time when I use the Revive Pet ability. Just f:RegisterUnitEvent("UNIT_HEALTH", "pet") is enough.

You are not limited to that soundkit constant table. If you want to explore all of the possible sound IDs, you can browse https://www.wowhead.com/sounds and use the number in the URL for the sound page. For example, the "level up" sound is at https://www.wowhead.com/sound=888/levelup. The number in the URL is 888 so you would use PlaySound(888) to play it.

Examples I use for some stuff is PlaySound(23331) which has a few random "engineering doodad" fun sounds. I also use the old major/minor glyph sounds for special events PlaySoundFile(567404)PlaySoundFile(567487) I don't remember which one is which, but played together, they sound great.

Notice how those last two say "PlaySoundFile" instead. Sound IDs, which PlaySound uses, are basically indexes to a scripted table of sounds, some going to single sounds, others going to a group of randomly played sounds. File IDs, however, correlate directly to a file. File IDs are a little more tricky to get if you don't know what you're doing. wow.tools is one of the best tools available. That specific link takes you to the main sound table for the game. Searching names or IDs gets you File IDs in the FileDataID columns.

Going back to that engineering doodad ID, let's search for that. Now we know that ID plays one of five random sounds.


All times are GMT -6. The time now is 07:59 PM.

vBulletin © 2021, Jelsoft Enterprises Ltd
© 2004 - 2021 MMOUI