Advertisement
Guest User

Untitled

a guest
Aug 19th, 2017
443
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.65 KB | None | 0 0
  1. core:import("CoreMissionScriptElement")
  2. ElementCustomSound = ElementCustomSound or class(CoreMissionScriptElement.MissionScriptElement)
  3.  
  4. function ElementCustomSound:init(...)
  5. ElementCustomSound.super.init(self, ...)
  6. end
  7. function ElementCustomSound:client_on_executed(...)
  8. self:on_executed(...)
  9. end
  10.  
  11. function ElementCustomSound:play(src)
  12. if MusicModule then
  13. managers.music:stop_custom()
  14. Global.music_manager.source:post_event("stop_all_music")
  15. managers.music._player = managers.menu_component._main_panel:video({
  16. name = "music",
  17. video = src,
  18. visible = false,
  19. loop = self._values.loop or false
  20. })
  21. managers.music._player:set_volume_gain(Global.music_manager.volume)
  22. end
  23. end
  24.  
  25. function ElementCustomSound:play_secondary(src)
  26. if MusicModule then
  27. managers.menu_component._secondary_panel = managers.menu_component._ws:panel():panel()
  28. self._secondary_player = managers.menu_component._secondary_panel:video({
  29. name = "secondary_sound",
  30. video = src,
  31. visible = false,
  32. loop = false
  33. })
  34. self._secondary_player:set_volume_gain(Global.music_manager.volume)
  35. end
  36. end
  37.  
  38. function ElementCustomSound:stop()
  39.  
  40. if MusicModule then
  41. managers.music:stop_custom()
  42. Global.music_manager.source:post_event("stop_all_music")
  43. end
  44.  
  45. end
  46.  
  47. function ElementCustomSound:on_executed(instigator)
  48.  
  49. log("[ELEMENT] Attempt to execute CustomSound")
  50.  
  51. if not MusicModule then
  52. log("[ELEMENT] ERROR! MusicModule NOT FOUND")
  53. return
  54. end
  55.  
  56. if not self._values.enabled then
  57. log("[ELEMENT] ERROR! Element is NOT ENABLED")
  58. return
  59. end
  60.  
  61. if self._values.force_stop then
  62. log("[ELEMENT] Force Stop Executed")
  63. self:stop()
  64. return
  65. end
  66.  
  67. if not self._values.sound_path or self._values.sound_path == "" then
  68. log("[ELEMENT] There is no sound with that path to play. Stopping...")
  69. managers.music:stop_custom()
  70. return
  71. end
  72.  
  73. if self._values.sound_path and not self._values.use_as_secondary then
  74. log("[ELEMENT] Playing on the PRIMARY CHANNEL")
  75. self:play(self._values.sound_path)
  76. end
  77.  
  78. if self._values.sound_path and self._values.use_as_secondary then
  79. log("[ELEMENT] Playing on the SECONDARY CHANNEL")
  80. self:play_secondary(self._values.sound_path)
  81. end
  82.  
  83. if self._values.use_as_secondary and self._values.use_subtitles then
  84. log("[ELEMENT] Playing on the SECONDARY CHANNEL WITH SUBTITLES")
  85. local string_id = self._values.subtitle_id or ""
  86. local duration = self._values.subtitle_duration or 5
  87.  
  88. DramaExt:play_subtitle(string_id, duration)
  89. end
  90. log("[ELEMENT] Executed.")
  91.  
  92. ElementCustomSound.super.on_executed(self, instigator)
  93. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement