Advertisement
AFRLme

Modified Volume Slider Script [VS] (works)

Nov 10th, 2012
383
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.39 KB | None | 0 0
  1. -- * notes * --
  2. -- this is only the main part of the script - the rest is done inside the editor itself!
  3. -- this is my modified english version of einzelkaempfer's vol slider script!
  4. -- I've added various new functions like:
  5. -- º active handle animation image on mouse button hold
  6. -- º plays a sound or speech file depending on current active volume type
  7. -- º added various glitch fixes
  8. -- º included some print statements to log file
  9. -- º etc
  10. -- * --
  11. -- Regards, Lee :)
  12.  
  13. -- VolConMinPos / VolConMaxPos(volume control slider minimum/maximum position; x axis - "ReglerMinPos/ReglerMaxPos")
  14. -- VolConWidth (the width of the image you're using as the slider handle - "ReglerWidth")
  15. -- VolConYPos (sets the y position (vertical axis) of the slider handles - use bottom edge of image for y position - "ReglerYPos"
  16.  
  17. VolConMinPos = 1063
  18. VolConMaxPos = 1872
  19. VolConWidth = 18
  20. VolConYPos = {558; 477; 395} --music(0),sfx(1),voice(2)
  21.  
  22. ------------------------------------------------------------------
  23.  
  24. -- VolConTotal (gets the distance between the min & max pos - "ReglerTotal")
  25. -- Slider1 (converts volcontotal into % - "Regler1")
  26. -- defaultHoldTime (time it take for mouse hold to register "GehaltenStandard")
  27. -- play_sound (variable containing the location to an action that plays a sound file)
  28. -- play_speech (variable containing the location to an action that plays a speech file)
  29.  
  30. VolConTotal = VolConMaxPos - VolConMinPos
  31. Slider1 = VolConTotal / 100
  32. defaultHoldTime = game:getInt(VGameHoldTime)
  33. play_sound = getObject('Scenes[Options_Menu].SceneActions[play_sound]')
  34. play_speech = getObject('Scenes[Options_Menu].SceneActions[play_speech]')
  35.  
  36. -- Load Volume Options Script
  37. -- i = 0, 2 (i defines which slider is active: music[0], sfx[1], voice[2])  
  38. -- VolVal (volume value is the volume level - "VolWert")
  39.  
  40. function beginVolCon()
  41.   for i = 0, 2 do
  42.     startAnimation("Animations[AniVolCon_" .. i .. "]")
  43.     startAnimation("Animations[AniVolCon_" .. i .. "x]")
  44.  
  45.     local VolVal = getVolume(i)
  46.     if VolVal < 0 then
  47.       setVolume(i, 0)
  48.       VolVal = 0
  49.     elseif VolVal > 100 then
  50.       setVolume(i, 100)
  51.       VolVal = 100
  52.     end
  53.    
  54.     local VolConPos = math.floor((VolVal * Slider1 + VolConMinPos) + 0.5)
  55.  
  56.  setVolConPos(i, VolConPos)
  57.   end
  58.  print("volume script has been started!")
  59. end
  60.  
  61. -- Set the positions of the slider handles (slider only)
  62. function setVolConPos(typ, xpos)
  63.   local VolAnim = getObject("ActiveAnimations[AniVolCon_" .. typ .. "]")
  64.   local VolAnim2 = getObject("ActiveAnimations[AniVolCon_" .. typ .. "x]")
  65.   VolAnim:setValue(VAnimationCurrentPosition, {x=xpos,y=VolConYPos[typ + 1]})
  66.   VolAnim2:setValue(VAnimationCurrentPosition, {x=xpos,y=VolConYPos[typ + 1]})
  67. end
  68.  
  69. -- Set the positions of the slider handles (buttons only)
  70. function setVolConPos2(typ, xpos)
  71.   local VolAnim = getObject("ActiveAnimations[AniVolCon_" .. typ .. "]")
  72.   VolAnim:setValue(VAnimationCurrentPosition, {x=xpos,y=VolConYPos[typ + 1]})
  73. end
  74.  
  75.  
  76. -- Checks if mouse button is being held down
  77. function mousebtnHold(standard)
  78.   if standard == false then
  79.     game:setValue(VGameHoldTime, 1)
  80.   else
  81.     game:setValue(VGameHoldTime, defaultHoldTime)
  82.   end
  83. end
  84.  
  85.  
  86. -- The function which allows you to drag the slider handle
  87. function dragVolCon(typ)
  88.   local CursorPos = getCursorPos()
  89.   local VolConPos = math.floor(CursorPos.x - VolConWidth / 2 + 0.5)
  90.  
  91.   if VolConPos < VolConMinPos then
  92.     VolConPos = VolConMinPos
  93.   elseif VolConPos > VolConMaxPos then
  94.     VolConPos = VolConMaxPos
  95.   end
  96.  
  97.   setVolConPos(typ, VolConPos)
  98.  
  99.   local VolVal = math.floor(((VolConPos - VolConMinPos) / Slider1) + 0.5)
  100.   setVolume(typ, VolVal)
  101.  
  102. end
  103.  
  104.  
  105. -- Plus_Minus Buttons raise or lower vol by 10%
  106. function pluminClick(typ, cond)
  107.   VolVal = getVolume(typ)
  108.  
  109.   if cond == true then
  110.     VolVal = VolVal + 10
  111.     if VolVal > 100 then VolVal = 100 end
  112.   else
  113.     VolVal = VolVal - 10
  114.     if VolVal < 0 then VolVal = 0 end      
  115.   end
  116.  
  117.   setVolume(typ, VolVal)
  118.   local VolConPos = math.floor((VolVal * Slider1 + VolConMinPos) + 0.5)
  119.  
  120.   setVolConPos2(typ, VolConPos)
  121.  
  122.  if typ == 1 then
  123.   startAction(play_sound)
  124.   print("sound volume is now set at " .. VolVal .. " - button")
  125.  else
  126.  if typ == 2 then
  127.   startAction(play_speech)
  128.   print("speech volume is now set at " .. VolVal .." - button")
  129.  else
  130.   print("music Volume is now set at " .. VolVal .. " - button")
  131.  end
  132.  end
  133.  
  134. end -- pluminClick()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement