Login / Registrieren
DE EN FR ES IT CZ
Zurück Nach oben

Changing music volume always at text?

  • #1, by Novel 12 years ago Zitieren
    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?
  • #2, by afrlme 12 years ago Zitieren
    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.
  • #3, by Novel 12 years ago Zitieren
    Awesome! It works perfectly! Thank you! smile
  • #4, by afrlme 12 years ago Zitieren
    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
  • #5, by Novel 12 years ago Zitieren
    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!
  • #6, by afrlme 12 years ago Zitieren
    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.
  • #7, by Novel 12 years ago Zitieren
    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.
  • #8, by afrlme 12 years ago Zitieren
    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")
    

  • #9, by Novel 12 years ago Zitieren
    Works! I love you. :-)
  • #10, by wimf 10 years ago Zitieren
    Hello. Nice script. It is possible to have the same effect (updated lower/raise volume) on the narration voice ?

    Thank in advance
  • #11, by afrlme 10 years ago Zitieren
    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.