Chained Volume Control (CMS)

From The Official Visionaire Studio: Adventure Game Engine Wiki
Revision as of 20:59, 23 March 2014 by AFRLme (talk) (Created page with "{| class="wikitable" style="width:100%" |- ! style="text-align:left" | Name !! style="text-align:left" | Type !! style="text-align:left" | By |- | Chained Volume Control || De...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Name Type By
Chained Volume Control Definition AFRLme

This script automatically lowers the music volume during speech file playback & raises it back up again after speech file playback has ended.

Instructions

1. Add the main script to the Visionaire Studio Script Editor & set the script as a definition script.
2. Edit the val part; as required...

local val = 10

3. Sit back & let it work its magic.

Main Script

--[[
Chained Volume Control [V1] (13/03/2014)
Written by AFRLme [Lee Clarke]
-- + --
alternatingfrequencies@hotmail.com | skype @ AFRLme
-- + --
This script is donation optional. In game credit is non-negotiable.
You are free to: ¹ use it in your game(s). ² modify the script.
Do not remove - or edit - this comment block.
--]]

-- * local variables * --
local val = 10 -- percentage 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")