Forum Announcement, Click Here to Read More From EA_Cade.

Injecting multiple "SocialMixerInteraction" to a snippets ?

Dramatic-GamerDramatic-Gamer Posts: 713 Member
edited March 5 in Nominated Threads
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.
Youtube_Banner_2017.jpg
Post edited by EA_Cade on

Comments

  • TriplisTriplis Posts: 3,048 Member
    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 = [
        {
            "name": "Triplis_SorcererTrait_MixerInteractions_FriendlyNonTouching_Snippet",
            "mixer_instance_ids": (13250433561655961719, 10814470620858752309),
            "snippet_tuning_ids": (24508, )
        },	
        {
            "name": "Triplis_SorcererTrait_MixerInteractions_MeanTouching_Snippet",
            "mixer_instance_ids": (17437340195943479714, ),
            "snippet_tuning_ids": (24506, )
        },	
        {
            "name": "Triplis_SorcererTrait_DeathInteractions_DeathAll_Snippet",
            "mixer_instance_ids": (17537670152126568118, 10120003953743559761, 18002559964044978289),
            "snippet_tuning_ids": (16338, )
        },	
    ]
    
    @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['mixer_instance_ids']:
                    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['snippet_tuning_ids']:
                    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
    
    Mods moved from MTS, now hosted at: https://triplis.github.io
  • Dramatic-GamerDramatic-Gamer Posts: 713 Member
    Triplis 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 = [
        {
            "name": "Triplis_SorcererTrait_MixerInteractions_FriendlyNonTouching_Snippet",
            "mixer_instance_ids": (13250433561655961719, 10814470620858752309),
            "snippet_tuning_ids": (24508, )
        },	
        {
            "name": "Triplis_SorcererTrait_MixerInteractions_MeanTouching_Snippet",
            "mixer_instance_ids": (17437340195943479714, ),
            "snippet_tuning_ids": (24506, )
        },	
        {
            "name": "Triplis_SorcererTrait_DeathInteractions_DeathAll_Snippet",
            "mixer_instance_ids": (17537670152126568118, 10120003953743559761, 18002559964044978289),
            "snippet_tuning_ids": (16338, )
        },	
    ]
    
    @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['mixer_instance_ids']:
                    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['snippet_tuning_ids']:
                    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 ♥
    Youtube_Banner_2017.jpg

Leave a Comment

BoldItalicStrikethroughOrdered listUnordered list
Emoji
Image
Align leftAlign centerAlign rightToggle HTML viewToggle full pageToggle lights
Drop image/file
Return to top