Search this Thread |
![]() |
![]() |
lizcandor
Original Poster
|
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 ![]() [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. |
|
Last edited by lizcandor : 24th Aug 2020 at 6:03 PM.
|
![]() |
#2 |
Lyralei
|
Interesting stuffs! Thanks for sharing it :DÂ*I'll use this for my own research as well! |
|
|
![]() |
#3 |
Armise |
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. |
|
|
![]() |