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

From The Official Visionaire Studio: Adventure Game Engine Wiki
 
(15 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{| class="wikitable" style="width:100%"
+
{| class="ts" style="width:100%"
 
|-
 
|-
! style="text-align:left" | Name !! style="text-align:left" | Type !! style="text-align:left" | By !! style="text-align:left;width:10%" | Share
+
! style="text-align:left" | Name !! style="text-align:left" | Type !! style="text-align:left" | By
 
|-
 
|-
| Chained Volume Control || Definition || AFRLme || {{#TwitterFBLike:|small|like}}
+
| Chained Volume Control || Definition || [https://www.patreon.com/AFRLme AFRLme]
 
|}
 
|}
  
Line 9: Line 9:
  
 
== Instructions ==
 
== Instructions ==
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 17: Line 17:
  
 
== Main Script ==
 
== Main Script ==
<syntaxhighlight>
+
<html><button class="copybtn" onclick="CopyToClipboard('main_script')"></button></html>
 +
<syntaxhighlight lang="lua" id="main_script">
 
--[[
 
--[[
 
Chained Volume Control [V1] (13/03/2014)
 
Chained Volume Control [V1] (13/03/2014)
 
Written by AFRLme [Lee Clarke]
 
Written by AFRLme [Lee Clarke]
 
-- + --
 
-- + --
alternatingfrequencies@hotmail.com | skype @ AFRLme
+
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.
 
This script is donation optional. In game credit is non-negotiable.
Line 48: Line 52:
  
 
== 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)
 
Written by AFRLme [Lee Clarke]
 
Written by AFRLme [Lee Clarke]
 
-- + --
 
-- + --
alternatingfrequencies@hotmail.com | skype @ AFRLme
+
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.
 
This script is donation optional. In game credit is non-negotiable.
Line 89: Line 96:
 
registerEventHandler("textStopped", "onTextStopped")
 
registerEventHandler("textStopped", "onTextStopped")
 
registerEventHandler("mainLoop", "onMainLoop")
 
registerEventHandler("mainLoop", "onMainLoop")
</syntaxhighlight>
+
</syntaxhighlight>{{toc}}

Latest revision as of 16:09, 15 September 2022

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