Allow setting the volume for a sound in the trigger dialog

Posted by Kahenraz on Tue 27 Sep 2016 08:07 PM — 2 posts, 14,547 views.

#0
Currently I have to either modify my sound files in Audacity to change their volume or use PlaySound() and run the effect as a script, which then requires me to use the world input debugger every time I want to test the volume.

Neither of these options are straightforward or convenient. It would be great if I could set the volume right there in the "sound" area of the trigger dialog.
Australia Forum Administrator #1
I don't really want to fiddle with the resources layout as people may have re-done those in different languages. See:

http://www.gammon.com.au/scripts/doc.php?general=plugin_callbacks

There is a callback: OnPluginPlaySound

That lets you handle the sound playing (for example for triggers). Here is an example plugin I made a while back that plays different volume levels and panning depending on the file name:


<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>

<muclient>
<plugin
   name="Sound_Volume_Reducer"
   author="Nick Gammon"
   id="b1308ed1e6d5e4facdaf7bdd"
   language="Lua"
   purpose="Plays trigger sounds more quietly"
   date_written="2010-06-02 06:33:40"
   requires="4.40"
   version="1.0"
   >
<description trim="y">
<![CDATA[
Install this to play trigger sounds at reduced volume.
]]>
</description>

</plugin>

<!--  Script  -->

<script>
<![CDATA[

volumes = {
  ["west"] = { volume = -6, pan = -100} ,
  ["east"] = { volume = -15, pan = 100} ,
  }
  
function OnPluginPlaySound (sound)

  -- defaults
  local volume = -12
  local pan = 0
  
  -- search file name for a keyword that affects its volume
  for k, v in pairs (volumes) do
    if string.match (sound, k) then
      volume = v.volume
      pan = v.pan
      break
    end -- if matched part of sound name
  end -- for
  
  PlaySound (0, sound, false, volume, pan)  -- play supplied sound as required
end -- function

]]>
</script>
</muclient>


You could do something similar that checks a variable and plays at that sound level. Then make an alias to alter the variable's value. You could make another alias to do a test sound.