obs = obslua -- Version 1.0 -- Define variables for source name, parent scene name, delay time, and hotkey ID source_name = "" parent_scene_name = "" delay_seconds = 5 hotkey_id = obs.OBS_INVALID_HOTKEY_ID -- Description for the script function script_description() return "Activates selected source in the specified parent scene, waits for a specified amount of time, and then deactivates it." end -- This function runs when the script is loaded function script_load(settings) script_update(settings) -- Register the hotkey hotkey_id = obs.obs_hotkey_register_frontend("activate_source_hotkey", "Run Instant Replay", activate_source) local hotkey_save_array = obs.obs_data_get_array(settings, "activate_source_hotkey") obs.obs_hotkey_load(hotkey_id, hotkey_save_array) obs.obs_data_array_release(hotkey_save_array) end -- Update settings from script settings function script_update(settings) source_name = obs.obs_data_get_string(settings, "source_name") or source_name parent_scene_name = obs.obs_data_get_string(settings, "parent_scene_name") or parent_scene_name delay_seconds = obs.obs_data_get_int(settings, "delay_seconds") or delay_seconds end -- Save settings function script_save(settings) obs.obs_data_set_string(settings, "source_name", source_name) obs.obs_data_set_string(settings, "parent_scene_name", parent_scene_name) obs.obs_data_set_int(settings, "delay_seconds", delay_seconds) -- Save hotkey settings local hotkey_save_array = obs.obs_hotkey_save(hotkey_id) obs.obs_data_set_array(settings, "activate_source_hotkey", hotkey_save_array) obs.obs_data_array_release(hotkey_save_array) end -- Activate the source and set up a timer to deactivate it function activate_source(pressed) if not pressed then return end -- Check if the source name and parent scene name are defined if source_name == "" or parent_scene_name == "" then obs.script_log(obs.LOG_ERROR, "Please specify both the source name and the parent scene name.") return end -- Get the parent scene local parent_scene = obs.obs_get_source_by_name(parent_scene_name) if not parent_scene then obs.script_log(obs.LOG_ERROR, "Parent scene not found: " .. parent_scene_name) return end -- Get the scene object local scene = obs.obs_scene_from_source(parent_scene) if not scene then obs.script_log(obs.LOG_ERROR, "Failed to get scene from source.") obs.obs_source_release(parent_scene) return end -- Get the source item in the scene local scene_item = obs.obs_scene_find_source(scene, source_name) if scene_item then obs.obs_sceneitem_set_visible(scene_item, true) -- Set up a timer to deactivate the source after the delay obs.timer_add(deactivate_source, delay_seconds * 1000) -- Delay in milliseconds else obs.script_log(obs.LOG_ERROR, "Source not found: " .. source_name) end -- Release the scene object and parent scene obs.obs_source_release(parent_scene) end -- Deactivate the source function deactivate_source() -- Get the parent scene local parent_scene = obs.obs_get_source_by_name(parent_scene_name) if not parent_scene then obs.script_log(obs.LOG_ERROR, "Parent scene not found: " .. parent_scene_name) return end -- Get the scene object local scene = obs.obs_scene_from_source(parent_scene) if not scene then obs.script_log(obs.LOG_ERROR, "Failed to get scene from source.") obs.obs_source_release(parent_scene) return end -- Get the source item in the scene local scene_item = obs.obs_scene_find_source(scene, source_name) if scene_item then obs.obs_sceneitem_set_visible(scene_item, false) else obs.script_log(obs.LOG_ERROR, "Source not found: " .. source_name) end -- Remove the timer after deactivating the source obs.timer_remove(deactivate_source) -- Release the scene object and parent scene obs.obs_source_release(parent_scene) end -- Script properties UI for inputting source name, parent scene name, and delay time function script_properties() local props = obs.obs_properties_create() -- Create a dropdown for scenes local scene1 = obs.obs_properties_add_list( props, 'parent_scene_name', 'Parent Scene Name', obs.OBS_COMBO_TYPE_EDITABLE, obs.OBS_COMBO_FORMAT_STRING) -- Enumerate all scenes and populate the dropdown local scenes = obs.obs_frontend_get_scenes() -- Use frontend API to get scenes if scenes then for _, scene in ipairs(scenes) do local name = obs.obs_source_get_name(scene) obs.obs_property_list_add_string(scene1, name, name) end end obs.source_list_release(scenes) -- Create a dropdown for sources local source1 = obs.obs_properties_add_list( props, 'source_name', 'Source Name', obs.OBS_COMBO_TYPE_EDITABLE, obs.OBS_COMBO_FORMAT_STRING) local scenes = obs.obs_frontend_get_scenes() -- Use frontend API to get scenes if scenes then for _, scene in ipairs(scenes) do local name = obs.obs_source_get_name(scene) obs.obs_property_list_add_string(source1, name, name) end end local sources1 = obs.obs_enum_sources() if sources1 then for _, source in ipairs(sources1) do local name = obs.obs_source_get_name(source) obs.obs_property_list_add_string(source1, name, name) end end obs.source_list_release(sources1) -- Property to set the delay time in seconds obs.obs_properties_add_int(props, "delay_seconds", "Delay Time (seconds)", 1, 3600, 1) return props end