Difference between revisions of "Chained Volume Control (CMS)"

From The Official Visionaire Studio: Adventure Game Engine Wiki
(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...")
 
Line 45: Line 45:
 
registerEventHandler("textStarted", "onTextStarted")
 
registerEventHandler("textStarted", "onTextStarted")
 
registerEventHandler("textStopped", "onTextStopped")
 
registerEventHandler("textStopped", "onTextStopped")
 +
</syntaxhighlight>
 +
 +
== Alternative Script ==
 +
<syntaxhighlight>
 +
--[[
 +
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")
 
</syntaxhighlight>
 
</syntaxhighlight>

Revision as of 19:06, 24 March 2014

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")