aralserdar
New Member
-- Result:
obs = obslua
interval = 30
pause_interval = 30
source_count = 1
old_count = 0
selectedsources = {}
sourceidx = 0
gsettings = nil
tick = 0
-- ------------------------------------------------------------
function update_text()
if tick >= interval and sourceidx < source_count then
tick = tick - interval
sourceidx = sourceidx + 1
end
if sourceidx >= source_count then --Pause duration
if tick >= pause_interval then
sourceidx = 0
tick = tick - pause_interval
else
tick = tick + 1
--hide all sources
for i = 0, source_count - 1 do
local other_source_name = obs.obs_data_get_string(gsettings, selectedsources)
local other_source = obs.obs_get_source_by_name(other_source_name)
if other_source ~= nil then
obs.obs_source_set_enabled(other_source, false)
end
end
print("Pausing-----")
return
end
end
if gsettings == nil then
return false
end
local source_name
local source
if source_count > sourceidx then
source_name = obs.obs_data_get_string(gsettings, selectedsources[sourceidx])
else
source_name = ''
end
source = obs.obs_get_source_by_name(source_name)
--hide other sources
for i = 0, source_count - 1 do
local other_source_name = obs.obs_data_get_string(gsettings, selectedsources)
local other_source = obs.obs_get_source_by_name(other_source_name)
if i ~= sourceidx and other_source ~= nil then
obs.obs_source_set_enabled(other_source, false)
end
end
--show only selected source and reset it
if source_name ~= '' and source ~= nil then
print(string.format("Enabling #%s#", source_name))
obs.obs_source_set_enabled(source, true)
if tick == 0 then
local settings = obs.obs_data_create()
obs.obs_data_set_string(settings, 'text', 'reset')
obs.obs_source_update(source, settings)
obs.obs_data_release(settings)
obs.obs_source_release(source)
end
end
tick = tick + 1
end
-- ------------------------------------------------------------
function script_description()
return 'Repeat Media Sources Periodically.\n\nBy CreatorSet.com'
end
function script_update(settings)
print('script_update')
sourceidx = 0
gsettings = settings
old_count = source_count
interval = obs.obs_data_get_int(settings, 'interval')
pause_interval = obs.obs_data_get_int(settings, 'pause_interval')
source_count = obs.obs_data_get_int(settings, 'source_count')
obs.timer_remove(update_text)
selectedsources = {}
for i = 0, source_count - 1 do
table.insert(selectedsources, i, string.format('Source #%d', i + 1))
end
obs.timer_add(update_text, 1000)
tick = 0
end
function script_defaults(settings)
obs.obs_data_set_default_int(settings, 'interval', 12)
obs.obs_data_set_default_int(settings, 'pause_interval', 5)
obs.obs_data_set_default_int(settings, 'source_count', 1)
end
function on_source_count(props, prop, settings)
print('on_source_count')
diff = source_count - old_count
if diff > 0 then
for idx = old_count, old_count + diff - 1 do
local p =
obs.obs_properties_add_list(
props,
string.format('Source #%d', idx + 1),
string.format('Source #%d', idx + 1),
obs.OBS_COMBO_TYPE_LIST,
obs.OBS_COMBO_FORMAT_STRING
)
local sources = obs.obs_enum_sources()
if sources ~= nil then
for source in ipairs(sources) do
local source_id = obs.obs_source_get_unversioned_id(sources[source])
if source_id == 'ffmpeg_source' then -- or source_id == "text_ft2_source" then
local name = obs.obs_source_get_name(sources[source])
local scene = obs.obs_scene_from_source(obs.obs_frontend_get_current_scene())
local s = obs.obs_scene_find_source(scene, name)
if s ~= nil then
obs.obs_property_list_add_string(p, name, name)
end
end
end
obs.source_list_release(sources)
end
end
end
return true
end
function script_properties()
props = obs.obs_properties_create()
obs.obs_properties_add_int(props, 'interval', 'Play duration of each media (seconds)', 1, 3600, 1)
obs.obs_properties_add_int(props, 'pause_interval', 'Pause duration after loop (seconds)', 1, 3600, 1)
local t = obs.obs_properties_add_int(props, 'source_count', 'Source Count', 1, 1000, 1)
obs.obs_property_set_modified_callback(t, on_source_count)
for idx = 0, source_count - 1 do
local p =
obs.obs_properties_add_list(
props,
string.format('Source #%d', idx + 1),
string.format('Source #%d', idx + 1),
obs.OBS_COMBO_TYPE_LIST,
obs.OBS_COMBO_FORMAT_STRING
)
local sources = obs.obs_enum_sources()
if sources ~= nil then
for source in ipairs(sources) do
local source_id = obs.obs_source_get_unversioned_id(sources[source])
if source_id == 'ffmpeg_source' then -- or source_id == "text_ft2_source" then
local name = obs.obs_source_get_name(sources[source])
local scene = obs.obs_scene_from_source(obs.obs_frontend_get_current_scene())
local s = obs.obs_scene_find_source(scene, name)
if s ~= nil then
obs.obs_property_list_add_string(p, name, name)
end
end
end
obs.source_list_release(sources)
end
end
return props
end
obs = obslua
interval = 30
pause_interval = 30
source_count = 1
old_count = 0
selectedsources = {}
sourceidx = 0
gsettings = nil
tick = 0
-- ------------------------------------------------------------
function update_text()
if tick >= interval and sourceidx < source_count then
tick = tick - interval
sourceidx = sourceidx + 1
end
if sourceidx >= source_count then --Pause duration
if tick >= pause_interval then
sourceidx = 0
tick = tick - pause_interval
else
tick = tick + 1
--hide all sources
for i = 0, source_count - 1 do
local other_source_name = obs.obs_data_get_string(gsettings, selectedsources)
local other_source = obs.obs_get_source_by_name(other_source_name)
if other_source ~= nil then
obs.obs_source_set_enabled(other_source, false)
end
end
print("Pausing-----")
return
end
end
if gsettings == nil then
return false
end
local source_name
local source
if source_count > sourceidx then
source_name = obs.obs_data_get_string(gsettings, selectedsources[sourceidx])
else
source_name = ''
end
source = obs.obs_get_source_by_name(source_name)
--hide other sources
for i = 0, source_count - 1 do
local other_source_name = obs.obs_data_get_string(gsettings, selectedsources)
local other_source = obs.obs_get_source_by_name(other_source_name)
if i ~= sourceidx and other_source ~= nil then
obs.obs_source_set_enabled(other_source, false)
end
end
--show only selected source and reset it
if source_name ~= '' and source ~= nil then
print(string.format("Enabling #%s#", source_name))
obs.obs_source_set_enabled(source, true)
if tick == 0 then
local settings = obs.obs_data_create()
obs.obs_data_set_string(settings, 'text', 'reset')
obs.obs_source_update(source, settings)
obs.obs_data_release(settings)
obs.obs_source_release(source)
end
end
tick = tick + 1
end
-- ------------------------------------------------------------
function script_description()
return 'Repeat Media Sources Periodically.\n\nBy CreatorSet.com'
end
function script_update(settings)
print('script_update')
sourceidx = 0
gsettings = settings
old_count = source_count
interval = obs.obs_data_get_int(settings, 'interval')
pause_interval = obs.obs_data_get_int(settings, 'pause_interval')
source_count = obs.obs_data_get_int(settings, 'source_count')
obs.timer_remove(update_text)
selectedsources = {}
for i = 0, source_count - 1 do
table.insert(selectedsources, i, string.format('Source #%d', i + 1))
end
obs.timer_add(update_text, 1000)
tick = 0
end
function script_defaults(settings)
obs.obs_data_set_default_int(settings, 'interval', 12)
obs.obs_data_set_default_int(settings, 'pause_interval', 5)
obs.obs_data_set_default_int(settings, 'source_count', 1)
end
function on_source_count(props, prop, settings)
print('on_source_count')
diff = source_count - old_count
if diff > 0 then
for idx = old_count, old_count + diff - 1 do
local p =
obs.obs_properties_add_list(
props,
string.format('Source #%d', idx + 1),
string.format('Source #%d', idx + 1),
obs.OBS_COMBO_TYPE_LIST,
obs.OBS_COMBO_FORMAT_STRING
)
local sources = obs.obs_enum_sources()
if sources ~= nil then
for source in ipairs(sources) do
local source_id = obs.obs_source_get_unversioned_id(sources[source])
if source_id == 'ffmpeg_source' then -- or source_id == "text_ft2_source" then
local name = obs.obs_source_get_name(sources[source])
local scene = obs.obs_scene_from_source(obs.obs_frontend_get_current_scene())
local s = obs.obs_scene_find_source(scene, name)
if s ~= nil then
obs.obs_property_list_add_string(p, name, name)
end
end
end
obs.source_list_release(sources)
end
end
end
return true
end
function script_properties()
props = obs.obs_properties_create()
obs.obs_properties_add_int(props, 'interval', 'Play duration of each media (seconds)', 1, 3600, 1)
obs.obs_properties_add_int(props, 'pause_interval', 'Pause duration after loop (seconds)', 1, 3600, 1)
local t = obs.obs_properties_add_int(props, 'source_count', 'Source Count', 1, 1000, 1)
obs.obs_property_set_modified_callback(t, on_source_count)
for idx = 0, source_count - 1 do
local p =
obs.obs_properties_add_list(
props,
string.format('Source #%d', idx + 1),
string.format('Source #%d', idx + 1),
obs.OBS_COMBO_TYPE_LIST,
obs.OBS_COMBO_FORMAT_STRING
)
local sources = obs.obs_enum_sources()
if sources ~= nil then
for source in ipairs(sources) do
local source_id = obs.obs_source_get_unversioned_id(sources[source])
if source_id == 'ffmpeg_source' then -- or source_id == "text_ft2_source" then
local name = obs.obs_source_get_name(sources[source])
local scene = obs.obs_scene_from_source(obs.obs_frontend_get_current_scene())
local s = obs.obs_scene_find_source(scene, name)
if s ~= nil then
obs.obs_property_list_add_string(p, name, name)
end
end
end
obs.source_list_release(sources)
end
end
return props
end