View Single Post
10-30-17, 05:09 PM   #9
MunkDev
A Scalebane Royal Guard
 
MunkDev's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2015
Posts: 431
Actually, now that we're talking about sound kits, I remembered that PlaySound was replaced by PlaySoundkitID in 7.2(?) so you can actually mute sounds with a filthy little hack. PlaySoundkitID (and PlaySoundFile) both return handles in the form of an integer ID that increments on every call. So by hooking into PlaySound and playing another sound immediately after it you can figure out the sound handle ID and cancel it.


Lua Code:
  1. local mutex = false -- need this so it doesn't recurse when PlaySound is called from within
  2. hooksecurefunc('PlaySound', function(id)
  3.           if mutex then return end -- we called this time, just return
  4.           mutex = true -- flag mutex
  5.           -- play another sound to figure out the ID.
  6.           -- can't play the same sound because it's occupied by another handle.
  7.           local played, handle = PlaySound(id+1) -- just use the ID+1 to guarantee it's different
  8.           mutex = false -- unflag mutex
  9.           if played then
  10.                StopSound(handle-1) -- stop the sound you wanted to stop in the first place
  11.                StopSound(handle) -- stop your dummy sound
  12.           end
  13. end)

This should effectively do what you asked for, without replacing the function and without spreading taint.
__________________

Last edited by MunkDev : 10-30-17 at 05:35 PM.
  Reply With Quote