### Example Usage of Multi-pane Choose Option Dialog Source: https://sims4communitylibrary.readthedocs.io/en/latest/sims4communitylib.dialogs.option_dialogs.options.multi_pane.html Demonstrates the setup for a multi-pane choose option dialog, including callback functions for option selection and dialog submission. This example illustrates how to define handlers for individual dialogs and the overall dialog submission. ```python def _on_option_chosen_in_dialog_one(option_identifier: str, choice: str): pass def _on_option_chosen_in_dialog_two(option_identifier: str, choice: str): pass def _on_submit(chosen_options: Dict[int, Any]): pass ``` -------------------------------- ### Setup ASM Default Source: https://sims4communitylibrary.readthedocs.io/en/latest/sims4communitylib.classes.interactions.html A function that occurs when setting up the Animation State Machine. Returns true if setup is proper, false otherwise. ```python setup_asm_default(_asm_ , _*args_ , _**kwargs_) A function that occurs when setting up the Animation State Machine. Parameters:| **asm** (_NativeAsm_) – An instance of the Animation State Machine ---|--- Returns:| True, if the ASM was setup properly. False, if not. Return type:| bool ``` -------------------------------- ### Example Usage of Premade Choose Sim Option Dialog Source: https://sims4communitylibrary.readthedocs.io/en/latest/sims4communitylib.dialogs.premade_dialogs.html Demonstrates how to use the CommonPremadeChooseSimOptionDialog to prompt the player to select a Sim. This example shows how to set localized string tokens for the title and description. ```python from sims4communitylib.dialogs.option_dialogs.common_choose_sim_option_dialog import CommonPremadeChooseSimOptionDialog from sims4communitylib.utils.common_function_utils import CommonFunctionUtils from sims4communitylib.utils.localization.common_localization_utils import CommonLocalizationUtils from sims4communitylib.enums.strings_enum import CommonStringId from sims4communitylib.utils.sims.common_sim_utils import CommonSimUtils from sims4communitylib.utils.localization.common_localization_utils import CommonLocalizedStringColor def _on_chosen(_sim_info): pass # LocalizedStrings within other LocalizedStrings title_tokens = ( CommonLocalizationUtils.create_localized_string( CommonStringId.TESTING_SOME_TEXT_FOR_TESTING, text_color=CommonLocalizedStringColor.GREEN ), ) description_tokens = ( CommonLocalizationUtils.create_localized_string( CommonStringId.TESTING_TEST_TEXT_WITH_SIM_FIRST_AND_LAST_NAME, tokens=(CommonSimUtils.get_active_sim_info(),), text_color=CommonLocalizedStringColor.BLUE ), ) # Example of instantiating the dialog # CommonPremadeChooseSimOptionDialog( # title_identifier=CommonStringId.TESTING_SOME_TEXT_FOR_TESTING, # description_identifier=CommonStringId.TESTING_TEST_TEXT, # title_tokens=title_tokens, # description_tokens=description_tokens, # on_close=CommonFunctionUtils.noop, # include_sim_callback=None, # Optional: Filter Sims # instanced_sims_only=True, # Optional: Only show instanced Sims # on_sim_chosen=_on_chosen # ) ``` -------------------------------- ### Show Targeted Question Dialog Example Source: https://sims4communitylibrary.readthedocs.io/en/latest/sims4communitylib.dialogs.basic_dialogs.html Demonstrates how to create and display a targeted question dialog. This example shows how to format localized strings with tokens, including Sim information, and how to handle OK and Cancel button selections. ```Python def _common_testing_show_targeted_question_dialog(): def _ok_chosen(_: UiDialogOkCancel): pass def _cancel_chosen(_: UiDialogOkCancel): pass # LocalizedStrings within other LocalizedStrings description_tokens = (CommonLocalizationUtils.create_localized_string(CommonStringId.TESTING_TEST_TEXT_WITH_SIM_FIRST_AND_LAST_NAME, tokens=(CommonSimUtils.get_active_sim_info(),), text_color=CommonLocalizedStringColor.BLUE),) dialog = CommonTargetedQuestionDialog( CommonStringId.TESTING_TEST_TEXT_WITH_STRING_TOKEN, question_tokens=description_tokens, ok_text_identifier=CommonLocalizationUtils.create_localized_string(CommonStringId.TESTING_TEST_BUTTON_ONE, text_color=CommonLocalizedStringColor.RED), cancel_text_identifier=CommonStringId.TESTING_TEST_BUTTON_TWO ) dialog.show( CommonSimUtils.get_active_sim_info(), tuple(CommonSimUtils.get_sim_info_for_all_sims_generator())[0], on_ok_selected=_ok_chosen, on_cancel_selected=_cancel_chosen ) ``` -------------------------------- ### Show Input Text Dialog Example Source: https://sims4communitylibrary.readthedocs.io/en/latest/sims4communitylib.dialogs.basic_dialogs.html Demonstrates how to create and display a CommonInputTextDialog. This example shows how to format title and description tokens, including localized strings and Sim information. The dialog is displayed using the show method, with a callback for when the player submits a value. ```Python def _common_testing_show_input_text_dialog(): def _on_submit(input_value: str, outcome: CommonChoiceOutcome): pass # LocalizedStrings within other LocalizedStrings title_tokens = (CommonLocalizationUtils.create_localized_string(CommonStringId.TESTING_SOME_TEXT_FOR_TESTING, text_color=CommonLocalizedStringColor.GREEN),) description_tokens = (CommonLocalizationUtils.create_localized_string(CommonStringId.TESTING_TEST_TEXT_WITH_SIM_FIRST_AND_LAST_NAME, tokens=(CommonSimUtils.get_active_sim_info(),), text_color=CommonLocalizedStringColor.BLUE),) from sims4communitylib.utils.common_icon_utils import CommonIconUtils dialog = CommonInputTextDialog( ModInfo.get_identity(), CommonStringId.TESTING_TEST_TEXT_WITH_STRING_TOKEN, CommonStringId.TESTING_TEST_TEXT_WITH_STRING_TOKEN, 'default_text', title_tokens=title_tokens, description_tokens=description_tokens ) dialog.show(on_submit=_on_submit) ``` -------------------------------- ### Show Object Picker Dialog Example Source: https://sims4communitylibrary.readthedocs.io/en/latest/sims4communitylib.dialogs.basic_dialogs.html Demonstrates how to create and display a dialog prompting the player to choose an object. This example includes localized strings for the title and description, custom row options with icons, and pagination settings. It also shows how to handle the player's choice. ```Python def _common_testing_show_choose_object_dialog(): def _on_chosen(choice: str, outcome: CommonChoiceOutcome): pass # LocalizedStrings within other LocalizedStrings title_tokens = (CommonLocalizationUtils.create_localized_string(CommonStringId.TESTING_SOME_TEXT_FOR_TESTING, text_color=CommonLocalizedStringColor.GREEN),) description_tokens = (CommonLocalizationUtils.create_localized_string(CommonStringId.TESTING_TEST_TEXT_WITH_SIM_FIRST_AND_LAST_NAME, tokens=(CommonSimUtils.get_active_sim_info(),), text_color=CommonLocalizedStringColor.BLUE),) from sims4communitylib.utils.common_icon_utils import CommonIconUtils options = [ ObjectPickerRow( option_id=1, name=CommonLocalizationUtils.create_localized_string(CommonStringId.TESTING_SOME_TEXT_FOR_TESTING), row_description=CommonLocalizationUtils.create_localized_string(CommonStringId.TESTING_TEST_BUTTON_ONE), row_tooltip=None, icon=CommonIconUtils.load_checked_square_icon(), tag='Value 1' ), ObjectPickerRow( option_id=2, name=CommonLocalizationUtils.create_localized_string(CommonStringId.TESTING_SOME_TEXT_FOR_TESTING), row_description=CommonLocalizationUtils.create_localized_string(CommonStringId.TESTING_TEST_BUTTON_TWO), row_tooltip=None, icon=CommonIconUtils.load_arrow_navigate_into_icon(), tag='Value 2' ), ObjectPickerRow( option_id=3, name=CommonLocalizationUtils.create_localized_string('Value 3'), row_description=CommonLocalizationUtils.create_localized_string(CommonStringId.TESTING_TEST_BUTTON_TWO), row_tooltip=None, icon=CommonIconUtils.load_arrow_navigate_into_icon(), tag='Value 3' ) ] dialog = CommonChooseObjectDialog( CommonStringId.TESTING_TEST_TEXT_WITH_STRING_TOKEN, CommonStringId.TESTING_TEST_TEXT_WITH_STRING_TOKEN, tuple(options), title_tokens=title_tokens, description_tokens=description_tokens, per_page=2 ) dialog.show(on_chosen=_on_chosen) ``` -------------------------------- ### Example Usage of CommonChooseSimsOptionDialog Source: https://sims4communitylibrary.readthedocs.io/en/latest/sims4communitylib.dialogs.option_dialogs.options.sims.html This is an example of how to use the CommonChooseSimsOptionDialog. It defines a callback function `_on_submit` that will receive a list of selected SimInfo objects when the dialog is confirmed. ```python def _on_submit(sim_info_list: Tuple[SimInfo]): pass ``` -------------------------------- ### Animation State Machine Setup Source: https://sims4communitylibrary.readthedocs.io/en/latest/sims4communitylib.classes.interactions.html Demonstrates the setup_asm_default method for initializing the Animation State Machine (ASM) for an interaction. ```python def setup_asm_default(self, asm: NativeAsm, *args, **kwargs) -> bool: # A function that occurs when setting up the Animation State Machine. # Parameters:| **asm** (_NativeAsm_) – An instance of the Animation State Machine # Returns:| True, if the ASM was setup properly. False, if not. # Return type:| bool ``` -------------------------------- ### Implement a Singleton Service with CommonService Source: https://sims4communitylibrary.readthedocs.io/en/latest/sims4communitylib.services.html Inherit from CommonService to create a singleton service. Instances are retrieved by calling the get() class method. Subsequent calls to get() return the same instance. ```python class ExampleService(CommonService): @property def first_value(self) -> str: return 'yes' # ExampleService.get() returns an instance of ExampleService. # Calling ExampleService.get() again, will return the same instance. ExampleService.get().first_value ``` -------------------------------- ### Example Sim Data Storage Implementation Source: https://sims4communitylibrary.readthedocs.io/en/latest/sims4communitylib.persistence.html Inherit from CommonPersistedSimDataStorage to create custom Sim data persistence. Override get_mod_identity to return your mod's identity. Example properties can be managed using get_data and set_data. ```python class ExamplePersistedSimDataStorage(CommonPersistedSimDataStorage): @classmethod def get_mod_identity(cls) -> CommonModIdentity: # !!!Override with the CommonModIdentity of your own mod!!! from sims4communitylib.modinfo import ModInfo return ModInfo.get_identity() @property def example_property_one(self) -> bool: # Could also be written self.get_data(default=False, key='example_property_one') and it would do the same thing. return self.get_data(default=False) @example_property_one.setter def example_property_one(self, value: bool): # Could also be written self.set_data(value, key='example_property_one') and it would do the same thing. self.set_data(value) ``` -------------------------------- ### Example of CommonChooseResponseDialog Source: https://sims4communitylibrary.readthedocs.io/en/latest/sims4communitylib.dialogs.basic_dialogs.html This function demonstrates how to create and display a CommonChooseResponseDialog. It defines responses, title and description tokens, and then shows the dialog to the player. To run this example, use the in-game console command 's4clib_testing.show_choose_response_dialog'. ```Python def _common_testing_show_choose_response_dialog(): def _on_chosen(choice: str, outcome: CommonChoiceOutcome): pass responses: Tuple[CommonUiDialogResponse] = ( CommonUiDialogResponse( 1, 'Value 1', text=CommonLocalizationUtils.create_localized_string(CommonStringId.TESTING_TEST_BUTTON_ONE) ), CommonUiDialogResponse( 2, 'Value 2', text=CommonLocalizationUtils.create_localized_string(CommonStringId.TESTING_TEST_BUTTON_TWO) ), CommonUiDialogResponse( 3, 'Value 3', text=CommonLocalizationUtils.create_localized_string('Test Button 3') ) ) title_tokens = (CommonLocalizationUtils.create_localized_string(CommonStringId.TESTING_SOME_TEXT_FOR_TESTING, text_color=CommonLocalizedStringColor.GREEN),) description_tokens = (CommonLocalizationUtils.create_localized_string(CommonStringId.TESTING_TEST_TEXT_WITH_SIM_FIRST_AND_LAST_NAME, tokens=(CommonSimUtils.get_active_sim_info(),), text_color=CommonLocalizedStringColor.BLUE),) active_sim_info = CommonSimUtils.get_active_sim_info() dialog = CommonChooseResponseDialog( ModInfo.get_identity(), CommonStringId.TESTING_TEST_TEXT_WITH_STRING_TOKEN, CommonStringId.TESTING_TEST_TEXT_WITH_STRING_TOKEN, responses, title_tokens=title_tokens, description_tokens=description_tokens, per_page=2 ) dialog.show( on_chosen=_on_chosen, sim_info=active_sim_info, include_previous_button=False ) ``` -------------------------------- ### Interaction Execution Logic Source: https://sims4communitylibrary.readthedocs.io/en/latest/sims4communitylib.classes.interactions.html Provides an example of the on_started method for defining the primary action of an interaction when it is initiated. ```python def on_started(self, interaction_sim: Sim, interaction_target: Any) -> CommonExecutionResult: result = True if not result: return CommonExecutionResult.FALSE # Put here what you want the interaction to do as soon as the player clicks it while it is enabled. return CommonExecutionResult.TRUE ``` -------------------------------- ### Custom Object Interaction Example Source: https://sims4communitylibrary.readthedocs.io/en/latest/sims4communitylib.classes.interactions.html Example of creating a custom object interaction by inheriting from `CommonObjectInteraction`. Shows how to implement `on_test` for conditional display and `on_started` for the interaction's core functionality. ```python class _ExampleObjectInteraction(CommonObjectInteraction): @classmethod def on_test(cls, interaction_sim: Sim, interaction_target: Any, interaction_context: InteractionContext, **kwargs) -> CommonTestResult: result = 1 + 1 if result == 2: # Interaction will be displayed, but disabled, it will also have a tooltip that displays on hover with the text "Test Tooltip" return cls.create_test_result(False, reason="Test Tooltip") # Alternative way to specify a tooltip with the text "Test Tooltip" # return cls.create_test_result(False, reason="No Reason", tooltip=CommonLocalizationUtils.create_localized_tooltip("Test Tooltip")) if result == 3: # Interaction will be hidden completely. return CommonTestResult.NONE # Interaction will display and be enabled. return CommonTestResult.TRUE def on_started(self, interaction_sim: Sim, interaction_target: Any) -> CommonExecutionResult: result = True if not result: return CommonExecutionResult.FALSE # Put here what you want the interaction to do as soon as the player clicks it while it is enabled. return CommonExecutionResult.TRUE ``` -------------------------------- ### Example: Apply Bare Feet Appearance Modifier Source: https://sims4communitylibrary.readthedocs.io/en/latest/sims4communitylib.classes.buffs.html This example demonstrates how to create a custom appearance modifier to attach 'bare feet' CAS parts to Sims. It handles different ages, genders, and species (human, dog, cat, fox). ```python class CommonExampleApplyBareFeetAppearanceModifier(AppearanceModifier): class CommonAttachBareFeetModifier(CommonAttachCASPartsAppearanceModifier): # noinspection PyMissingOrEmptyDocstring @property def mod_identity(self) -> CommonModIdentity: return ModInfo.get_identity() # noinspection PyMissingOrEmptyDocstring @property def log_identifier(self) -> str: return 'common_example_apply_bare_feet' def _get_cas_parts( self, source_sim_info: SimInfo, modified_sim_info: SimInfo, original_unmodified_sim_info: SimInfo, random_seed: int ) -> Tuple[CommonCASPart]: # Human # yfShoes_Nude adult_human_female_bare_feet_id = 6543 # ymShoes_Nude adult_human_male_bare_feet_id = 6563 # cuShoes_Nude child_human_bare_feet_id = 22018 # puShoes_Nude toddler_human_bare_feet_id = 132818 # Dog # adShoes_Nude adult_large_dog_bare_feet_id = 125251 # alShoes_Nude adult_small_dog_bare_feet_id = 148839 # cdShoes_Nude child_dog_bare_feet_id = 158046 # Cat # acShoes_Nude adult_cat_bare_feet_id = 150367 # ccShoes_Nude child_cat_bare_feet_id = 164111 # Fox adult_fox_bare_feet_id = 277492 bare_feet_cas_part_id = None if CommonAgeUtils.is_teen_adult_or_elder(original_unmodified_sim_info): if CommonSpeciesUtils.is_human(original_unmodified_sim_info): if CommonGenderUtils.is_female(original_unmodified_sim_info): bare_feet_cas_part_id = adult_human_female_bare_feet_id elif CommonGenderUtils.is_male(original_unmodified_sim_info): bare_feet_cas_part_id = adult_human_male_bare_feet_id elif CommonSpeciesUtils.is_large_dog(original_unmodified_sim_info): bare_feet_cas_part_id = adult_large_dog_bare_feet_id elif CommonSpeciesUtils.is_small_dog(original_unmodified_sim_info): bare_feet_cas_part_id = adult_small_dog_bare_feet_id elif CommonSpeciesUtils.is_cat(original_unmodified_sim_info): bare_feet_cas_part_id = adult_cat_bare_feet_id elif CommonSpeciesUtils.is_fox(original_unmodified_sim_info): bare_feet_cas_part_id = adult_fox_bare_feet_id elif CommonAgeUtils.is_child(original_unmodified_sim_info): if CommonSpeciesUtils.is_human(original_unmodified_sim_info): bare_feet_cas_part_id = child_human_bare_feet_id elif CommonSpeciesUtils.is_large_dog(original_unmodified_sim_info) or CommonSpeciesUtils.is_small_dog(original_unmodified_sim_info): bare_feet_cas_part_id = child_dog_bare_feet_id elif CommonSpeciesUtils.is_cat(original_unmodified_sim_info): bare_feet_cas_part_id = child_cat_bare_feet_id elif CommonAgeUtils.is_toddler(original_unmodified_sim_info): bare_feet_cas_part_id = toddler_human_bare_feet_id if bare_feet_cas_part_id is None: return tuple() return CommonCASPart(bare_feet_cas_part_id, CommonCASUtils.get_body_type_of_cas_part(bare_feet_cas_part_id)), # We override the original "appearance_modifiers" to so we can insert our custom appearance modifier. FACTORY_TUNABLES = { 'appearance_modifiers': TunableList( description=' The specific appearance modifiers to use for this buff. ', tunable=TunableList( description=' A tunable list of weighted modifiers. When applying modifiers one of the modifiers in this list will be applied. The weight will be used to run a weighted random selection. ', tunable=TunableTuple( ``` -------------------------------- ### Load All Instances as GUID to Instance Map Source: https://sims4communitylibrary.readthedocs.io/en/latest/sims4communitylib.utils.resources.html Loads all instances of a specified type and organizes them into a dictionary where keys are the instance GUIDs and values are the instance objects. This is efficient for direct access by ID. ```python all_mood_guids = CommonResourceUtils.load_all_instances_as_guid_to_instance(Types.MOOD) ``` -------------------------------- ### Example Interaction with Conditional Testing Source: https://sims4communitylibrary.readthedocs.io/en/latest/sims4communitylib.classes.interactions.html This example demonstrates how to control an interaction's visibility, enabled state, and tooltip based on test conditions. It shows how to return specific results from the on_test method to achieve different outcomes. ```python class _ExampleInteraction(CommonSocialSuperInteraction): @classmethod def on_test(cls, interaction_sim: Sim, interaction_target: Any, interaction_context: InteractionContext, interaction=None, **kwargs) -> TestResult: result = 1 + 1 if result == 2: # Interaction will be displayed, but disabled, it will also have a tooltip that displays on hover with the text "Test Tooltip" return cls.create_test_result(False, reason="Test Tooltip") # Alternative way to specify a tooltip with the text "Test Tooltip" # return cls.create_test_result(False, reason="No Reason", tooltip=CommonLocalizationUtils.create_localized_tooltip("Test Tooltip")) if result == 3: # Interaction will be hidden completely. return CommonTestResult.NONE # Interaction will display and be enabled. return CommonTestResult.TRUE # Instead of on_started, SocialSuperInteractions use on_run. def on_run(self, interaction_sim: Sim, interaction_target: Any, timeline: Timeline) -> bool: result = True if not result: return False # Put here what you want the interaction to do as soon as the player clicks it while it is enabled. return True def on_cancelled(self, interaction_sim: Sim, interaction_target: Any, finishing_type: FinishingType, cancel_reason_msg: str, **kwargs): result = True if not result: return False # Put here what you want the interaction to do as soon as the player clicks it while it is enabled. return True ``` -------------------------------- ### Listen to S4CLSimInitializedEvent Source: https://sims4communitylibrary.readthedocs.io/en/latest/sims4communitylib.events.sim.events.html Example of how to register a listener for the S4CLSimInitializedEvent. This event occurs after a Sim has been initialized. ```python from sims4communitylib.events.event_handling.common_event_registry import CommonEventRegistry from sims4communitylib.modinfo import ModInfo class ExampleEventListener: # In order to listen to an event, your function must match these criteria: # - The function is static (staticmethod). # - The first and only required argument has the name "event_data". # - The first and only required argument has the Type Hint for the event you are listening for. # - The argument passed to "handle_events" is the name of your Mod. @staticmethod @CommonEventRegistry.handle_events(ModInfo.get_identity().name) def handle_event(event_data: S4CLSimInitializedEvent): pass ``` -------------------------------- ### load_all_instances_as_guid_to_instance Source: https://sims4communitylibrary.readthedocs.io/en/latest/sims4communitylib.utils.resources.html Loads all instances of a specified type and returns a dictionary mapping GUID to instance. ```APIDOC ## load_all_instances_as_guid_to_instance ### Description Loads all instances of the specified type and converts it to a dictionary mapping of GUID to Instance. ### Parameters #### Path Parameters - **instance_type** (Types) - The type of instances being loaded. - **return_type** (Type[CommonExpectedReturnType], optional) - The type of the returned value. Defaults to Any. ### Returns A dictionary of instance GUID to instances of the specified type. ### Return Type Dict[int, Any] ``` -------------------------------- ### Custom Terrain Interaction Example Source: https://sims4communitylibrary.readthedocs.io/en/latest/sims4communitylib.classes.interactions.html Example of creating a custom terrain interaction by inheriting from `CommonTerrainInteraction`. Demonstrates how to use `on_test` to control interaction visibility and tooltips, and `on_started` to define the interaction's execution logic. ```python class _ExampleTerrainInteraction(CommonTerrainInteraction): @classmethod def on_test(cls, interaction_sim: Sim, interaction_target: Any, interaction_context: InteractionContext, **kwargs) -> CommonTestResult: result = 1 + 1 if result == 2: # Interaction will be displayed, but disabled, it will also have a tooltip that displays on hover with the text "Test Tooltip" return cls.create_test_result(False, reason="Test Tooltip") # Alternative way to specify a tooltip with the text "Test Tooltip" # return cls.create_test_result(False, reason="No Reason", tooltip=CommonLocalizationUtils.create_localized_tooltip("Test Tooltip")) if result == 3: # Interaction will be hidden completely. return CommonTestResult.NONE # Interaction will display and be enabled. return CommonTestResult.TRUE def on_started(self, interaction_sim: Sim, interaction_target: Any) -> CommonExecutionResult: result = True if not result: return CommonExecutionResult.FALSE # Put here what you want the interaction to do as soon as the player clicks it while it is enabled. return CommonExecutionResult.TRUE ``` -------------------------------- ### Listen to S4CLSimAfterSetCurrentOutfitEvent Source: https://sims4communitylibrary.readthedocs.io/en/latest/sims4communitylib.events.sim.events.html Example of how to register a listener for the S4CLSimAfterSetCurrentOutfitEvent. This event occurs after a Sim's outfit has been set. ```python from sims4communitylib.events.event_handling.common_event_registry import CommonEventRegistry from sims4communitylib.modinfo import ModInfo class ExampleEventListener: # In order to listen to an event, your function must match these criteria: # - The function is static (staticmethod). # - The first and only required argument has the name "event_data". # - The first and only required argument has the Type Hint for the event you are listening for. # - The argument passed to "handle_events" is the name of your Mod. @staticmethod @CommonEventRegistry.handle_events(ModInfo.get_identity().name) def handle_event(event_data: S4CLSimAfterSetCurrentOutfitEvent): pass ``` -------------------------------- ### Example Console Command Registration Source: https://sims4communitylibrary.readthedocs.io/en/latest/sims4communitylib.services.commands.html Register a new console command with aliases and arguments. This command prints a provided message to the console. ```python from sims4communitylib.services.commands.common_console_command import CommonConsoleCommand from sims4communitylib.utils.common_log_utils import Output from sims4communitylib.services.commands.common_console_command_argument import CommonConsoleCommandArgument from sims4communitylib.enums.common_enums import CommandType, CommandRestrictionFlags @CommonConsoleCommand(ModInfo.get_identity(), 's4clib_testing.example_command', 'Print an example message', command_aliases=('s4clib_testing.examplecommand',), command_arguments=(CommonConsoleCommandArgument('thing_to_print', 'Text or Num', 'If specified, this value will be printed to the console. Default is "24".'),)) def _common_testing_do_example_command(output: Output, thing_to_print: str='24'): output(f'Here is what to print: {thing_to_print}') ``` -------------------------------- ### Listen to S4CLSimSetCurrentOutfitEvent Source: https://sims4communitylibrary.readthedocs.io/en/latest/sims4communitylib.events.sim.events.html Example of how to register a listener for the S4CLSimSetCurrentOutfitEvent. This event occurs before a Sim's outfit is actually set. ```python from sims4communitylib.events.event_handling.common_event_registry import CommonEventRegistry from sims4communitylib.modinfo import ModInfo class ExampleEventListener: # In order to listen to an event, your function must match these criteria: # - The function is static (staticmethod). # - The first and only required argument has the name "event_data". # - The first and only required argument has the Type Hint for the event you are listening for. # - The argument passed to "handle_events" is the name of your Mod. @staticmethod @CommonEventRegistry.handle_events(ModInfo.get_identity().name) def handle_event(event_data: S4CLSimSetCurrentOutfitEvent): pass ``` -------------------------------- ### Listen for Sim Changed Breasts Event Source: https://sims4communitylibrary.readthedocs.io/en/latest/sims4communitylib.events.sim.events.html Example of how to set up a listener for the S4CLSimChangedGenderOptionsBreastsEvent. Ensure your listener function is static and correctly typed. ```python from sims4communitylib.events.event_handling.common_event_registry import CommonEventRegistry from sims4communitylib.modinfo import ModInfo class ExampleEventListener: # In order to listen to an event, your function must match these criteria: # - The function is static (staticmethod). # - The first and only required argument has the name "event_data". # - The first and only required argument has the Type Hint for the event you are listening for. # - The argument passed to "handle_events" is the name of your Mod. @staticmethod @CommonEventRegistry.handle_events(ModInfo.get_identity()) def handle_event(event_data: S4CLSimChangedGenderOptionsBreastsEvent): pass ``` -------------------------------- ### Listen to S4CLZoneLateLoadEvent Source: https://sims4communitylibrary.readthedocs.io/en/latest/sims4communitylib.events.zone_spin.events.html Example of how to register a listener for the S4CLZoneLateLoadEvent. Listener functions must be static and correctly typed to receive event data. ```python from sims4communitylib.events.event_handling.common_event_registry import CommonEventRegistry from sims4communitylib.modinfo import ModInfo class ExampleEventListener: # In order to listen to an event, your function must match these criteria: # - The function is static (staticmethod). # - The first and only required argument has the name "event_data". # - The first and only required argument has the Type Hint for the event you are listening for. # - The argument passed to "handle_events" is the name of your Mod. @staticmethod @CommonEventRegistry.handle_events(ModInfo.get_identity().name) def handle_event(event_data: S4CLZoneLateLoadEvent): pass ``` -------------------------------- ### CommonTargetedQuestionDialog Source: https://sims4communitylibrary.readthedocs.io/en/latest/sims4communitylib.dialogs.basic_dialogs.html A Sim to Sim question dialog. To see an example dialog, run the command s4clib_testing.show_targeted_questionDialog in the in-game console. ```APIDOC ## class CommonTargetedQuestionDialog(question_text, question_tokens=(), ok_text_identifier=CommonStringId.OK, ok_text_tokens=(), cancel_text_identifier=CommonStringId.CANCEL, cancel_text_tokens=(), mod_identity=None) ### Description A Sim to Sim question dialog. ### Parameters * **question_text** (Union[int, str, LocalizedString, CommonStringId]) - A decimal identifier of the question text. * **question_tokens** (Iterator[Any], optional) - Tokens to format into the question text. * **ok_text_identifier** (Union[int, str, LocalizedString, CommonStringId], optional) - A decimal identifier for the Ok text. * **ok_text_tokens** (Iterator[Any], optional) - Tokens to format into the Ok text. * **cancel_text_identifier** (Union[int, str, LocalizedString, CommonStringId], optional) - A decimal identifier for the Cancel text. * **cancel_text_tokens** (Iterator[Any], optional) - Tokens to format into the Cancel text. * **mod_identity** (CommonModIdentity, optional) - The identity of the mod creating the dialog. ## show(sim_info, target_sim_info, on_ok_selected=CommonFunctionUtils.noop, on_cancel_selected=CommonFunctionUtils.noop) ### Description Show the dialog and invoke the callbacks upon the player making a choice. ### Parameters * **sim_info** (SimInfo) - The Sim that is the source of the question. * **target_sim_info** (SimInfo) - The Sim that is the target of the question. * **on_ok_selected** (Callable[[UiDialogOkCancel, Any]], optional) - Invoked upon the player clicking the Ok button in the dialog. * **on_cancel_selected** (Callable[[UiDialogOkCancel, Any]], optional) - Invoked upon the player clicking the Cancel button in the dialog. ``` -------------------------------- ### Listen to S4CLSaveLoadedEvent Source: https://sims4communitylibrary.readthedocs.io/en/latest/sims4communitylib.events.save.events.html Example of how to register a static method to listen for the S4CLSaveLoadedEvent. Ensure the listener function is static and correctly typed. ```python from sims4communitylib.events.event_handling.common_event_registry import CommonEventRegistry from sims4communitylib.modinfo import ModInfo class ExampleEventListener: # In order to listen to an event, your function must match these criteria: # - The function is static (staticmethod). # - The first and only required argument has the name "event_data". # - The first and only required argument has the Type Hint for the event you are listening for. # - The argument passed to "handle_events" is the name of your Mod. @staticmethod @CommonEventRegistry.handle_events(ModInfo.get_identity().name) def handle_event(event_data: S4CLSaveLoadedEvent): pass ``` -------------------------------- ### Listen for Sim Revived Event Source: https://sims4communitylibrary.readthedocs.io/en/latest/sims4communitylib.events.sim.events.html Example of how to set up a static method to listen for the S4CLSimRevivedEvent. Ensure your ModInfo is correctly passed to handle_events. ```python from sims4communitylib.events.event_handling.common_event_registry import CommonEventRegistry from sims4communitylib.modinfo import ModInfo class ExampleEventListener: # In order to listen to an event, your function must match these criteria: # - The function is static (staticmethod). # - The first and only required argument has the name "event_data". # - The first and only required argument has the Type Hint for the event you are listening for. # - The argument passed to "handle_events" is the name of your Mod. @staticmethod @CommonEventRegistry.handle_events(ModInfo.get_identity().name) def handle_event(event_data: S4CLSimRevivedEvent): pass ``` -------------------------------- ### Show Input Integer Dialog Example Source: https://sims4communitylibrary.readthedocs.io/en/latest/sims4communitylib.dialogs.basic_dialogs.html Demonstrates how to create and display a dialog that prompts the player to enter an integer value. Includes setting title and description tokens with localized strings and Sim information. ```Python def _common_testing_show_input_integer_dialog(): def _on_submit(input_value: integer, outcome: CommonChoiceOutcome): pass # LocalizedStrings within other LocalizedStrings title_tokens = (CommonLocalizationUtils.create_localized_string(CommonStringId.TESTING_SOME_TEXT_FOR_TESTING, text_color=CommonLocalizedStringColor.GREEN),) description_tokens = (CommonLocalizationUtils.create_localized_string(CommonStringId.TESTING_TEST_TEXT_WITH_SIM_FIRST_AND_LAST_NAME, tokens=(CommonSimUtils.get_active_sim_info(),), text_color=CommonLocalizedStringColor.BLUE),) from sims4communitylib.utils.common_icon_utils import CommonIconUtils dialog = CommonInputFloatDialog( CommonStringId.TESTING_TEST_TEXT_WITH_STRING_TOKEN, CommonStringId.TESTING_TEST_TEXT_WITH_STRING_TOKEN, 2, title_tokens=title_tokens, description_tokens=description_tokens ) dialog.show(on_submit=_on_submit) ``` -------------------------------- ### get_time_service Source: https://sims4communitylibrary.readthedocs.io/en/latest/sims4communitylib.utils.time.html Get an instance of the TimeService. ```APIDOC ## get_time_service ### Description Get an instance of the TimeService. ### Returns - **TimeService** - An instance of the Time Service. ``` -------------------------------- ### get_game_clock Source: https://sims4communitylibrary.readthedocs.io/en/latest/sims4communitylib.utils.time.html Get an instance of the GameClock. ```APIDOC ## get_game_clock ### Description Get an instance of the GameClock. ### Returns - **GameClock** - An instance of the game clock. ``` -------------------------------- ### Registering a Build/Buy Enter Event Listener Source: https://sims4communitylibrary.readthedocs.io/en/latest/sims4communitylib.events.build_buy.events.html Example of how to register a static method to listen for the S4CLBuildBuyEnterEvent. Ensure the listener function is static and the event_data argument is type-hinted correctly. ```python from sims4communitylib.events.event_handling.common_event_registry import CommonEventRegistry from sims4communitylib.modinfo import ModInfo class ExampleEventListener: # In order to listen to an event, your function must match these criteria: # - The function is static (staticmethod). # - The first and only required argument has the name "event_data". # - The first and only required argument has the Type Hint for the event you are listening for. # - The argument passed to "handle_events" is the name of your Mod. @staticmethod @CommonEventRegistry.handle_events(ModInfo.get_identity().name) def handle_event(event_data: S4CLBuildBuyEnterEvent): pass ``` -------------------------------- ### Create and Show a Choose Sim Dialog Source: https://sims4communitylibrary.readthedocs.io/en/latest/sims4communitylib.dialogs.basic_dialogs.html This example demonstrates how to create and display a CommonChooseSimDialog. It includes setting up localized strings for the title and description, populating the dialog with Sim options, and defining a callback function to handle the player's choice. ```Python def _common_testing_show_choose_sim_dialog(): def _on_chosen(choice: Union[SimInfo, None], outcome: CommonChoiceOutcome): pass # LocalizedStrings within other LocalizedStrings title_tokens = (CommonLocalizationUtils.create_localized_string(CommonStringId.TESTING_SOME_TEXT_FOR_TESTING, text_color=CommonLocalizedStringColor.GREEN),) description_tokens = (CommonLocalizationUtils.create_localized_string(CommonStringId.TESTING_TEST_TEXT_WITH_SIM_FIRST_AND_LAST_NAME, tokens=(CommonSimUtils.get_active_sim_info(),), text_color=CommonLocalizedStringColor.BLUE),) from sims4communitylib.utils.common_icon_utils import CommonIconUtils current_count = 0 count = 25 options = [] for sim_info in CommonSimUtils.get_sim_info_for_all_sims_generator(): if current_count >= count: break sim_id = CommonSimUtils.get_sim_id(sim_info) should_select = random.choice((True, False)) is_enabled = random.choice((True, False)) options.append( SimPickerRow( sim_id, select_default=should_select, tag=sim_info, is_enable=is_enabled ) ) current_count += 1 dialog = CommonChooseSimDialog( CommonStringId.TESTING_TEST_TEXT_WITH_STRING_TOKEN, CommonStringId.TESTING_TEST_TEXT_WITH_STRING_TOKEN, tuple(options), title_tokens=title_tokens, description_tokens=description_tokens ) dialog.show(on_chosen=_on_chosen, column_count=5) ``` -------------------------------- ### Create and Show Ok Dialog Source: https://sims4communitylibrary.readthedocs.io/en/latest/sims4communitylib.dialogs.basic_dialogs.html Demonstrates how to create and display a CommonOkDialog. This includes setting localized titles and descriptions with tokens, and a custom 'Ok' button text. The dialog is shown with a callback function to handle acknowledgment. ```python def _common_testing_show_ok_dialog(): def _on_acknowledged(_dialog: UiDialogOk): if _dialog.accepted: pass else: pass # LocalizedStrings within other LocalizedStrings title_tokens = (CommonLocalizationUtils.create_localized_string(CommonStringId.TESTING_SOME_TEXT_FOR_TESTING, text_color=CommonLocalizedStringColor.GREEN),) description_tokens = (CommonLocalizationUtils.create_localized_string(CommonStringId.TESTING_TEST_TEXT_WITH_SIM_FIRST_AND_LAST_NAME, tokens=(CommonSimUtils.get_active_sim_info(),), text_color=CommonLocalizedStringColor.BLUE),) dialog = CommonOkDialog( CommonStringId.TESTING_TEST_TEXT_WITH_STRING_TOKEN, CommonStringId.TESTING_TEST_TEXT_WITH_STRING_TOKEN, title_tokens=title_tokens, description_tokens=description_tokens, ok_text_identifier=CommonLocalizationUtils.create_localized_string(CommonStringId.TESTING_TEST_BUTTON_ONE, text_color=CommonLocalizedStringColor.RED) ) dialog.show(on_acknowledged=_on_acknowledged) ``` -------------------------------- ### Build and Show Dialog Source: https://sims4communitylibrary.readthedocs.io/en/latest/sims4communitylib.dialogs.option_dialogs.options.sims.html Demonstrates the method to display the constructed dialog to the player and handle their selections. It allows customization of columns, selectable count, and callbacks. ```python option_dialog.show( sim_info=CommonSimUtils.get_active_sim_info(), column_count=4, max_selectable=5, on_submit=_on_submit ) ``` -------------------------------- ### Interaction Testing and Lifecycle Example Source: https://sims4communitylibrary.readthedocs.io/en/latest/sims4communitylib.classes.interactions.html Demonstrates how to implement the on_test, on_started, and on_cancelled methods for a custom interaction. The on_test method controls visibility and enabled state based on conditions, while on_started and on_cancelled handle the interaction's execution and termination. ```python class _ExampleInteraction(CommonSocialMixerInteraction): @classmethod def on_test(cls, interaction_sim: Sim, interaction_target: Any, interaction_context: InteractionContext, *args, **kwargs) -> TestResult: result = 1 + 1 if result == 2: # Interaction will be displayed, but disabled, it will also have a tooltip that displays on hover with the text "Test Tooltip" return cls.create_test_result(False, reason="Test Tooltip") # Alternative way to specify a tooltip with the text "Test Tooltip" # return cls.create_test_result(False, reason="No Reason", tooltip=CommonLocalizationUtils.create_localized_tooltip("Test Tooltip")) if result == 3: # Interaction will be hidden completely. return CommonTestResult.NONE # Interaction will display and be enabled. return CommonTestResult.TRUE def on_started(self, interaction_sim: Sim, interaction_target: Any) -> CommonExecutionResult: result = True if not result: return CommonExecutionResult.FALSE # Put here what you want the interaction to do as soon as the player clicks it while it is enabled. return CommonExecutionResult.TRUE def on_cancelled(self, interaction_sim: Sim, interaction_target: Any, finishing_type: FinishingType, cancel_reason_msg: str, **kwargs): result = True if not result: return False # Put here what you want the interaction to do as soon as the player clicks it while it is enabled. return True ``` -------------------------------- ### Create and Show Ok/Cancel Dialog Source: https://sims4communitylibrary.readthedocs.io/en/latest/sims4communitylib.dialogs.basic_dialogs.html Demonstrates how to create and display a basic Ok/Cancel dialog with localized strings and tokens. Callbacks are provided for Ok and Cancel selections. ```Python def _common_testing_show_ok_cancel_dialog(): def _ok_chosen(_: UiDialogOkCancel): pass def _cancel_chosen(_: UiDialogOkCancel): pass # LocalizedStrings within other LocalizedStrings title_tokens = (CommonLocalizationUtils.create_localized_string(CommonStringId.TESTING_SOME_TEXT_FOR_TESTING, text_color=CommonLocalizedStringColor.GREEN),) description_tokens = (CommonLocalizationUtils.create_localized_string(CommonStringId.TESTING_TEST_TEXT_WITH_SIM_FIRST_AND_LAST_NAME, tokens=(CommonSimUtils.get_active_sim_info(),), text_color=CommonLocalizedStringColor.BLUE),) dialog = CommonOkCancelDialog( CommonStringId.TESTING_TEST_TEXT_WITH_STRING_TOKEN, CommonStringId.TESTING_TEST_TEXT_WITH_STRING_TOKEN, title_tokens=title_tokens, description_tokens=description_tokens, ok_text_identifier=CommonLocalizationUtils.create_localized_string(CommonStringId.TESTING_TEST_BUTTON_ONE, text_color=CommonLocalizedStringColor.RED), cancel_text_identifier=CommonStringId.TESTING_TEST_BUTTON_TWO ) dialog.show(on_ok_selected=_ok_chosen, on_cancel_selected=_cancel_chosen) ``` -------------------------------- ### CommonChooseSimDialog.rows Source: https://sims4communitylibrary.readthedocs.io/en/latest/sims4communitylib.dialogs.basic_dialogs.html Gets the collection of rows that have been added to the dialog. ```APIDOC ## rows ### Description The rows to display in the dialog. ### Returns A collection of rows added to the dialog. ### Return Type Tuple[BasePickerRow] ``` -------------------------------- ### Create and Display Multi-Pane Choose Dialog Source: https://sims4communitylibrary.readthedocs.io/en/latest/sims4communitylib.dialogs.basic_dialogs.html This example demonstrates how to create a multi-pane choose dialog with two sub-dialogs, each containing multiple options. It shows how to define localized strings for titles and descriptions, and how to add sub-dialogs with their respective callback functions. ```Python def _common_testing_show_multi_pane_choose_dialog(): def _on_submit(choices_made: Tuple[Any], outcome: CommonChoiceOutcome) -> None: pass def _on_sub_dialog_one_chosen(choice: Any, outcome: CommonChoiceOutcome) -> None: pass def _on_sub_dialog_two_chosen(choice: Any, outcome: CommonChoiceOutcome) -> None: pass # LocalizedStrings within other LocalizedStrings title_tokens = (CommonLocalizationUtils.create_localized_string(CommonStringId.TESTING_SOME_TEXT_FOR_TESTING, text_color=CommonLocalizedStringColor.GREEN),) description_tokens = (CommonLocalizationUtils.create_localized_string(CommonStringId.TESTING_TEST_TEXT_WITH_SIM_FIRST_AND_LAST_NAME, tokens=(CommonSimUtils.get_active_sim_info(),), text_color=CommonLocalizedStringColor.BLUE),) from sims4communitylib.utils.common_icon_utils import CommonIconUtils # Create the dialog. dialog = CommonMultiPaneChooseDialog( ModInfo.get_identity(), CommonStringId.TESTING_TEST_TEXT_WITH_STRING_TOKEN, CommonStringId.TESTING_TEST_TEXT_WITH_STRING_TOKEN, title_tokens=title_tokens, description_tokens=description_tokens ) sub_dialog_one_options = [ ObjectPickerRow( option_id=1, name=CommonLocalizationUtils.create_localized_string(CommonStringId.TESTING_SOME_TEXT_FOR_TESTING), row_description=CommonLocalizationUtils.create_localized_string(CommonStringId.TESTING_TEST_BUTTON_ONE), row_tooltip=None, icon=CommonIconUtils.load_checked_square_icon(), tag='Value 1' ), ObjectPickerRow( option_id=2, name=CommonLocalizationUtils.create_localized_string(CommonStringId.TESTING_SOME_TEXT_FOR_TESTING), row_description=CommonLocalizationUtils.create_localized_string(CommonStringId.TESTING_TEST_BUTTON_TWO), row_tooltip=None, icon=CommonIconUtils.load_arrow_navigate_into_icon(), tag='Value 2' ), ObjectPickerRow( option_id=3, name=CommonLocalizationUtils.create_localized_string('Value 3'), row_description=CommonLocalizationUtils.create_localized_string(CommonStringId.TESTING_TEST_BUTTON_TWO), row_tooltip=None, icon=CommonIconUtils.load_arrow_navigate_into_icon(), tag='Value 3' ) ] # Add sub dialog one. sub_dialog_one = CommonChooseObjectDialog( CommonStringId.TESTING_TEST_TEXT_WITH_STRING_TOKEN, CommonStringId.TESTING_TEST_TEXT_WITH_STRING_TOKEN, tuple(sub_dialog_one_options), title_tokens=title_tokens, description_tokens=description_tokens ) dialog.add_sub_dialog(sub_dialog_one, on_chosen=_on_sub_dialog_one_chosen) # Add sub dialog two. sub_dialog_two_options = [ ObjectPickerRow( option_id=4, name=CommonLocalizationUtils.create_localized_string('Value 4'), row_description=CommonLocalizationUtils.create_localized_string(CommonStringId.TESTING_TEST_BUTTON_ONE), row_tooltip=None, icon=CommonIconUtils.load_checked_square_icon(), tag='Value 4' ), ObjectPickerRow( option_id=5, name=CommonLocalizationUtils.create_localized_string('Value 5'), row_description=CommonLocalizationUtils.create_localized_string(CommonStringId.TESTING_TEST_BUTTON_TWO), row_tooltip=None, icon=CommonIconUtils.load_arrow_navigate_into_icon(), tag='Value 5' ), ObjectPickerRow( option_id=6, name=CommonLocalizationUtils.create_localized_string('Value 6'), row_description=CommonLocalizationUtils.create_localized_string(CommonStringId.TESTING_TEST_BUTTON_TWO), row_tooltip=None, icon=CommonIconUtils.load_arrow_navigate_into_icon(), tag='Value 6' ) ] sub_dialog_two = CommonChooseObjectDialog( CommonStringId.TESTING_TEST_TEXT_WITH_STRING_TOKEN, CommonStringId.TESTING_TEST_TEXT_WITH_STRING_TOKEN, tuple(sub_dialog_two_options), title_tokens=title_tokens, description_tokens=description_tokens ) dialog.add_sub_dialog(sub_dialog_two, on_chosen=_on_sub_dialog_two_chosen) # Show the dialog. dialog.show(on_submit=None) ``` -------------------------------- ### setup_asm_default Source: https://sims4communitylibrary.readthedocs.io/en/latest/sims4communitylib.classes.interactions.html Initializes the Animation State Machine (ASM). This function is crucial for setting up the necessary components for animation playback and management. ```APIDOC ## setup_asm_default ### Description A function that occurs when setting up the Animation State Machine. ### Parameters #### Path Parameters - **asm** (NativeAsm) - Required - An instance of the Animation State Machine ### Returns True, if the ASM was setup properly. False, if not. ### Return Type bool ``` -------------------------------- ### remove_appearance_modifiers_by_guid Source: https://sims4communitylibrary.readthedocs.io/en/latest/sims4communitylib.utils.sims.html Removes appearance modifiers from a Sim based on their GUID. ```APIDOC ## remove_appearance_modifiers_by_guid ### Description Removes appearance modifiers from a Sim by their GUID. ### Method static ### Parameters * **sim_info** (SimInfo) - Required - An instance of a Sim. * **modifier_guid** (int) - Required - The GUID of the modifier to remove. * **source** (str, optional) - The source of the removal. Default is 'S4CL Removal'. ```