- Site Map >
- Modding and Creation >
- Sims 4 Creation >
- Modding Discussion >
- Trait XML Instance Help
- Site Map >
- Modding and Creation >
- Sims 4 Creation >
- Modding Discussion >
- Trait XML Instance Help
Replies: 5 (Who?), Viewed: 796 times.
#1
21st Oct 2020 at 5:38 AM
Posts: 11
Thanks: 103 in 2 Posts
Trait XML Instance Help
Hi! I am trying to write a script in python to apply the clumsy trait to the active sim. I used this thread as the basis (I test the code that scumbumbo wrote and everything worked as expected). I changed the xml instance code to the one for clumsy and re-ran the code and nothing happened. The outputs showed up, but the trait was not applied to the sim. I think that I am using the wrong xml instance id (I am honestly unsure of what the name for the code is). I got the number by searching for "trait_Clumsy" in the xml file finder and using the number listed under "instance" which is 16832 is that the right number? Do I have to do something special to add in a 4th "normal" trait?
Advertisement
Lab Assistant
#2
21st Oct 2020 at 10:58 AM
Posts: 137
Thanks: 4460 in 38 Posts
I believe you need to remove a personality trait before you can add another.
This function in the TraitTracker class seems to be blocking the addition of a 4th personality trait:
specifically this part:
You would have to get the sim's personality traits and remove one of them before you can add another.
Here is a fully working example of a 'clumsy' and 'unclumsy" cheat which adds or removes the clumsy trait.
This function in the TraitTracker class seems to be blocking the addition of a 4th personality trait:
Code:
def can_add_trait(self, trait): if not self._has_valid_lod(trait): return False if self.has_trait(trait): logger.info('Trying to equip an existing trait {} for Sim {}', trait, self._sim_info) return False if trait.is_personality_trait and self.empty_slot_number == 0: logger.info('Reach max equipment slot number {} for Sim {}', self.equip_slot_number, self._sim_info) return False if not trait.is_valid_trait(self._sim_info): logger.info("Trying to equip a trait {} that conflicts with Sim {}'s age {} or gender {}", trait, self._sim_info, self._sim_info.age, self._sim_info.gender) return False elif self.is_conflicting(trait): logger.info('Trying to equip a conflicting trait {} for Sim {}', trait, self._sim_info) return False return True
specifically this part:
Code:
if trait.is_personality_trait and self.empty_slot_number == 0: logger.info('Reach max equipment slot number {} for Sim {}', self.equip_slot_number, self._sim_info) return False
You would have to get the sim's personality traits and remove one of them before you can add another.
Here is a fully working example of a 'clumsy' and 'unclumsy" cheat which adds or removes the clumsy trait.
Code:
from sims4.resources import Types import sims4.commands import services from server_commands.argument_helpers import get_tunable_instance import random CLUMSY_TRAIT_ID = 16832 # For refilling empty personality trait slots def add_random_trait(sim_info, output): trait_tracker = sim_info.trait_tracker trait_manager = services.get_instance_manager(Types.TRAIT) possible_traits = [trait for trait in trait_manager.types.values() if trait.is_personality_trait and trait_tracker.can_add_trait(trait)] if possible_traits: chosen_trait = random.choice(possible_traits) sim_info.add_trait(chosen_trait) output('added trait: {}'.format(chosen_trait)) @sims4.commands.Command('clumsy', command_type=sims4.commands.CommandType.Live) def add_trait(_connection=None): # Get the console output output = sims4.commands.CheatOutput(_connection) # Get the sim_info for the active sim sim_info = services.get_active_sim().sim_info # Get the tuned trait instance clumsy_trait = get_tunable_instance(Types.TRAIT, CLUMSY_TRAIT_ID) # Check if our sim already has that trait if sim_info.has_trait(clumsy_trait): output('Sim is already clumsy') return False if not clumsy_trait.is_valid_trait(sim_info): output('Cannot add trait to sim. Wrong age or species') return False # Get the sim's trait tracker so we can easily check for conflicts # Do not add or remove traits using the trait tracker, use the sim_info. trait_tracker = sim_info.trait_tracker # First remove all conflicting traits (maker conflicts with clumsy) if trait_tracker.is_conflicting(clumsy_trait): output('Sim has conflicting trait!') for trait in trait_tracker.equipped_traits: if trait.is_conflicting(clumsy_trait): sim_info.remove_trait(trait) output('Removed conflicting trait: {}'.format(trait)) # Check if we need to remove a trait. if trait_tracker.empty_slot_number == 0: output('Sim has max traits... removing one...') # Randomly select a trait to remove trait = random.choice(trait_tracker.personality_traits) sim_info.remove_trait(trait) output('Randomly removed trait: {}'.format(trait)) sim_info.add_trait(clumsy_trait) output('Sim is now clumsy') # Refill any empty personality trait slots if sim had multiple conflicts removed while trait_tracker.empty_slot_number > 0: add_random_trait(sim_info, output) return True @sims4.commands.Command('unclumsy', command_type=sims4.commands.CommandType.Live) def remove_trait(_connection=None): output = sims4.commands.CheatOutput(_connection) sim_info = services.get_active_sim().sim_info clumsy_trait = get_tunable_instance(Types.TRAIT, CLUMSY_TRAIT_ID) if not sim_info.has_trait(clumsy_trait): output('Sim is not clumsy!') else: sim_info.remove_trait(clumsy_trait) output('Sim is no longer clumsy') # Fill the now empty slot add_random_trait(sim_info, output) return True
#3
21st Oct 2020 at 11:58 PM
Posts: 11
Thanks: 103 in 2 Posts
Oh wow thank you so much!! This is exactly what I was looking for! Can the death by anger trait be added because it is not a "standard trait"? Other mods like the slice of life personality analyzer also add a 4th custom trait to a premade sim do you think that when the creator made those new traits she categorized them as a "special traits" so they can be added after the sim is created?
Lab Assistant
#4
22nd Oct 2020 at 3:29 AM
Posts: 137
Thanks: 4460 in 38 Posts
Quote: Originally posted by 13pigpen
Oh wow thank you so much!! This is exactly what I was looking for! Can the death by anger trait be added because it is not a "standard trait"? Other mods like the slice of life personality analyzer also add a 4th custom trait to a premade sim do you think that when the creator made those new traits she categorized them as a "special traits" so they can be added after the sim is created? |
The death by anger trait is a "ghost" trait (gives the sim the shader effect) so it can be added because only personality traits use up the 3 personality trait slots.
Usually, mod creators set their traits as "gameplay" traits or "hidden" traits, depending on if they want the trait to be visible or not.
Gameplay traits are stuff like the trait rewards from the rewards store and the trait rewards from completing aspirations. They're traits added through gameplay, so the game does not limit how many you can have.
Hidden traits are... hidden. They're not visible in the ui. They're stuff like the occult traits, species traits, age traits, and gender traits.
The trait tracker only enforces the 3 trait limit on personality traits, so you can add as many "gameplay" and "hidden" traits to a sim as you want.
#5
22nd Oct 2020 at 4:17 AM
Posts: 11
Thanks: 103 in 2 Posts
that makes sense. The type of trait would then be specified in the xml code for the trait right?
Lab Assistant
#6
22nd Oct 2020 at 9:33 AM
Posts: 137
Thanks: 4460 in 38 Posts
Quote: Originally posted by 13pigpen
that makes sense. The type of trait would then be specified in the xml code for the trait right? |
It's specified in 2 places.
The first is in the xml tuning for the trait and looks like this:
Code:
<E n="trait_type">GAMEPLAY</E>
The second is in the trait's "sim data" file and looks like this:
Code:
<T name="trait_type">1</T>
Personality traits have PERSONALITY as their trait type in the xml file, with 0 as their trait type in their simdata file.
You can extract a trait's tuning with Sims 4 Studio to get both the xml tuning and sim data tuning into a package file to look at.
Who Posted
|