- Site Map >
- Modding and Creation >
- Sims 4 Creation >
- Modding Discussion >
- Overriding the sim spawn function ("create_sim_instance"), causes sim to be greyed out at the portrait panel.
- Site Map >
- Modding and Creation >
- Sims 4 Creation >
- Modding Discussion >
- Overriding the sim spawn function ("create_sim_instance"), causes sim to be greyed out at the portrait panel.
Replies: 3 (Who?), Viewed: 1218 times.
#1
11th Feb 2016 at 4:50 PM
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
#2
12th Feb 2016 at 4:26 PM
Posts: 2,671
Thanks: 62738 in 190 Posts
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:
ETA - or better yet, don't do your code if the create_sim_instance fails, e.g.
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
#3
12th Feb 2016 at 4:49 PM
Posts: 2,671
Thanks: 62738 in 190 Posts
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...
I've made this mistake myself in the past, caused me no end of grief until Deaderpool pointed out my error.
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.
#4
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!
Who Posted
|