Forum Discussion

SacrificialsMod's avatar
7 years ago

Injecting multiple "SocialMixerInteraction" to a snippets ?

Hello, I'm trying to inject multiple interactions to a snippet using python.
I've used "Scumbumbo's" code which worked on a "Single Interaction" only, adding more than one interaction to the "Mixer Id" didn't work.



import injector
import sims4.resources
from sims4.tuning.instance_manager import InstanceManager
from sims4.resources import Types
import services



SNIPPET_ID = 24511

MIXER_ID = 13984173314801262715



@injector.inject_to(InstanceManager, 'load_data_into_class_instances')
def add_mixer_to_snippet(original, self):

original(self)

if self.TYPE == Types.SNIPPET:

key = sims4.resources.get_resource_key(SNIPPET_ID, Types.SNIPPET)
snippet_tuning = self._tuned_classes.get(key)


if snippet_tuning is None:
return


affordance_manager = services.affordance_manager()
key = sims4.resources.get_resource_key(MIXER_ID, Types.INTERACTION)
mixer_tuning = affordance_manager.get(key)
if mixer_tuning is None:

return

snippet_tuning.value = snippet_tuning.value + (mixer_tuning, )


How can I modify this to make it accept more than one interaction in the "MIXER_ID" ?

Thank You very much.
  • Not sure if you're still looking for help with this, but I was browsing and saw this. Realized it'd be quick to share a working example. Haven't looked at the code in a while, but this was a setup I copied the structure of from someone else (I'd give credit if I could remember who).

    Here's an example. Enables you to do both multiple mixers per snippet and do more than one snippet type.

    Hope this helps. :)


    Triplis_SorcererTrait_Interactions_mixer_to_snippets =

    @Triplis_SorcererTrait_Injector.inject_to(InstanceManager, 'load_data_into_class_instances')
    def Triplis_Sorcerer_add_mixers_to_snippets(original, self):
    original(self)

    if self.TYPE == Types.SNIPPET:
    # For each set of interaction ids and object ids...
    for snippet_tun_hash in Triplis_SorcererTrait_Interactions_mixer_to_snippets:

    # First, get a tuple containing the tunings for all the social mixers...
    affordance_manager = services.affordance_manager()
    mixer_list = []
    for mixer_id in snippet_tun_hash:
    key = sims4.resources.get_resource_key(mixer_id, Types.INTERACTION)
    mixer_tuning = affordance_manager.get(key)
    if not mixer_tuning is None:
    mixer_list.append(mixer_tuning)
    mixer_tuple = tuple(mixer_list)

    # Now update the tunings for all the snippets in our snippet list
    for snippet_id in snippet_tun_hash:
    key = sims4.resources.get_resource_key(snippet_id, Types.SNIPPET)
    snippet_tuning = self._tuned_classes.get(key)
    if not snippet_tuning is None:
    snippet_tuning.value = snippet_tuning.value + mixer_tuple
  • "Triplis;c-16445976" wrote:
    Not sure if you're still looking for help with this, but I was browsing and saw this. Realized it'd be quick to share a working example. Haven't looked at the code in a while, but this was a setup I copied the structure of from someone else (I'd give credit if I could remember who).

    Here's an example. Enables you to do both multiple mixers per snippet and do more than one snippet type.

    Hope this helps. :)


    Triplis_SorcererTrait_Interactions_mixer_to_snippets =

    @Triplis_SorcererTrait_Injector.inject_to(InstanceManager, 'load_data_into_class_instances')
    def Triplis_Sorcerer_add_mixers_to_snippets(original, self):
    original(self)

    if self.TYPE == Types.SNIPPET:
    # For each set of interaction ids and object ids...
    for snippet_tun_hash in Triplis_SorcererTrait_Interactions_mixer_to_snippets:

    # First, get a tuple containing the tunings for all the social mixers...
    affordance_manager = services.affordance_manager()
    mixer_list = []
    for mixer_id in snippet_tun_hash:
    key = sims4.resources.get_resource_key(mixer_id, Types.INTERACTION)
    mixer_tuning = affordance_manager.get(key)
    if not mixer_tuning is None:
    mixer_list.append(mixer_tuning)
    mixer_tuple = tuple(mixer_list)

    # Now update the tunings for all the snippets in our snippet list
    for snippet_id in snippet_tun_hash:
    key = sims4.resources.get_resource_key(snippet_id, Types.SNIPPET)
    snippet_tuning = self._tuned_classes.get(key)
    if not snippet_tuning is None:
    snippet_tuning.value = snippet_tuning.value + mixer_tuple


    Thank You so much! I got help by Basemental a while ago so I stopped checking this thread.
    This will come in handy for future projects.
    Much appreciated ♥

About The Sims 4 Mods & Custom Content

Find expert tips, troubleshooting help, tutorials for mods and custom content, and The Sims 4 patch files in our forum.4,698 PostsLatest Activity: 22 hours ago