- Site Map >
- Modding and Creation >
- Sims 3 Creation >
- Modding Discussion >
- [RESOLVED, added solution details]AddElement not working with custom hidden traits
- Site Map >
- Modding and Creation >
- Sims 3 Creation >
- Modding Discussion >
- [RESOLVED, added solution details]AddElement not working with custom hidden traits
Replies: 3 (Who?), Viewed: 624 times.
#1
24th Aug 2020 at 3:38 PM
Last edited by lizcandor : 24th Aug 2020 at 5:03 PM.
[RESOLVED, added solution details]AddElement not working with custom hidden traits
Has anyone had any luck with adding custom hidden traits programmatically, not just adding them manually in-game? I've created them using Arsil's mod and I can add them with MC, but using
Code:
or simDescription.TraitManager.AddHiddenElement((TraitNames)hex-code)
Code:
(which should be the same as each other) in a script just doesn't work for some reason (returns false and fails to add the trait). AddElement does work for custom non-hidden traits (including one of the exact same traits I'm having trouble with now, before I changed its category in my traits XML to "none" to make it hidden) and default hidden traits (as a test I added a line right below the one for adding my trait that should add Pizza Appreciator, which worked). So it seems like the issue is specifically with the combination of AddElement and a hidden trait not in the TraitNames enum, not a problem with AddElement, hidden traits, or custom traits in general or with the surrounding code.simDescription.TraitManager.AddElement((TraitNames)hex-code, hidden: true, doFail: false)
I've seen a few older posts by Armise (the only other person who I know for sure has tried this ) about making a mod with custom hidden traits using Arsil's mod, just like I am - it's been a couple years now, but @Armise I'd be interested to know if you also ran into this? No pressure though, I'm just wondering if the problem is something I specifically did or something about custom hidden traits made like this in general - in which case I may make my hidden traits into reward traits instead.
[EDIT: Wait a minute, right after writing this it occurred to me that what I should do is check how MC adds traits, since I know for certain that MC 1) is a script mod and 2) has a method that is able to add these traits to sims. Sometimes the process of asking a question stimulates your mind to find your own answer, I guess. I'll try imitating MC (which also uses AddHiddenElement, but appears to be more careful about getting the trait guid than I am) and update if that works.]
[EDIT 2: Okay, adding a new method that runs this code (borrowed almost verbatim from MC's ChangeTrait class), and using that method to add the traits instead of just AddHiddenElement by itself worked:]
Code:
Trait trait = TraitManager.GetTraitFromDictionary(traitName); int iTraitsForBabiesAndToddlers = TraitManager.kTraitsForBabiesAndToddlers; int iTraitsForChildren = TraitManager.kTraitsForChildren; int iTraitsForTeens = TraitManager.kTraitsForTeens; int iTraitsForYoungAdultAndOlder = TraitManager.kTraitsForYoungAdultAndOlder; try { // Don't use MaxValue as EA adds to this number for [[University]] purposes TraitManager.kTraitsForBabiesAndToddlers = 10000000; TraitManager.kTraitsForChildren = 10000000; TraitManager.kTraitsForTeens = 10000000; TraitManager.kTraitsForYoungAdultAndOlder = 10000000; if (trait.IsHidden) { sim.SimDescription.TraitManager.AddHiddenElement(traitName); } else { sim.SimDescription.AddTrait(trait); } } finally { TraitManager.kTraitsForBabiesAndToddlers = iTraitsForBabiesAndToddlers; TraitManager.kTraitsForChildren = iTraitsForChildren; TraitManager.kTraitsForTeens = iTraitsForTeens; TraitManager.kTraitsForYoungAdultAndOlder = iTraitsForYoungAdultAndOlder; }
From also looking into AddElement in ILSpy, I figured out that what this means is adding the trait failed before because the sims I was using it on already had their trait slots maxed out. I didn't think that would be a problem for a hidden trait, but apparently it is, at least as long as that trait has age species availability flags specified - if I remove the age/species availability restrictions from the traits XML entries for the traits in question, just using AddHiddenElement instead of the code above works fine. Conclusion: trait slot limitations do in fact apply to hidden traits; so in my mod I will just leave the age/species restrictions off, make sure the code that applies the trait doesn't run on non-human or age-inappropriate sims, and use AddHiddenElement.
Advertisement
#2
26th Aug 2020 at 3:31 PM
Posts: 3,860
Thanks: 8537 in 67 Posts
Interesting stuffs! Thanks for sharing it :D I'll use this for my own research as well!
#3
26th Nov 2020 at 10:48 PM
Posts: 46
Yeah so I don't log in here often, so sorry for the late reply.
No, I don't remember running in problems with adding traits, but I had another model to copy : the other occult classes, which all apply the corresponding hidden trait to the sim in each specific way. I don't remember the exact method call of course.
No, I don't remember running in problems with adding traits, but I had another model to copy : the other occult classes, which all apply the corresponding hidden trait to the sim in each specific way. I don't remember the exact method call of course.
#4
16th Nov 2022 at 4:54 AM
Posts: 268
Thanks: 1166 in 17 Posts
Thank you so much lizcandor. You are a legit boss. I was looking into adding hidden traits via an immediate interactions and thanks to your findings I was able to pull it off.
Who Posted
|