obs = obslua source_name = "" format_string = "%H:%M" mode = 1 Gtime = "" time_array = {1,1,1,1,1} path_array = {} transition_array ={"25","25","25","25","25"} function is_it_time_to_change() print("time check called") local time = os.date(format_string) print("time: " .. time) Gtime = tonumber(string.sub(time,1,2)) --print("Gtime: " .. Gtime) local counter1 = 1 print(transition_array[4]) while counter1 <= mode+1 do time_array[counter1] = tonumber(string.sub(transition_array[counter1],1,2)) -- print("time in hours: " .. time_array[counter1] .. "time " .. counter1) counter1 = counter1+1 end -- time_array -- print("mode: " .. mode) if mode == 1 then print("we are in mode 2") if time == transition_array[1] then print("change to picture 2 exact time") change_image(path_array[2]) elseif time == transition_array[2] then print("change back to picture 1 exact time") change_image(path_array[1]) else print("do i get here when reloading?") between_times() end elseif mode == 2 then print("we are in mode 3") if time == transition_array[1] then change_image(path_array[2]) elseif time == transition_array[2] then change_image(path_array[3]) elseif time == transition_array[3] then change_image(path_array[1]) else between_times() end elseif mode == 3 then print("we are in mode 4") if time == transition_array[1] then change_image(path_array[2]) elseif time == transition_array[2] then change_image(path_array[3]) elseif time == transition_array[3] then change_image(path_array[4]) elseif time == transition_array[4] then change_image(path_array[1]) else between_times() end elseif mode == 4 then print("we are in mode 5") if time == transition_array[1] then change_image(path_array[2]) elseif time == transition_array[2] then change_image(path_array[3]) elseif time == transition_array[3] then change_image(path_array[4]) elseif time == transition_array[4] then change_image(path_array[5]) elseif time == transition_array[5] then change_image(path_array[1]) else between_times() end end end function between_times() local k = 1 while k <= mode do print("k = " .. k) local type = compare_time(time_array[k], time_array[k+1], Gtime) print("time3: " .. time_array[3]) if type == "out_of_bounds_left" then if k == 1 then change_image(path_array[1]) break else change_image(path_array[k-1]) break end elseif type == "in bounds" then change_image(path_array[k]) break elseif type == "out_of_bounds_right" then if k == 1 then change_image(path_array[k]) elseif k+1 == mode+1 then -- print("this happens when the first one happens again") change_image(path_array[1]) break else -- print("path: " .. k) change_image(path_array[k+1]) end k = k+1 end end end function compare_time(time_one, time_two , Gtime) local type = "" -- print("time_one: " .. time_one .. ", time_two: " .. time_two .. ", Gtime: " .. Gtime) if Gtime > time_one and Gtime < time_two then type = "in bounds" elseif Gtime < time_one and Gtime <= time_two then type = "out_of_bounds_left" else type = "out_of_bounds_right" end print(type) return type end function change_image(path) --print("this is called") local source = obs.obs_get_source_by_name(source_name) --print(source_name) if source ~= nil then local settings = obs.obs_data_create() obs.obs_data_set_string(settings, "file", path) obs.obs_source_update(source, settings) --print(path) print("updated source") obs.obs_data_release(settings) obs.obs_source_release(source) end end function populate_list_property_with_source_names(list_property) local sources = obs.obs_enum_sources() obs.obs_property_list_clear(list_property) obs.obs_property_list_add_string(list_property, "", "") for _,source in pairs(sources) do if obs.obs_source_get_id(source) == "image_source" then local name = obs.obs_source_get_name(source) obs.obs_property_list_add_string(list_property, name, name) end end obs.source_list_release(sources) end function script_properties() local props = obs.obs_properties_create() local p = obs.obs_properties_add_list(props, "source", "Image source", obs.OBS_COMBO_TYPE_EDITABLE, obs.OBS_COMBO_FORMAT_STRING) populate_list_property_with_source_names(p) local g = obslua.obs_properties_add_list(props, "mode", "My list", obslua.OBS_COMBO_TYPE_LIST, obslua.OBS_COMBO_FORMAT_INT) MY_OPTIONS = {"2", "3", "4", "5"} for i,v in ipairs(MY_OPTIONS) do obslua.obs_property_list_add_int(g, v, i) end obs.obs_properties_add_path(props, "path1", "path of picture 1", obs.OBS_PATH_FILE, "Picture (*.png *.jpg *.bmp *.gif", nil) obs.obs_properties_add_text(props, "1to2" , "when to change picture 1 to 2",obs.OBS_TEXT_DEFAULT) obs.obs_properties_add_path(props, "path2", "path of picture 2", obs.OBS_PATH_FILE, "Picture (*.png *.jpg *.bmp *.gif", nil) obs.obs_properties_add_text(props, "2to1" , "when to change picture 2 to 1",obs.OBS_TEXT_DEFAULT) obs.obs_properties_add_text(props, "2to3" , "when to change picture 2 to 3",obs.OBS_TEXT_DEFAULT) obs.obs_properties_add_path(props, "path3", "path of picture 3", obs.OBS_PATH_FILE, "Picture (*.png *.jpg *.bmp *.gif", nil) obs.obs_properties_add_text(props, "3to1" , "when to change picture 3 to 1",obs.OBS_TEXT_DEFAULT) obs.obs_properties_add_text(props, "3to4" , "when to change picture 3 to 4",obs.OBS_TEXT_DEFAULT) obs.obs_properties_add_path(props, "path4", "path of picture 4", obs.OBS_PATH_FILE, "Picture (*.png *.jpg *.bmp *.gif", nil) obs.obs_properties_add_text(props, "4to1" , "when to change picture 4 to 1",obs.OBS_TEXT_DEFAULT) obs.obs_properties_add_text(props, "4to5" , "when to change picture 4 to 5",obs.OBS_TEXT_DEFAULT) obs.obs_properties_add_path(props, "path5", "path of picture 5", obs.OBS_PATH_FILE, "Picture (*.png *.jpg *.bmp *.gif", nil) obs.obs_properties_add_text(props, "5to1" , "when to change picture 5 to 1",obs.OBS_TEXT_DEFAULT) obs.obs_properties_add_button(props, "update_settings", "update settings", is_it_time_to_change) obslua.obs_property_set_visible(obslua.obs_properties_get(props, "path3"), false) obslua.obs_property_set_visible(obslua.obs_properties_get(props, "2to3"), false) obslua.obs_property_set_visible(obslua.obs_properties_get(props, "3to1"), false) obslua.obs_property_set_visible(obslua.obs_properties_get(props, "path4"), false) obslua.obs_property_set_visible(obslua.obs_properties_get(props, "3to4"), false) obslua.obs_property_set_visible(obslua.obs_properties_get(props, "4to1"), false) obslua.obs_property_set_visible(obslua.obs_properties_get(props, "path5"), false) obslua.obs_property_set_visible(obslua.obs_properties_get(props, "4to5"), false) obslua.obs_property_set_visible(obslua.obs_properties_get(props, "5to1"), false) obslua.obs_property_set_modified_callback(g, set_visibility) return props end -- checks for exact time first, then for time frames function script_load(settings) source_name = obs.obs_data_get_string(settings, "source") print("source name:" .. source_name) mode = obslua.obs_data_get_int(settings, "mode") local i =1 -- print("mode in load: " .. mode+1) while (i <= mode+1) do transition_array[i] = obs.obs_data_get_string(settings, (i .. "to" .. i+1)) path_array[i] = obs.obs_data_get_string(settings, "path" .. i) -- print("i in load: " .. i .. " " .. transition_array[i]) i = i+1 end transition_array[i-1] = obs.obs_data_get_string(settings, i-1 .. "to" .. 1) is_it_time_to_change() obs.timer_add(is_it_time_to_change, 50000) end function script_defaults(settings) obs.obs_data_set_default_string(settings, "1to2", "00:00") obs.obs_data_set_default_string(settings, "2to1", "13:37") obs.obs_data_set_default_int(settings, "mode", "2") end -- thanks bfxdev for the callback code which i modified a bit function set_visibility(props, property, settings) -- Retrieves value selected in list mode = obslua.obs_data_get_int(settings, "mode") -- Preset parameters if mode == 1 then obslua.obs_property_set_visible(obslua.obs_properties_get(props, "path1"), true) obslua.obs_property_set_visible(obslua.obs_properties_get(props, "path2"), true) obslua.obs_property_set_visible(obslua.obs_properties_get(props, "1to2"), true) obslua.obs_property_set_visible(obslua.obs_properties_get(props, "2to1"), true) obslua.obs_property_set_visible(obslua.obs_properties_get(props, "path3"), false) obslua.obs_property_set_visible(obslua.obs_properties_get(props, "2to3"), false) obslua.obs_property_set_visible(obslua.obs_properties_get(props, "3to1"), false) obslua.obs_property_set_visible(obslua.obs_properties_get(props, "path4"), false) obslua.obs_property_set_visible(obslua.obs_properties_get(props, "3to4"), false) obslua.obs_property_set_visible(obslua.obs_properties_get(props, "4to1"), false) obslua.obs_property_set_visible(obslua.obs_properties_get(props, "path5"), false) obslua.obs_property_set_visible(obslua.obs_properties_get(props, "4to5"), false) obslua.obs_property_set_visible(obslua.obs_properties_get(props, "5to1"), false) elseif mode == 2 then obslua.obs_property_set_visible(obslua.obs_properties_get(props, "path1"), true) obslua.obs_property_set_visible(obslua.obs_properties_get(props, "path2"), true) obslua.obs_property_set_visible(obslua.obs_properties_get(props, "1to2"), true) obslua.obs_property_set_visible(obslua.obs_properties_get(props, "2to1"), false) obslua.obs_property_set_visible(obslua.obs_properties_get(props, "path3"), true) obslua.obs_property_set_visible(obslua.obs_properties_get(props, "2to3"), true) obslua.obs_property_set_visible(obslua.obs_properties_get(props, "3to1"), true) obslua.obs_property_set_visible(obslua.obs_properties_get(props, "path4"), false) obslua.obs_property_set_visible(obslua.obs_properties_get(props, "3to4"), false) obslua.obs_property_set_visible(obslua.obs_properties_get(props, "4to1"), false) obslua.obs_property_set_visible(obslua.obs_properties_get(props, "path5"), false) obslua.obs_property_set_visible(obslua.obs_properties_get(props, "4to5"), false) obslua.obs_property_set_visible(obslua.obs_properties_get(props, "5to1"), false) elseif mode == 3 then obslua.obs_property_set_visible(obslua.obs_properties_get(props, "path1"), true) obslua.obs_property_set_visible(obslua.obs_properties_get(props, "path2"), true) obslua.obs_property_set_visible(obslua.obs_properties_get(props, "1to2"), true) obslua.obs_property_set_visible(obslua.obs_properties_get(props, "2to1"), false) obslua.obs_property_set_visible(obslua.obs_properties_get(props, "path3"), true) obslua.obs_property_set_visible(obslua.obs_properties_get(props, "2to3"), true) obslua.obs_property_set_visible(obslua.obs_properties_get(props, "3to1"), false) obslua.obs_property_set_visible(obslua.obs_properties_get(props, "path4"), true) obslua.obs_property_set_visible(obslua.obs_properties_get(props, "3to4"), true) obslua.obs_property_set_visible(obslua.obs_properties_get(props, "4to1"), true) obslua.obs_property_set_visible(obslua.obs_properties_get(props, "path5"), false) obslua.obs_property_set_visible(obslua.obs_properties_get(props, "4to5"), false) obslua.obs_property_set_visible(obslua.obs_properties_get(props, "5to1"), false) elseif mode == 4 then obslua.obs_property_set_visible(obslua.obs_properties_get(props, "path1"), true) obslua.obs_property_set_visible(obslua.obs_properties_get(props, "path2"), true) obslua.obs_property_set_visible(obslua.obs_properties_get(props, "1to2"), true) obslua.obs_property_set_visible(obslua.obs_properties_get(props, "2to1"), false) obslua.obs_property_set_visible(obslua.obs_properties_get(props, "path3"), true) obslua.obs_property_set_visible(obslua.obs_properties_get(props, "2to3"), true) obslua.obs_property_set_visible(obslua.obs_properties_get(props, "3to1"), false) obslua.obs_property_set_visible(obslua.obs_properties_get(props, "path4"), true) obslua.obs_property_set_visible(obslua.obs_properties_get(props, "3to4"), true) obslua.obs_property_set_visible(obslua.obs_properties_get(props, "4to1"), false) obslua.obs_property_set_visible(obslua.obs_properties_get(props, "path5"), true) obslua.obs_property_set_visible(obslua.obs_properties_get(props, "4to5"), true) obslua.obs_property_set_visible(obslua.obs_properties_get(props, "5to1"), true) end -- IMPORTANT: returns true to trigger refresh of the properties return true end function script_update(settings) local j = 1 while (j <= mode+1) do transition_array[j] = obs.obs_data_get_string(settings, (j .. "to" .. j+1)) path_array[j] = obs.obs_data_get_string(settings, "path" .. j) j = j+1 end transition_array[j-1] = obs.obs_data_get_string(settings, j-1 .. "to" .. 1) --[[local pic_counter = 1 while pic_counter < (number_of_pictures+1) do transition_array[pic_counter] = obs.obs_data_get_string(settings, text_name_array[pic_counter]) path_array[pic_counter] = obs.obs_data_get_string(settings, path_name_array[pic_counter]) end--]] source_name = obs.obs_data_get_string(settings, "source") --[[ one_to_two= obs.obs_data_get_string(settings, "one_to_two") two_to_one= obs.obs_data_get_string(settings, "two_to_one") path1= obs.obs_data_get_string(settings, "1st_picture") path2= obs.obs_data_get_string(settings, "2nd_picture") --]] end function script_description() return "Lets you switch up to 5 different pictues based on time. times need to be from lowest to highest.\n\nMade by Hukinator" end