![]() If sim_info.has_trait(trait_manager.get(SOME_TRAIT_TUNING_ID)):Īs you can see, this portion is very open for customization. # this would add your trait to all sims with an existing trait There are more interesting kinds of checks you can do, too: Sim_info.add_trait(SOME_TRAIT_FOR_EVERY_OTHER_SIM) The last part is there for if you have multiple traits that should be applied to different sims after the list is filtered. Of course, add more `sim_info.has_trait(YOUR_TRAIT_NAME)` cases for each trait you're adding, or create a helper function to make your code more readable and concise. If sim_info is None or sim_info.has_trait(YOUR_TRAIT_NAME): This will prevent the game from trying to add the same traits again, which will improve performance. You can do that like this: Please note: I highly recommend that you include a condition to check if the `sim_info` has already had your trait(s) added to it. # keep in mind that this filters out animals, but NOT occults # this would make it so that your trait(s) can only be applied to adult, human sims If sim_info is None or sim_info.age != Age.ADULT or sim_info.species != Species.HUMAN: # keep in mind that this does NOT filter out animals or occultsįrom sims.sim_info_types import Age, Species # this would make it so that your trait(s) can only be applied to sims that are teens or older If sim_info is None or sim_info.age < Age.TEEN: ![]() You'll have to do some digging into the `sims.sim_info` module to know everything that's possible to do here, but as a couple of examples: if your trait only applies to humans, then add a condition here that checks if the `sim_info` is not a human). Replace `YOUR_CONDITIONS_HERE` with anything you'd like to filter sims by (i.e. In order to assign these variables their values, you have to use the traits' decimal tuning ID in place of `YOUR_TRAIT_TUNING_ID`. Of course, replace `YOUR_TRAIT_NAME` with a name to store your trait in, and create more variables for however traits you would like to add. If sim_info is None or YOUR_CONDITIONS_HERE: YOUR_TRAIT_NAME = trait_manager.get(YOUR_TRAIT_TUNING_ID) # add as many of these as you need This will of course vary heavily depending on your needs, but you can base your function off of the following:ĭef CREATORNAME_MODNAME_add_traits_to_sim(sim_info): You'll need a function that determines which traits to add to whom. This will be used to append your script to existing scripts in the game. Setattr(target_object, target_function_name, inject(target_function, new_function)) Target_function = getattr(target_object, target_function_name) Return new_function(target_function, *args, **kwargs)ĭef inject_to(target_object, target_function_name): If not, you can use the following:ĭef inject(target_function, _inject(*args, **kwargs): If you already have an injector, skip this step. Injectors are used to insert your code into the game's code. It is assumed that you already have your custom trait(s) made, and that you are at least somewhat familiar with Python scripting. Please view the updated tutorial on Medium.Īre you making a mod that has custom traits? Do any of those traits need to be automatically assigned to all of the sims in the game? This tutorial will show you one quick way to achieve that.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |