Difference between revisions of "Chained Volume Control (CMS)"
From The Official Visionaire Studio: Adventure Game Engine Wiki
m (→Main Script) (Tag: Visual edit) |
m (→Alternative Script) (Tag: Visual edit) |
||
Line 11: | Line 11: | ||
1. Add the [[#Main_Script|main script]] to the Visionaire Studio Script Editor & set the script as a definition script.<br /> | 1. Add the [[#Main_Script|main script]] to the Visionaire Studio Script Editor & set the script as a definition script.<br /> | ||
2. Edit the val part; as required... | 2. Edit the val part; as required... | ||
− | <syntaxhighlight> | + | <syntaxhighlight lang="lua"> |
local val = 10 | local val = 10 | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Line 48: | Line 48: | ||
== Alternative Script == | == Alternative Script == | ||
− | <syntaxhighlight> | + | <syntaxhighlight lang="lua"> |
--[[ | --[[ | ||
Chained Volume Control (smooth fade) [V1] (24/03/2014) | Chained Volume Control (smooth fade) [V1] (24/03/2014) |
Revision as of 14:55, 13 June 2018
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")
Alternative Script
--[[
Chained Volume Control (smooth fade) [V1] (24/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 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")