View Single Post
01-08-18, 05:53 PM   #2
Kanegasi
A Molten Giant
 
Kanegasi's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2007
Posts: 666
EDIT: neither of these work, see this post for one that does

If you replaced the sound using the filepath trick (World of Warcraft\Sound etc):

Lua Code:
  1. local f=CreateFrame('frame')
  2. f:SetScript('OnEvent',function(self,_,handle)
  3.     if handle==self.handle then
  4.         SetCVar('Sound_MasterVolume',self.master)
  5.     end
  6. end)
  7. f:RegisterEvent('SOUNDKIT_FINISHED')
  8. hooksecurefunc('PlaySound',function(id,_,_,_,_,_,_,own)
  9.     if id==8960 and not own then
  10.         local played,handle=PlaySound(64,'Master',false)
  11.         if played and handle then
  12.             StopSound(handle) StopSound(handle-1)
  13.             played,handle=PlaySound(8960,'Master',true,true,nil,nil,nil,true)
  14.             if played and handle then
  15.                 f.handle=handle
  16.                 f.master=GetCVar('Sound_MasterVolume')
  17.                 SetCVar('Sound_MasterVolume',1)
  18.             end
  19.         end
  20.     end
  21. end)


If your sound is just in a folder (for example, Interface\AddOns\YourAddOn\sound.ogg):

Lua Code:
  1. local f=CreateFrame('frame')
  2. f:SetScript('OnEvent',function(self,_,handle)
  3.     if handle==self.handle then
  4.         SetCVar('Sound_MasterVolume',self.master)
  5.     end
  6. end)
  7. f:RegisterEvent('SOUNDKIT_FINISHED')
  8. hooksecurefunc('PlaySound',function(id)
  9.     if id==8960 then
  10.         local played,handle=PlaySound(64,'Master',false)
  11.         if played and handle then
  12.             StopSound(handle) StopSound(handle-1)
  13.             played,handle=PlaySoundFile('Interface\\path\\to\\sound.ogg','Master',true,true)
  14.             if played and handle then
  15.                 f.handle=handle
  16.                 f.master=GetCVar('Sound_MasterVolume')
  17.                 SetCVar('Sound_MasterVolume',1)
  18.             end
  19.         end
  20.     end
  21. end)


Just in case you aren't sure what to do with this, go to http://addon.bool.no, name this whatever you want at the top, copy one of these pieces of code into the big box, then download and install like any other addon.

Last edited by Kanegasi : 01-11-18 at 07:12 PM. Reason: doesn't work, new code in linked post
  Reply With Quote