Forum Discussion
9 years ago
@RexZheng I made a post over there with my scripts: http://modthesims.info/showthread.php?t=591559
I'll post them here as well (well, I say "my scripts," but they were pretty much copy/paste with ID name changes).
Basically, I wanted to inject into the list you find in object_sim, the one for interactions that show up when you click on your sim (and don't require another sim to do them). I thought this was the right code for it, but something isn't working because the interaction simply doesn't show up. It only shows up if I use an XML override, i.e. editing object_sim directly and putting it in my package file.
(I hope I'm not intruding on your thread, pearlbh)
Injector (named "triplis_child_play_injector")
Other file (I don't know what you'd call it... the thing that calls the injector)
I'll post them here as well (well, I say "my scripts," but they were pretty much copy/paste with ID name changes).
Basically, I wanted to inject into the list you find in object_sim, the one for interactions that show up when you click on your sim (and don't require another sim to do them). I thought this was the right code for it, but something isn't working because the interaction simply doesn't show up. It only shows up if I use an XML override, i.e. editing object_sim directly and putting it in my package file.
(I hope I'm not intruding on your thread, pearlbh)
Injector (named "triplis_child_play_injector")
# Python function injection
# By scripthoge at ModTheSims
#
from functools import wraps
import inspect
# method calling injection
def inject(target_function, new_function):
@wraps(target_function)
def _inject(*args, **kwargs):
return new_function(target_function, *args, **kwargs)
return _inject
# decarator injection.
def inject_to(target_object, target_function_name):
def _inject_to(new_function):
target_function = getattr(target_object, target_function_name)
setattr(target_object, target_function_name, inject(target_function, new_function))
return new_function
return _inject_to
def is_injectable(target_function, new_function):
target_argspec = inspect.getargspec(target_function)
new_argspec = inspect.getargspec(new_function)
return len(target_argspec.args) == len(new_argspec.args) - 1
Other file (I don't know what you'd call it... the thing that calls the injector)
import services
import triplis_child_play_injector
import sims.sim
Triplis_Child_Play_sa_instance_ids = (13884954916998690505, )
@triplis_child_play_injector.inject_to(sims.sim.Sim, 'on_add')
def Triplis_Child_Play_add_super_affordances(original, self):
original(self)
sa_list = []
affordance_manager = services.affordance_manager()
for sa_id in Triplis_Child_Play_sa_instance_ids:
tuning_class = affordance_manager.get(sa_id)
if not tuning_class is None:
sa_list.append(tuning_class)
self._super_affordances = self._super_affordances + tuple(sa_list)
About The Sims 4 Mods & Custom Content
Find expert tips, troubleshooting help, tutorials for mods and custom content, and The Sims 4 patch files in our forum.15,595 PostsLatest Activity: 2 hours ago
Community Highlights
Recent Discussions
- 2 hours ago
- 2 hours ago
- 3 hours ago
- 3 hours ago