Guest User

Untitled

a guest
Aug 21st, 2018
38
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --[[
  2. Sliding option handler [v1] (13/08/2018)
  3. Written by AFRLme [Lee Clarke]
  4. -- + --
  5. afrlme@outlook.com | https://de.tail.studio
  6. -- + --
  7. This script was created as freelance work for (game name) [developer name]. In game credit is non-negotiable.
  8. You are free to: ¹ use it in your game(s). ² modify the script.
  9. Do not remove - or edit - this comment block.
  10. --]]
  11.  
  12. -- * local vars for storing data * --
  13. local rail, anim, width, perc, pos, loop
  14.  
  15. -- * table for storing objects, interaction polygons, begin & end slider rail positions * --
  16. sliders = {
  17.  { obj = Objects["slider_music"].ObjectPolygon, b = 64, e = 864 },
  18.  { obj = Objects["slider_sound"].ObjectPolygon, b = 64, e = 864 }
  19. }
  20.  
  21. -- * sound tables for volume slider * --
  22. vol_sndz = { sfx = "vispath:Sounds/Character/Yeah.ogg" }
  23.  
  24. function slider_sound()
  25.  if rail == 2 then startSound(vol_sndz["sfx"], {flags = 1, volume = getVolume(eSoundVolume)}) end -- play sfx on sound volume change or lose focus
  26.  loop = nil; anim = nil; rail = nil -- reset some variables
  27.  Conditions["options_modified"].ConditionValue = true -- set options_modified condition to true to signify an option has been changed (will be used to determine if config.ini should be updated)
  28. end
  29.  
  30. -- * function that handles mouse events * --
  31. function onMouseEvent(typ, pos)
  32.  if game.CurrentScene:getName() == "options_menu" then -- force it to only register events for settings scene
  33.  
  34.   if typ == eEvtMouseLeftButtonHolding then
  35.     for i = 1, #sliders do
  36.      if isPointInsidePolygon(getCursorPos(), sliders[i].obj) then rail = i; if loop == nil then registerEventHandler("mainLoop", "updateSlider"); loop = true end end
  37.     end
  38.   elseif typ == eEvtMouseLeftButtonHold then
  39.    slider_sound(); unregisterEventHandler("mainLoop", "updateSlider")
  40.   end
  41.  
  42.  end
  43. end
  44.  
  45. function updateSlider()
  46.  if rail ~= nil then
  47.   pos = getCursorPos().x; if pos  sliders[rail].e then pos = sliders[rail].e end
  48.   perc = math.floor( (getCursorPos().x - sliders[rail].b) / (sliders[rail].e - sliders[rail].b) * 100 ) -- convert mouse position on rail to percentage value
  49.   if perc  100 then perc = 100 end -- fallback in case percentage lower than 0 or higher than 100
  50.   if not isPointInsidePolygon(getCursorPos(), sliders[rail].obj) then slider_sound(); unregisterEventHandler("mainLoop", "updateSlider") end
  51.   if rail == 1 then
  52.    setVolume(eMusicVolume, perc) -- update music volume
  53.   elseif rail == 2 then
  54.    setVolume(eSoundVolume, perc) -- update sound volume
  55.   end
  56.   anim = ActiveAnimations["vol_"..rail] -- get animation current position
  57.   anim.AnimationCurrentPosition = {x = (pos - 23) , y = anim.AnimationCurrentPosition.y} -- update rail handle position
  58.   if anim.AnimationCurrentPosition.x  sliders[rail].e then anim.AnimationCurrentPosition = {x = (sliders[rail].e - 23), y = anim.AnimationCurrentPosition.y} end
  59.  end
  60. end
  61.  
  62. registerEventHandler("mouseEvent", "onMouseEvent") -- creates an event listener & assigns it to a function "onMouseEvent" to handle mouse events
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×