Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- core:import("CoreMissionScriptElement")
- ElementCustomSound = ElementCustomSound or class(CoreMissionScriptElement.MissionScriptElement)
- function ElementCustomSound:init(...)
- ElementCustomSound.super.init(self, ...)
- end
- function ElementCustomSound:client_on_executed(...)
- self:on_executed(...)
- end
- function ElementCustomSound:play(src)
- if MusicModule then
- managers.music:stop_custom()
- Global.music_manager.source:post_event("stop_all_music")
- managers.music._player = managers.menu_component._main_panel:video({
- name = "music",
- video = src,
- visible = false,
- loop = self._values.loop or false
- })
- managers.music._player:set_volume_gain(Global.music_manager.volume)
- end
- end
- function ElementCustomSound:play_secondary(src)
- if MusicModule then
- managers.menu_component._secondary_panel = managers.menu_component._ws:panel():panel()
- self._secondary_player = managers.menu_component._secondary_panel:video({
- name = "secondary_sound",
- video = src,
- visible = false,
- loop = false
- })
- self._secondary_player:set_volume_gain(Global.music_manager.volume)
- end
- end
- function ElementCustomSound:stop()
- if MusicModule then
- managers.music:stop_custom()
- Global.music_manager.source:post_event("stop_all_music")
- end
- end
- function ElementCustomSound:on_executed(instigator)
- log("[ELEMENT] Attempt to execute CustomSound")
- if not MusicModule then
- log("[ELEMENT] ERROR! MusicModule NOT FOUND")
- return
- end
- if not self._values.enabled then
- log("[ELEMENT] ERROR! Element is NOT ENABLED")
- return
- end
- if self._values.force_stop then
- log("[ELEMENT] Force Stop Executed")
- self:stop()
- return
- end
- if not self._values.sound_path or self._values.sound_path == "" then
- log("[ELEMENT] There is no sound with that path to play. Stopping...")
- managers.music:stop_custom()
- return
- end
- if self._values.sound_path and not self._values.use_as_secondary then
- log("[ELEMENT] Playing on the PRIMARY CHANNEL")
- self:play(self._values.sound_path)
- end
- if self._values.sound_path and self._values.use_as_secondary then
- log("[ELEMENT] Playing on the SECONDARY CHANNEL")
- self:play_secondary(self._values.sound_path)
- end
- if self._values.use_as_secondary and self._values.use_subtitles then
- log("[ELEMENT] Playing on the SECONDARY CHANNEL WITH SUBTITLES")
- local string_id = self._values.subtitle_id or ""
- local duration = self._values.subtitle_duration or 5
- DramaExt:play_subtitle(string_id, duration)
- end
- log("[ELEMENT] Executed.")
- ElementCustomSound.super.on_executed(self, instigator)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement