Custom Buffs

Buff

class CommonBuff(...)

Bases: sphinx.ext.autodoc.importer._MockObject, sims4communitylib.logging.has_class_log.HasClassLog

An inheritable class that provides a way to create Custom Buffs.

classmethod get_log_identifier()

A string identifier for the log of the class.

Note

This is the text that will appear when logging messages.

Returns:The identifier for the log
Return type:str
classmethod get_mod_identity()

Retrieve the identity of the mod that owns the class.

Warning

Override this function with the CommonModIdentity of your mod.

This is a MUST override to allow for proper Exception Handling and Logging!

Returns:An instance of CommonModIdentity
Return type:CommonModIdentity
Raises:NotImplementedError – Thrown when the function is not implemented.
on_added(owner, from_load=False, apply_buff_loot=True)

A hook that occurs upon the Buff being added to the Sim.

Parameters:
  • owner (Sim) – The Sim that owns the Buff.
  • from_load (bool, optional) – True, if the Buff was added from a load. Default is False.
  • apply_buff_loot (bool, optional) – If True, Loot was applied when the Buff was added. Default is True.
on_removed(owner, apply_loot_on_remove=True)

A hook that occurs upon the Buff being removed from the Sim.

Parameters:
  • owner (Sim) – The Sim that owns the Buff.
  • apply_loot_on_remove (bool, optional) – If True, Loot will be applied after the Buff is removed. If False, it won’t. Default is True.
sim

Retrieve the Sim that owns the Buff.

Returns:An instance of the Sim that owns the Buff
Return type:Sim

Appearance Modifiers

class CommonAttachCASPartsAppearanceModifier

Bases: sims4communitylib.classes.appearance_modifiers.common_attach_cas_parts_appearance_modifier.BaseAppearanceModification, sims4communitylib.logging.has_log.HasLog

Attach CAS Parts to a Sim by utilizing Appearance Modifiers.

Note

Appearance Modifiers will apply to any outfit a Sim wears, when switching outfits ALL of their outfits will APPEAR to have the attached CAS Part. However, appearance modifiers are only temporary.

Note

To see an example of this appearance modifier in action, run the command s4clib_testing.toggle_example_appearance_modifier_buff in the console. (The Sim will have bare feet)

Example usage:
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(
                    description='                    A Modifier to apply and weight for the weighted random                     selection.                    ',
                    modifier=TunableVariant(
                        custom_bare_feet_modifier=CommonAttachBareFeetModifier.TunableFactory(),
                    ),
                    weight=TunableMultiplier.TunableFactory(
                        description='                        A weight with testable multipliers that is used to                         determine how likely this entry is to be picked when                         selecting randomly.                        '
                    )
                )
            )
        )
    }


# We use this buff in a Buff tuning and then apply the buff to the Sim.
class CommonExampleApplyBareFeetBuff(Buff):

    # We override the original "appearance_modifier" to so we can insert our custom appearance modifier.
    INSTANCE_TUNABLES = {
        'appearance_modifier': OptionalTunable(CommonExampleApplyBareFeetAppearanceModifier.TunableFactory()),
    }
Example Tuning:

Buff Tuning:

<?xml version="1.0" encoding="utf-8"?>
<I c="CommonExampleApplyBareFeetBuff" i="buff" m="sims4communitylib.examples.common_example_apply_bare_feet_buff" n="S4CL_Example_Buff_ApplyBareFeet" s="16461769487103204847">
  <V n="appearance_modifier" t="enabled">
    <U n="enabled">
      <L n="appearance_modifiers">
        <L>
          <U>
            <V n="modifier" t="custom_bare_feet_modifier">
              <U n="custom_bare_feet_modifier" />
            </V>
          </U>
        </L>
      </L>
    </U>
  </V>
  <T n="audio_sting_on_add" p="OnAddSound">39b2aa4a:00000000:8af8b916cf64c646</T>
  <T n="audio_sting_on_remove" p="OnRemoveSound">39b2aa4a:00000000:3bf33216a25546ea</T>
  <T n="icon" p="Icon">2f7d0004:00000000:30f0846c783606f9</T>
  <T n="visible">False</T>
</I>

Sim Data:

<?xml version="1.0" encoding="utf-8"?>
<SimData version="0x00000101" u="0x0000001F">
  <Instances>
    <I name="S4CL_Example_Buff_ApplyBareFeet" schema="Buff" type="Object">
      <T name="audio_sting_on_add">FD04E3BE-001407EC-8AF8B916CF64C646</T>
      <T name="audio_sting_on_remove">FD04E3BE-001407EC-3BF33216A25546EA</T>
      <T name="buff_description">0x00000000</T>
      <T name="buff_name">0x00000000</T>
      <T name="icon">00B2D882-00000000-30F0846C783606F9</T>
      <T name="mood_type">0</T>
      <T name="mood_weight">0</T>
      <T name="timeout_string">0x00000000</T>
      <T name="timeout_string_no_next_buff">0x00000000</T>
      <T name="ui_sort_order">1</T>
    </I>
  </Instances>
  <Schemas>
    <Schema name="Buff" schema_hash="0x0D045687">
      <Columns>
        <Column name="audio_sting_on_add" type="ResourceKey" flags="0x00000000" />
        <Column name="audio_sting_on_remove" type="ResourceKey" flags="0x00000000" />
        <Column name="buff_description" type="LocalizationKey" flags="0x00000000" />
        <Column name="buff_name" type="LocalizationKey" flags="0x00000000" />
        <Column name="icon" type="ResourceKey" flags="0x00000000" />
        <Column name="mood_type" type="TableSetReference" flags="0x00000000" />
        <Column name="mood_weight" type="Int32" flags="0x00000000" />
        <Column name="timeout_string" type="LocalizationKey" flags="0x00000000" />
        <Column name="timeout_string_no_next_buff" type="LocalizationKey" flags="0x00000000" />
        <Column name="ui_sort_order" type="Int32" flags="0x00000000" />
      </Columns>
    </Schema>
  </Schemas>
</SimData>
combinable_sorting_key

A key used to combine this appearance modifiers with other appearance modifiers.

is_compatible_with_outfit(outfit_category)

Whether or not the appearance modifier is compatible with the specified outfit category.

Note

If the appearance modifier is not compatible, then the buff that applies it will be removed.

Parameters:outfit_category (OutfitCategory) – The outfit category being checked.
Returns:True, if the appearance modifier is compatible with the specified outfit category. False, if not.
Return type:bool
is_permanent_modification

Whether the modification is permanent or not.

log_identifier

A string identifier for the log used by instances of the class.

Note

This is the message identifier that will appear when logging messages.

Returns:The identifier of the log
Return type:str
mod_identity

The identity of the mod that owns this property

Warning

Override this property with the CommonModIdentity of your mod.

This is a MUST override to allow for proper Exception Handling and Logging!

Returns:An instance of CommonModIdentity
Return type:CommonModIdentity
Raises:NotImplementedError – Thrown when the property is not implemented.
modifier_type

The type of modifier being applied.