I received a private message asking to customize the volume in my code. I also didn't notice the last post here. Here's an updated code that allows you to replace any UI sound (anything that uses PlaySound) with a custom sound
OR adjust the volume of a UI sound.
Lua Code:
local entries={
[8960]=1 -- ready check
-- [ID]="path\\to\\sound"
-- [ID]=volume
}
-- the table above is where you enter the sound ID you want to change,
-- with the volume you want it at OR the path to a custom sound you want.
-- for example, [8960]=0.7 will play the ready check sound at 70%.
-- a custom example of [8960]="chicken.ogg" will play the sound file at
-- World of Warcraft\_retail_\chicken.ogg instead of the default ready check.
-- custom sounds can be placed alone anywhere in the running client's folder,
-- they do not need to be used by another addon. Examples:
-- _retail_\Sound\chicken.ogg
-- _classic_\Interface\AddOns\chicken.ogg
-- _classic_\WTF\chicken.ogg
-- _retail_\ASDFGHJKL\chicken.ogg
-- the path needed here is everything AFTER the _retail_ or _classic_ folder,
-- the sound file has to be there when WoW is started to be recognized.
-- this code is unable to control the volume of a custom sound,
-- you have to adjust the volume of the sound file itself.
-- PlaySoundFile also does not guarantee no dupes.
local pool,f={},CreateFrame('frame') f.handles={} f.lastchan={} f.nodupeids={} f.nodupehandles={}
function f.pool(t,i)
if i then pool[i]:SetScript('OnUpdate',nil) pool[i].t=nil return end
for i=1,#pool do
if pool[i] and not pool[i].t then pool[i].t={i=i,t=t} return i end
end
tinsert(pool,CreateFrame('frame')) i=#pool pool[i].t={i=i,t=t} return i
end
f:SetScript('OnEvent',function(_,_,handle)
if f.nodupehandles[handle] then
f.nodupeids[f.nodupehandles[handle]]=nil
f.nodupehandles[handle]=nil
end
if f.handles[handle] then
if f[f.handles[handle]] and f.lastchan[f.handles[handle]]==handle then
SetCVar(f.handles[handle],f[f.handles[handle]])
f[f.handles[handle]]=nil
end
f.handles[handle]=nil
end
end)
f:RegisterEvent('SOUNDKIT_FINISHED')
hooksecurefunc('PlaySound',function(id,channel,nodupe,_,_,_,_,own)
if not own and not f.nodupeids[id] and entries[id] then
local _,handle=PlaySound(64,'Master',false)
if handle then
StopSound(handle) StopSound(handle-1)
channel=(not channel and 'Master') or (strlower(channel)=='sfx' and 'SFX') or strlower(channel):gsub('^%a',strupper)
local cvar='Sound_'..channel..'Volume'
pool[f.pool({id,channel,nodupe,cvar})]:SetScript('OnUpdate',function(self)
local handle=nil
if type(entries[self.t.t[1]])=="string" then
_,handle=PlaySoundFile(entries[self.t.t[1]],self.t.t[2],self.t.t[3])
else
_,handle=PlaySound(self.t.t[1],self.t.t[2],self.t.t[3],true,nil,nil,nil,true)
end
if type(entries[self.t.t[1]])=="number" and handle then
if self.t.t[3]~=false then
f.nodupeids[self.t.t[1]]=handle
f.nodupehandles[handle]=self.t.t[1]
end
f.lastchan[self.t.t[4]]=handle
f.handles[handle]=self.t.t[4]
if not f[self.t.t[4]] then
f[self.t.t[4]]=GetCVar(self.t.t[4])
if f[self.t.t[4]] then SetCVar(self.t.t[4],entries[self.t.t[1]]) end
end
end
f.pool('',self.t.i)
end)
end
end
end)