Forum Discussion

SacrificialsMod's avatar
8 years ago

Adding interactions to a terrain via python script ? [SOLVED]

Hello, I've been trying to add interactions to a terrain using a python script but it's not showing up in game.
I've tried adding them to "object_terrain" tuning recourse " "14982" and it works fine but I couldn't figure out how to add them via a script.

This is the script that I used


import services
import injector
import objects
import objects.terrain
from objects.terrain import Terrain

DG_DeadlyToddlers_Interactions_ObjectTerrain_sa_instance_ids = (11438713963126644620, 13434953397345340498, )
DG_DeadlyToddlers_Interactions_ObjectTerrain_object_ids = (14982, )


@injector.inject_to(Terrain, 'on_add')
def DG_DeadlyToddlers_Interactions_ObjectTerrain_add_super_affordances(original, self):
original(self)
sa_list = []
affordance_manager = services.affordance_manager()
for sa_id in DG_DeadlyToddlers_Interactions_ObjectTerrain_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)


I've also tried this


import services
import injector
import objects
import types
import objects.terrain
from objects.terrain import Terrain

DG_DeadlyToddlers_Interactions_ObjectTerrain_sa_instance_ids = (11438713963126644620, 13434953397345340498, )
DG_DeadlyToddlers_Interactions_ObjectTerrain_object_ids = (14982, )

def attachinteraction(sa_list, affordance_manager, sa_id):
tuning_class = affordance_manager.get(sa_id)
if not tuning_class is None:
sa_list.append(tuning_class)

@injector.inject_to(Terrain, 'on_add')
def DG_DeadlyToddlers_Interactions_ObjectTerrain_add_super_affordances(original, self):
original(self)

if not self.guid64 in DG_DeadlyToddlers_Interactions_ObjectTerrain_object_ids:
return

sa_list = []
affordance_manager = services.affordance_manager()

if(isinstance(DG_DeadlyToddlers_Interactions_ObjectTerrain_sa_instance_ids, int)):
attachinteraction(sa_list, affordance_manager, DG_DeadlyToddlers_Interactions_ObjectTerrain_sa_instance_ids)
else:
for sa_id in DG_DeadlyToddlers_Interactions_ObjectTerrain_sa_instance_ids:
attachinteraction(sa_list, affordance_manager, sa_id)
self._super_affordances = self._super_affordances + tuple(sa_list)


& also this


import services
import objects.terrain
import injector

DG_DeadlyToddlers_Interactions_ObjectTerrain_sa_instance_ids = (13434953397345340498, 11438713963126644620, 15313978156997466037, )
DG_DeadlyToddlers_Interactions_ObjectTerrain_object_ids = (14982, )

@injector.inject_to(objects.terrain.Terrain, 'on_add')
def DG_DeadlyToddlers_Interactions_ObjectTerrain_add_super_affordances(original, self):
original(self)

if not self.guid64 in DG_DeadlyToddlers_Interactions_ObjectTerrain_object_ids:
return

sa_list = []
affordance_manager = services.affordance_manager()
for sa_id in DG_DeadlyToddlers_Interactions_ObjectTerrain_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)


but I had no luck, I wish someone can help me with this
*Note: adding these interactions to "Object_terrain" XML worked but injecting it via python so it's not ovverriding didn't
Thanks in advance

EDIT: I've finally found a code that adds interactions to terrain object by "batman101
from Sims 4 Occult Life State: Succubus mod.

This is the working code to add interactions to a terrain via python

import services
import injector
import sims4.resources
from sims4.tuning.instance_manager import InstanceManager
from sims4.resources import Types

DG_DeadlyToddlers_Interactions_ObjectTerrain_sa_instance_ids = (13434953397345340498, 11438713963126644620, 15313978156997466037,)
DG_DeadlyToddlers_Interactions_ObjectTerrain_object_ids = (14982,)

@injector.inject_to(InstanceManager, 'load_data_into_class_instances')
def add_superaffordances(original, self):
original(self)

if self.TYPE == Types.OBJECT:
affordance_manager = services.affordance_manager()
sa_list = []
for sa_id in DG_DeadlyToddlers_Interactions_ObjectTerrain_sa_instance_ids:
key = sims4.resources.get_resource_key(sa_id, Types.INTERACTION)
sa_tuning = affordance_manager.get(key)
if not sa_tuning is None:
sa_list.append(sa_tuning)
sa_tuple = tuple(sa_list)

for obj_id in DG_DeadlyToddlers_Interactions_ObjectTerrain_object_ids:
key = sims4.resources.get_resource_key(obj_id, Types.OBJECT)
obj_tuning = self._tuned_classes.get(key)
if not obj_tuning is None:
obj_tuning._super_affordances = obj_tuning._super_affordances + sa_tuple

  • "on_add" is not called for the Terrain object. Try using "__init__" instead. If that doesn't work, you'll have to get creative... :)
  • when I changed it to "__init__" I got an error saying "script Attempting to access the terrain object before it is created." in the last exception file.
    Thanks for the suggestion though, I really appreciate it, I'll keep trying & hopefully I'll get it to work

    EDIT: I've finally found a code that adds interactions to terrain object by "batman101
    from Sims 4 Occult Life State: Succubus mod.

    This is the working code to add interactions to a terrain via python

    import services
    import injector
    import sims4.resources
    from sims4.tuning.instance_manager import InstanceManager
    from sims4.resources import Types

    DG_DeadlyToddlers_Interactions_ObjectTerrain_sa_instance_ids = (13434953397345340498, 11438713963126644620, 15313978156997466037,)
    DG_DeadlyToddlers_Interactions_ObjectTerrain_object_ids = (14982,)

    @injector.inject_to(InstanceManager, 'load_data_into_class_instances')
    def add_superaffordances(original, self):
    original(self)

    if self.TYPE == Types.OBJECT:
    affordance_manager = services.affordance_manager()
    sa_list = []
    for sa_id in DG_DeadlyToddlers_Interactions_ObjectTerrain_sa_instance_ids:
    key = sims4.resources.get_resource_key(sa_id, Types.INTERACTION)
    sa_tuning = affordance_manager.get(key)
    if not sa_tuning is None:
    sa_list.append(sa_tuning)
    sa_tuple = tuple(sa_list)

    for obj_id in DG_DeadlyToddlers_Interactions_ObjectTerrain_object_ids:
    key = sims4.resources.get_resource_key(obj_id, Types.OBJECT)
    obj_tuning = self._tuned_classes.get(key)
    if not obj_tuning is None:
    obj_tuning._super_affordances = obj_tuning._super_affordances + sa_tuple

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.4,695 PostsLatest Activity: 24 hours ago