Home | Download | Discussion | Help | Site Map | New Posts | Sign in

Latest Site News

Nysha's New Creators for November - posted on 1st Dec 2017 at 10:00 AM
Replies: 4 (Who?), Viewed: 723 times.
Test Subject
Original Poster
#1 Old 16th Nov 2017 at 4:50 AM
Default Creating New Reward Traits without overriding?
I'm currently working on something and would love to add some achievements/reward traits to the reward store, but I need to override the file 'whims_whimsTracker' file and although I can make sure I update it constantly, it will likely conflict with other mods.

I tried some Python myself but didn't get it to work.
Code:
import services from sims4.collections
import make_immutable_slots_class, FrozenAttributeDict
from sims4.resources import Types, get_resource_key
from whims.whims_tracker import WhimsTracker
def add_reward_trait_sharer(self): reward_manager = services.get_instance_manager(Types.REWARD)
reward_tuning = reward_manager.get(7199758815256132942)
if reward_tuning is None:
return
immutable_slots_class = sims4.collections.make_immutable_slots_class(['award_type', 'cost'])
Rex_ActiveCareer_Aspiration_Reward_Trait = immutable_slots_class(dict(award_type = WhimAwardTypes.TRAIT, cost = 500))
trait_dict = dict(WhimsTracker.SATISFACTION_STORE_ITEMS)
trait_dict[reward_tuning] = Rex_ActiveCareer_Aspiration_Reward_Trait WhimsTracker.SATISFACTION_STORE_ITEMS = trait_dict

I also tried to inject tags to the game but that's a whole other story and now I'm really curious if tags can be injected, but I knew reward trait can be added since I noticed WW managed to do that. :/

Thanks in advance!
Advertisement
Top Secret Researcher
#2 Old 16th Nov 2017 at 11:50 AM
I've never worked with these myself so I'm not sure that your approach is even valid for what you're wanting to accomplish, but I'd suggest starting by logging any exceptions generated to a log file as you have at least one class you are referencing that appears not to have been imported -- WhimAwardTypes.

When I hit a brick wall I almost always use a try/except block around what I'm working on and use traceback and a custom log function to log any exceptions, and quite often something ends up in my log file to at least point me in the right direction. Use something like this:
Code:

import traceback
import os.path

def writelog(str, logname=None):
    if logname is None:
        logname = "__log.log"
    filename = os.path.join(os.path.dirname(os.path.realpath(__file__)), logname)
    with open(filename, "a") as fp:
        fp.write('{}\n'.format(str))

def your_function():
    try:
        YOUR PROBLEM CODE HERE
    except:
        writelog(traceback.format_exc())
Test Subject
Original Poster
#3 Old 9th Dec 2017 at 8:06 AM Last edited by konansock : 9th Dec 2017 at 9:29 AM.
Quote:
Originally Posted by scumbumbo
I've never worked with these myself so I'm not sure that your approach is even valid for what you're wanting to accomplish, but I'd suggest starting by logging any exceptions generated to a log file as you have at least one class you are referencing that appears not to have been imported -- WhimAwardTypes.

When I hit a brick wall I almost always use a try/except block around what I'm working on and use traceback and a custom log function to log any exceptions, and quite often something ends up in my log file to at least point me in the right direction. Use something like this:
Code:

import traceback
import os.path

def writelog(str, logname=None):
    if logname is None:
        logname = "__log.log"
    filename = os.path.join(os.path.dirname(os.path.realpath(__file__)), logname)
    with open(filename, "a") as fp:
        fp.write('{}\n'.format(str))

def your_function():
    try:
        YOUR PROBLEM CODE HERE
    except:
        writelog(traceback.format_exc())


Wow! I never expected Sumbumbo to reply to my silly question!

Actually I tried to make this code according to your injecting whims to whimsets code, because the two are highly similar

I haven't tried again these days, but I'll try when I got time! Thanks for your suggestion!

Edit: Actually I looked into your Inventory Type override as well, since this is a module file instead of other file like the whimsets, so I need to look into how to inject a script into the module files. I think some code must be incorrect so... As for the WhimAwardType, that function was defined inside the class WhimsTracker so I wasn't sure if I should import it, I'll definitely try!
Test Subject
Original Poster
#4 Old 9th Dec 2017 at 10:33 AM
OK, I edited the code some more and it now looks like this:

import services
import rex_teencriminal_injector
import sims4.collections
import sims4.resources
import services
from sims4.resources import Types
from sims4.tuning.instance_manager import InstanceManager
from whims.whims_tracker import WhimsTracker

manager = services.get_instance_manager(Types.REWARD)
reward_tuning = manager.get(7199758815256132942)
immutable_slots_class = sims4.collections.make_immutable_slots_class(set(['award_type', 'cost']))
reward_value = immutable_slots_class({'award_type':WhimsTracker.WhimAwardTypes.TRAIT , 'cost':500})

WhimsTracker.SATISFACTION_STORE_ITEMS = WhimsTracker.SATISFACTION_STORE_ITEMS + {reward_tuning:reward_value}

This way the game finally recognized the WhimsAwardType class and stop giving me script errors...
However, when I load up the reward store, it now shows nothing but blank...I think I should still try it some time later.
Top Secret Researcher
#5 Old 10th Dec 2017 at 3:57 AM
Seems like to add to a FrozenAttributeDict I had to "thaw" it first by converting it to something else (plain dict, most likely), adding the new values, and then converting that back again. Best guess without trying is that the "+" operation is failing and so the result applied to the WhimsTracker.SATISFACTION_STORE_ITEMS at the end is None, or possibly a regular dict which the game doesn't recognize properly as it's not the FrozenAttributeDict it's expecting.
Back to top