Forum Announcement, Click Here to Read More From EA_Cade.

Injecting Satisfaction Store Rewards

TURBODRIVERTURBODRIVER Posts: 68 Member
edited March 5 in Nominated Threads
Hey! This is a simple way of injecting new rewards to the satisfaction store. I haven't tested it with anything else than traits, but it should work with everything as long as you include all of the details in the 'SimReward' tunable file.
A way of injecting rewards was requested by @Triplis and I hope it can be helpful for others too. It took me a while to figure it all out.

This instruction is strictly explaining how to add new reward traits. Adding money, moodlet, object, and CAS rewards is possible too, but wasn't tested.

1. Create a SimReward tunable file. In that file, you need to include your reward. For more details, you should check out the TDESC documentation. The example below is for a trait.
<?xml version="1.0" encoding="utf-8"?>
<I c="SimReward" i="reward" m="rewards.reward" n="Name_Of_The_Tuning_File" s="9876543210">
  <T p="" n="icon">2F7D0004:00000000:ABABABABABABABAB</T>
  <T n="name">0x00000000</T>
  <T n="reward_description">0x00000000</T>
  <L n="rewards">
    <V t="specific_reward">
      <V n="specific_reward" t="trait">
        <U n="trait">
          <T n="trait">1234567890</T>
        </U>
      </V>
    </V>
  </L>
</I>

2. Create a Python file. In that file, place the code below and change/add your own reward at the end just like the example is showing. The first variable is the ID of the SimReward tunable file, the second variable is the cost of the reward, and the third is the type (MONEY, BUFF, OBJECT, TRAIT, CASPART).
import services
from sims4 import resources, collections
from sims4.collections import FrozenAttributeDict
from whims.whims_tracker import WhimsTracker


def register_satisfaction_store_reward(reward_id, cost, award_type=WhimsTracker.WhimAwardTypes.TRAIT):
    """
    Register satisfaction store reward of given type.
    This method retains the original classes state and won't conflict when adding multiple of different rewards.
    The 'award_type' keyword is set to 'TRAIT' as an example of what award types are available.
    :param reward_id: int -> id of the reward instance
    :param cost: int -> amount of satisfaction points this reward will cost
    :param award_type: WhimAwardTypes -> award type enum
    """

    reward_instance = services.get_instance_manager(resources.Types.REWARD).get(reward_id)

    if reward_instance is not None:
        immutable_slots_class = collections.make_immutable_slots_class(['cost', 'award_type'])
        reward_immutable_slots = immutable_slots_class(🐸🐸🐸🐸(cost=cost, award_type=award_type))

        satisfaction_store_items = 🐸🐸🐸🐸(WhimsTracker.SATISFACTION_STORE_ITEMS)
        satisfaction_store_items[reward_instance] = reward_immutable_slots

        WhimsTracker.SATISFACTION_STORE_ITEMS = FrozenAttributeDict(satisfaction_store_items)


# Example of injecting a new reward trait
register_satisfaction_store_reward(1234567890, 100, WhimsTracker.WhimAwardTypes.TRAIT)

And you're done. Save and compile. The reward should now be available in the satisfaction store.
Post edited by EA_Cade on

Comments

  • TriplisTriplis Posts: 3,048 Member
    Thanks so much for sharing this, Turbodriver. :)

    I tried it with a custom simreward trait and it wasn't showing up in game, and then I realized it needed to be loaded somehow, so I used a standard injector and added the lines:
    from sims4.tuning.instance_manager import InstanceManager
    import injector
    

    And added to:
    # Example of injecting a new reward trait
    register_satisfaction_store_reward(1234567890, 100, WhimsTracker.WhimAwardTypes.TRAIT)
    

    with:
    @injector.inject_to(InstanceManager, 'load_data_into_class_instances')
    def _load_satisfaction_store_rewards(original, self):
        original(self)
    
        register_satisfaction_store_reward(1234567890, 100, WhimsTracker.WhimAwardTypes.TRAIT)
    

    Now it's showing up in-game. Yay. :)

    Also, for anyone else wanting to make use of it, it looks like the forums censored parts with the first four letters of dictionary into "plum". I changed that part in my code as well to account for it.
    Mods moved from MTS, now hosted at: https://triplis.github.io

Leave a Comment

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