Replies: 0 (Who?), Viewed: 1078 times.
Original Poster
#1 Old 1st Feb 2016 at 6:36 PM
Default Adding to Emotional Whimsets via Script
I wanted to add a whim for sims to play SimLotto to the playful and confident moods, so I created a new emotional whimset for these based on whimSet_EmotionPlayful.

Unfortunately this didn't add the whim to the playful mood, but completely replaced the originals even though this was a new whimset and not an override. Apparantly there can be only one whimset which uses the "whimset_emotion" tuning per mood, and if you define a second one it replaces the original.

I considered doing a normal override of the whimset adding my new whim to the list, but we all know the kinds of issues that arise with that. So, as I'd played with modifying tuning on the fly for a couple of other (unfinished) projects, I thought it should be pretty easy to accomplish adding the whim objective to the whimset tuning on the fly. And it is.

You won't be able to run this "as is" since you don't have the package with the SimLotto whim (SimLotto 2 is still in development), but the example should be able to pretty easy to follow. The MTS_Scumbumbo_Whim_PlaySimLotto is just a standard situation_goal created in XML and in the mod's package file. The code below then adds that situation_goal to the end of the whims TunableList of the emotional whimsets for playful and confident.
import sims4.collections
import sims4.resources
import services
from sims4.tuning.instance_manager import InstanceManager

def add_goal_to_whimsets(self):
    # Get the tuning for MTS_Scumbumbo_Whim_PlaySimLotto
    manager = services.get_instance_manager(Types.SITUATION_GOAL)
    goal_tuning = manager.get(12955570644355834297)
    if goal_tuning is None:
        # The user must not have the package installed properly, so abort
    # Make an immutable slots object that points to our new goal tuning and defines the weight
    immutable_slots_class = sims4.collections.make_immutable_slots_class(set(['goal', 'weight']))
    whimset_goal = immutable_slots_class({'goal':goal_tuning, 'weight':1.0})
    # Get the tuning for the whimsets from the base game, whimSet_EmotionPlayful
    key = sims4.resources.get_resource_key(25421, Types.ASPIRATION)
    whimset_playful_tuning = self._tuned_classes.get(key)
    # and whimSet_EmotionConfident
    key = sims4.resources.get_resource_key(25424, Types.ASPIRATION)
    whimset_confident_tuning = self._tuned_classes.get(key)
    # And add our whimset goal to the whims TunableList for both whimsets
    if not whimset_playful_tuning is None:
        whimset_playful_tuning.whims = whimset_playful_tuning.whims + (whimset_goal,)
    if not whimset_confident_tuning is None:
        whimset_confident_tuning.whims = whimset_confident_tuning.whims + (whimset_goal,)

@injector.inject_to(InstanceManager, 'load_data_into_class_instances')
def SimLotto_load_data_into_class_instances(original, self):
    # Call the original function to load the tuning data into class instances

    # Alter the loaded tuning once it's been loaded
    if self.TYPE == Types.ASPIRATION:

Now, if someone else overrides the emotional whimset, or even if EA adds or changes the whimset in a game patch, our new situation goal still gets tacked onto the end of the list.
Back to top