-- RELOJ DE HUSO HORARIO v1.0 -- ........................... -- Script de OBS STUDIO formato LUA. -- Descripción: Transforma una FUENTE DE TEXTO en un reloj configurable. -- Tan solo debemos poner el nombre de la FUENTE DE TEXTO y automáticamente aparecerá el reloj. -- AUTOR: Basado en un script de Reloj, el código ha sido modificado por la Inteligencia Artificial (perplexity.ia) -- con las indicaciones de juanchoOBS miembro de OBS Studio. obs = obslua hora_inicio = "" source_name = "" datetime_format = "" activated = false HContador = 0 -- Function to set the time text for the hour counter function set_hour_counter_text(source, format) local current_time = os.time() local adjusted_time = current_time + (HContador * 3600) -- Adding hours based on HContador local text = os.date(format, adjusted_time) local settings = obs.obs_data_create() obs.obs_data_set_string(settings, "text", text) obs.obs_source_update(source, settings) obs.obs_data_release(settings) end function timer_callback() local source = obs.obs_get_source_by_name(source_name) if source ~= nil then set_hour_counter_text(source, datetime_format) obs.obs_source_release(source) end end function activate(activating) if activated == activating then return end activated = activating if activating then obs.timer_add(timer_callback, 1000) else obs.timer_remove(timer_callback) end end -- Called when a source is activated/deactivated function activate_signal(cd, activating) local source = obs.calldata_source(cd, "source") if source ~= nil then local name = obs.obs_source_get_name(source) if (name == source_name) then activate(activating) end end end function source_activated(cd) activate_signal(cd, true) end function source_deactivated(cd) activate_signal(cd, false) end function reset() activate(false) local source = obs.obs_get_source_by_name(source_name) if source ~= nil then local active = obs.obs_source_showing(source) obs.obs_source_release(source) activate(active) end end ---------------------------------------------------------- function script_description() return "Crea un contador horario con formato HH:MM:SS y ajuste de inicio basado en un control deslizante." end function script_properties() local props = obs.obs_properties_create() -- Add a slider property for HContador with range -12 to +12 obs.obs_properties_add_int(props, "HContador", "Ajuste de Hora (-12 a +12)", -12, 12, 1) -- Add a text property for datetime format (HH:MM:SS in this case) obs.obs_properties_add_text(props, "format", "Formato Hora Contador", obs.OBS_TEXT_DEFAULT) -- Add a list property for selecting the text source to display the hour counter local p = obs.obs_properties_add_list(props, "source", "Fuente de Texto", obs.OBS_COMBO_TYPE_EDITABLE, obs.OBS_COMBO_FORMAT_STRING) -- Populate the list with compatible text sources local sources = obs.obs_enum_sources() if sources ~= nil then for _, source in ipairs(sources) do source_id = obs.obs_source_get_id(source) if source_id == "text_gdiplus" or source_id == "text_ft2_source" then local name = obs.obs_source_get_name(source) obs.obs_property_list_add_string(p, name, name) end end end obs.source_list_release(sources) return props end function script_defaults(settings) obs.obs_data_set_default_string(settings, "format", "%H:%M:%S") end function script_update(settings) activate(false) source_name = obs.obs_data_get_string(settings, "source") datetime_format = obs.obs_data_get_string(settings, "format") HContador = obs.obs_data_get_int(settings, "HContador") reset() end function script_load(settings) local sh = obs.obs_get_signal_handler() obs.signal_handler_connect(sh, "source_show", source_activated) obs.signal_handler_connect(sh, "source_hide", source_deactivated) end