Hi there! You are currently browsing as a guest. Why not create an account? Then you get less ads, can thank creators, post feedback, keep a list of your favourites, and more!
Forum Resident
Original Poster
#1 Old 11th Feb 2016 at 4:50 PM
Default Overriding the sim spawn function ("create_sim_instance"), causes sim to be greyed out at the portrait panel.
I decided to make my height slider mod have an effect on NPC's, so I overrode the create_sim_instance function to calculate a random height for the sim if it hadn't been done before. While it does its intended job and all, it has the side effect of graying out the portrait of the sim in the sim panel. Here's the code:

Code:
import AddSimSlider
import services
import injector
import traits.trait_tracker
import random
import sims.sim_info
import ScumLog

#does very little except for randomizing a sim's height if it has not been set.

@injector.inject_to(sims.sim_info.SimInfo, 'create_sim_instance')
def randomizeHeightIfDefault(original, self, position, sim_spawner_tags=None, spawn_action=None, sim_location=None, additional_fgl_search_flags=None, from_load=False, use_fgl=True):
     original(self, position, sim_spawner_tags=None, spawn_action=None, sim_location=None, additional_fgl_search_flags=None, from_load=False, use_fgl=True)
     sim_info = self
     if sim_info.trait_tracker.has_trait(15258887174838921384) == False:
        trait= services.trait_manager().get(15258887174838921384)
        sim_info.add_trait(trait)
        randomNo = random.randrange(-100,100)
        AddSimSlider.randomize_height_for_NPC("height", randomNo, sim_info)
        ScumLog.log(str(randomNo))     
Advertisement
Deceased
#2 Old 12th Feb 2016 at 4:26 PM
create_sim_instance returns True or False at the end, so perhaps the caller is expecting to see that? Try proxying that return code for your caller, eg:
Code:
     original_rc = original(self, position, sim_spawner_tags=None, spawn_action=None, sim_location=None, additional_fgl_search_flags=None, from_load=False, use_fgl=True)
    ....
    ....
    return original_rc

ETA - or better yet, don't do your code if the create_sim_instance fails, e.g.
Code:
     if not original(self, position, sim_spawner_tags=None, spawn_action=None, sim_location=None, additional_fgl_search_flags=None, from_load=False, use_fgl=True):
        return False
    .... do your stuff ....
    return True
Deceased
#3 Old 12th Feb 2016 at 4:49 PM
Oh, noticed something else - this is probably more critical although you still want to return that True/False. You're reseting all the optional arguments when you call the original, you want to instead pass on the callers options...
Code:
original(self, position, sim_spawner_tags=sim_spawner_tags, spawn_action=spawn_action, sim_location=sim_location, additional_fgl_search_flags=additional_fgl_search_flags, from_load=from_load, use_fgl=use_fgl)

I've made this mistake myself in the past, caused me no end of grief until Deaderpool pointed out my error.
Forum Resident
Original Poster
#4 Old 13th Feb 2016 at 3:15 AM
Quote: Originally posted by scumbumbo
Oh, noticed something else - this is probably more critical although you still want to return that True/False. You're reseting all the optional arguments when you call the original, you want to instead pass on the callers options...
Code:
original(self, position, sim_spawner_tags=sim_spawner_tags, spawn_action=spawn_action, sim_location=sim_location, additional_fgl_search_flags=additional_fgl_search_flags, from_load=from_load, use_fgl=use_fgl)

I've made this mistake myself in the past, caused me no end of grief until Deaderpool pointed out my error.


Thanks for the help scumbumbo!
Back to top