Hi there! You are currently browsing as a guest. Why not create an account? Then you get less ads, can thank creators, post feedback, keep a list of your favourites, and more!
Quick Reply
Search this Thread
Field Researcher
Original Poster
#1 Old 5th Nov 2022 at 12:22 AM
Default How do I implement a condition whether sims have a custom trait?
I recently completed Arsil's tutorial on how to make a custom trait. However, I find myself lost on how to utilize this new tool.
Arsil's Custom Trait Tutorial

For my next project I wish to make a script mod which adds stretch marks to sims that have given birth. However, in real life not every individual inherets stretch marks. So, I wanted to make two custom hidden traits to act kind of like a DNA strand. One which will allow stretch marks to appear on sims after they have given birth and another which will filter out sims from getting stretch marks.

So, my question is how do I implement a condition for whether the sims have these custom traits?

I know in order to make a condition for the vanilla traits it goes like
Code:
if (sim.SimDescription.HasTrait(TraitNames.Insane)
{
EpicCodeApplies(sim)
}


However, I'm not entirely sure how to use custom traits as a condition in this case. I would just like to add a condition for the sim to have the Stretch Mark DNA strand on the code below.
Code:
private static ListenerAction OnHadBaby(Event e)
        {
			if (e.Actor is Sim sim)
            {
				if (sim.IsFemale && sim.SimDescription.TeenOrAbove && (Genealogy.IsParent(sim.SimDescription.Genealogy, sim.SimDescription.Genealogy)))
				{
					Simulator.AddObject(new OneShotFunctionTask(() => Helpers.FemaleStretchMarksOutfitSwap(sim)));
				}

			}
			return ListenerAction.Keep;
        }


Any help would be appreciated. Thank you all.
Advertisement
Field Researcher
#2 Old 6th Nov 2022 at 1:10 PM
To make HasTrait check for a custom instead of an EA trait, you just change from something like HasTrait(TraitNames.Insane) to HasTrait((TraitNames)hex-of-custom-trait) - for example, for the trait in Arsil's tutorial it'd be HasTrait((TraitNames)0x12DC32B0C3D9A022). It's the same for all the other cases I've found where you can add a custom entry to one of the game's enums: when you want to refer to it you write (name-of-enum)hex-of-custom-entry.
Field Researcher
Original Poster
#3 Old 6th Nov 2022 at 7:31 PM
Quote: Originally posted by lizcandor
To make HasTrait check for a custom instead of an EA trait, you just change from something like HasTrait(TraitNames.Insane) to HasTrait((TraitNames)hex-of-custom-trait) - for example, for the trait in Arsil's tutorial it'd be HasTrait((TraitNames)0x12DC32B0C3D9A022). It's the same for all the other cases I've found where you can add a custom entry to one of the game's enums: when you want to refer to it you write (name-of-enum)hex-of-custom-entry.


Thank you so much lizcandor. I will give this a shot when I get the chance.
Back to top