Menu
Login
Language
DE EN FR ES IT CZ
Back

Changing music volume always at text?

  • #1, von Novel Mittwoch, 12. März 2014, 23:19 Uhr vor 12 Jahren Quote
    I have a very cool soundtrack now for my game, but it includes lyrics and I fear that it might interfer with the speech. One possibility is to really put it in the background by turnin the volume down all the time and just put it up when it's certain that nobody speaks.
    Another possibility would be to turn it down anytime someone starts to speak, but that's pretty exhausting to script manually, so I was wondering if that can be automated by using LUA maybe?

    Neuling

    100 Posts

  • #2, von afrlme Donnerstag, 13. März 2014, 00:59 Uhr vor 12 Jahren Quote
    I don't see why you couldn't use the registerHookFunction to check for displayed text or the registerEventHandler with textStarted, textStopped handles to dip & rise the volume wink
    -- * local variables * --
    local val = 10 -- amount to raise/lower the volume by...
    
    -- * text started lower volume * --
    function onTextStarted(text)
     if text:getLink(VTextOwner):getId().tableId == eCharacters then setVolume(eMusicVolume, (getVolume(eMusicVolume) - val)) end
    end
    
    -- * text stopped raise volume * --
    function onTextStopped(text)
     if text:getLink(VTextOwner):getId().tableId == eCharacters then setVolume(eMusicVolume, (getVolume(eMusicVolume) + val)) end
    end
    
    -- * the event listeners for text start & stop * --
    registerEventHandler("textStarted", "onTextStarted")
    registerEventHandler("textStopped", "onTextStopped")
    

    This is just a quick example. I've not tested the code.

    Foren Imperator

    7290 Posts

  • #3, von Novel Sonntag, 23. März 2014, 20:36 Uhr vor 12 Jahren Quote
    Awesome! It works perfectly! Thank you! smile

    Neuling

    100 Posts

  • #4, von afrlme Sonntag, 23. März 2014, 20:44 Uhr vor 12 Jahren Quote
    haha... I guess sometimes I can et things right on the first try... unusual for something I devised off the top of my noggin'! smile

    Welcomes, anyway.

    * edit: added script to the script index & vs functions page of the new wiki wink

    Foren Imperator

    7290 Posts

  • #5, von Novel Samstag, 27. Dezember 2014, 12:00 Uhr vor 11 Jahren Quote
    I'd like to enable the player to turn the music off and on via a key command. So I guess I need to turn the music volume to zero and then toggle a "bypass"-condition in which I'd embed your LUA script.

    A very simple task... but I still haven't learned the LUA-basics so I fail to solve it. Help!

    Neuling

    100 Posts

  • #6, von afrlme Samstag, 27. Dezember 2014, 13:19 Uhr vor 11 Jahren Quote
    You could do this with a condition & a value.

    -- updated lower/raise volume.
    -- * local variables * --
    local val = 10 -- amount to raise/lower the volume by...
    
    -- * text started lower volume * --
    function onTextStarted(text)
     if text:getLink(VTextOwner):getId().tableId == eCharacters and Conditions["music_muted"].ConditionValue then setVolume(eMusicVolume, (getVolume(eMusicVolume) - val)) end
    end
    
    -- * text stopped raise volume * --
    function onTextStopped(text)
     if text:getLink(VTextOwner):getId().tableId == eCharacters and Conditions["music_muted"].ConditionValue then setVolume(eMusicVolume, (getVolume(eMusicVolume) + val)) end
    end
    
    -- * the event listeners for text start & stop * --
    registerEventHandler("textStarted", "onTextStarted")
    registerEventHandler("textStopped", "onTextStopped")
    


    mute music script.
    if Conditions["music_muted"].ConditionValue then
     Conditions["music_muted"].ConditionValue = false -- set unmuted
     setVolume( eMusicVolume, Values["music_vol"].Int ) -- restore music volume
    else
     Conditions["music_muted"].ConditionValue = true -- set muted
     Values["music_vol"].Int = getVolume(eMusicVolume) -- store current music volume
     setVolume(eMusicVolume, 0) -- mute music volume
    end
    

    ...create the condition & value & add this script to an execute a script action part inside of a key input (released) action.

    Foren Imperator

    7290 Posts

  • #7, von Novel Samstag, 27. Dezember 2014, 21:39 Uhr vor 11 Jahren Quote
    Hm, doesn't work yet. Do the condition and the value have to go in a certain place? I just put them in some scene and didn't change anything. Toggeling the music with the script works then, but when the music is off, it comes back after any text is said.

    Neuling

    100 Posts

  • #8, von afrlme Samstag, 27. Dezember 2014, 23:23 Uhr vor 11 Jahren Quote
    ah yeah er sorry I should have added "not" before the conditions in the dynamic volume script part.

    -- * local variables * --
    local val = 10 -- amount to raise/lower the volume by...
    
    -- * text started lower volume * --
    function onTextStarted(text)
     if text:getLink(VTextOwner):getId().tableId == eCharacters and not Conditions["music_muted"].ConditionValue then setVolume(eMusicVolume, (getVolume(eMusicVolume) - val)) end
    end
    
    -- * text stopped raise volume * --
    function onTextStopped(text)
     if text:getLink(VTextOwner):getId().tableId == eCharacters and not Conditions["music_muted"].ConditionValue then setVolume(eMusicVolume, (getVolume(eMusicVolume) + val)) end
    end
    
    -- * the event listeners for text start & stop * --
    registerEventHandler("textStarted", "onTextStarted")
    registerEventHandler("textStopped", "onTextStopped")
    

    Foren Imperator

    7290 Posts

  • #9, von Novel Montag, 29. Dezember 2014, 13:13 Uhr vor 11 Jahren Quote
    Works! I love you. :-)

    Neuling

    100 Posts

  • #10, von wimf Donnerstag, 11. Februar 2016, 10:09 Uhr vor 10 Jahren Quote
    Hello. Nice script. It is possible to have the same effect (updated lower/raise volume) on the narration voice ?

    Thank in advance

    Foren Fan

    238 Posts

  • #11, von afrlme Donnerstag, 11. Februar 2016, 16:44 Uhr vor 10 Jahren Quote
    Yeah, you need to remove the if query bits from the 2 functions.
    -- * local variables * --
    local val = 10 -- amount to raise/lower the volume by...
    
    -- * text started lower volume * --
    function onTextStarted(text)
     if not Conditions["music_muted"].ConditionValue then setVolume(eMusicVolume, (getVolume(eMusicVolume) - val)) end
    end
    
    -- * text stopped raise volume * --
    function onTextStopped(text)
     if not Conditions["music_muted"].ConditionValue then setVolume(eMusicVolume, (getVolume(eMusicVolume) + val)) end
    end
    
    -- * the event listeners for text start & stop * --
    registerEventHandler("textStarted", "onTextStarted")
    registerEventHandler("textStopped", "onTextStopped")
    

    ... assuming you are using the same script as above. I just removed the queries that check if the text belongs to a character. Now it should work for any displayed text.

    Foren Imperator

    7290 Posts