Chained Volume Control (CMS)
From The Official Visionaire Studio: Adventure Game Engine Wiki
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]
-- + --
email: afrlme@outlook.com
paypal: afrlme@zoho.com
patreon: https://www.patreon.com/AFRLme
portfolio: https://afrl.me
-- + --
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")
Alternative Script
--[[
Chained Volume Control (smooth fade) [V1] (24/03/2014)
Written by AFRLme [Lee Clarke]
-- + --
email: afrlme@outlook.com
paypal: afrlme@zoho.com
patreon: https://www.patreon.com/AFRLme
portfolio: https://afrl.me
-- + --
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 old, new, state
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
old = getVolume(eMusicVolume)
new = old - val
state = 1
end
end
-- * text stopped raise volume * --
function onTextStopped(text)
if text:getLink(VTextOwner):getId().tableId == eCharacters then state = 2 end
end
function onMainLoop()
if state == 1 and getVolume(eMusicVolume) > new then setVolume(eMusicVolume, (getVolume(eMusicVolume) - 1))
elseif state == 2 and getVolume(eMusicVolume) < old then setVolume(eMusicVolume, (getVolume(eMusicVolume) + 1))
else state = 0 end
end
-- * the event listeners for text start & stop * --
registerEventHandler("textStarted", "onTextStarted")
registerEventHandler("textStopped", "onTextStopped")
registerEventHandler("mainLoop", "onMainLoop")