- Site Map >
- Modding and Creation >
- Sims 3 Creation >
- Modding Discussion >
- Spawning a Sim?
- Site Map >
- Modding and Creation >
- Sims 3 Creation >
- Modding Discussion >
- Spawning a Sim?
Posts: 1,500
Thanks: 4287 in 41 Posts
It's been a little bit overwhelming. Like how do I spawn a sim of a certain species, occult type, age, traits. And then there's sliders and stuff.
Does anyone have any experience on this and wish to share?
SimBuilder simBuilder = new SimBuilder(); SimOutfit outfit = new SimOutfit(mBaseOutfit.Key); OutfitUtils.SetOutfit(simBuilder, outfit, null); simBuilder.UseCompression = true; // Set AGS stringReport += "\n\nAGS is " + (mAgeGenderSpecies & CASAgeGenderFlags.AgeMask).ToString() + " " + (mAgeGenderSpecies & CASAgeGenderFlags.GenderMask).ToString() + " " + (mAgeGenderSpecies & CASAgeGenderFlags.SpeciesMask).ToString(); simBuilder.Age = mAgeGenderSpecies & CASAgeGenderFlags.AgeMask; simBuilder.Gender = mAgeGenderSpecies & CASAgeGenderFlags.GenderMask; simBuilder.Species = mAgeGenderSpecies & CASAgeGenderFlags.SpeciesMask; // Set skintone ResourceKey resourceKey2 = (simBuilder.SkinTone = mSkinToneKey); simBuilder.SkinToneIndex = mSkinToneIndex; stringReport += "\n\nSkintone is " + mSkinToneKey.ToString() + "" + mSkinToneIndex.ToString(); OutfitUtils.SetAutomaticModifiers(simBuilder); // Set clothing stringReport += "\n"; for (int i = 0; i < mCASParts.Length; i++) { CASPart part = mCASParts[i]; string preset = mCASPartPresets[i]; simBuilder.AddPart(part); stringReport += "\nAdded part for " + part.BodyType.ToString(); if (preset != null) { if (CASUtils.ApplyPresetToPart(simBuilder, part, preset)) { simBuilder.SetPartPreset(part.Key, null, preset); } } else { simBuilder.SetPartPreset(part.Key, null, string.Empty); } // Adjust hair color presets? AdjustPresetForHairColor(simBuilder, part); } stringReport += "\n\nSet " + mCASParts.Length.ToString() + " parts"; // Set hair color simBuilder.HairBaseColor = mHairBaseColor; simBuilder.HairHaloLowColor = mHairHaloLowColor; simBuilder.HairHaloHighColor = mHairHaloHighColor; stringReport += "\n\nSet hair color " + mHairBaseColor.ToString() + " " + mHairHaloLowColor.ToString() + " " + mHairHaloHighColor.ToString(); // Set morphs simBuilder.MorphFat = mMorphFat; simBuilder.MorphFit = mMorphFit; simBuilder.MorphThin = mMorphThin; simBuilder.SetSecondaryNormalMapWeights(mSecondaryNormalMapWeights); stringReport += "\n\nSet morphs " + mMorphFat.ToString() + " " + mMorphFit.ToString() + " " + mMorphThin.ToString(); // Set facial blends (sliders) for (int j = 0; j < mFacialBlends.Length; j++) { SimOutfit.BlendInfo blendInfo = mFacialBlends[j]; if (simBuilder.Age != CASAgeGenderFlags.Teen && blendInfo.key == OutfitUtils.sTeenHeightModifierKey) { simBuilder.SetFacialBlend(blendInfo.key, 0f); } else { simBuilder.SetFacialBlend(blendInfo.key, blendInfo.amount); } } stringReport += "\n\nSet " + mFacialBlends.Length.ToString() + " blends"; // Set curl info (for pets) simBuilder.NumCurls = mNumCurls; simBuilder.CurlPixelRadius = mCurlPixelRadius; simBuilder.FurMap = mFurMap; stringReport += "\n\nSet fur";
Posts: 433
Thanks: 792 in 6 Posts
public override bool Run() { var btnp = Sims3.UI.ThreeButtonDialog.Show("Alien Sex","Female","Male","Cancel"); if(btnp == Sims3.UI.ThreeButtonDialog.ButtonPressed.ThirdButton){return false;} CASAgeGenderFlags aAge = CASAgeGenderFlags.YoungAdult; SimDescription simDescription = Genetics.MakeAlien(aAge, (btnp==Sims3.UI.ThreeButtonDialog.ButtonPressed.FirstButton)?CASAgeGenderFlags.Female:CASAgeGenderFlags.Male, GameUtils.GetCurrentWorld(), 1f, true); simDescription.SkillManager.AddElement(SkillNames.Logic); simDescription.SkillManager.AddElement(SkillNames.Handiness); Skill element = simDescription.SkillManager.GetElement(SkillNames.Logic); if (element != null) { element.ForceSkillLevelUp(RandomUtil.GetInt(AlienUtils.kAlienHouseholdLogicSkill[0], AlienUtils.kAlienHouseholdLogicSkill[1])); } element = simDescription.SkillManager.GetElement(SkillNames.Handiness); if (element != null) { element.ForceSkillLevelUp(RandomUtil.GetInt(AlienUtils.kAlienHouseholdHandinessSkill[0], AlienUtils.kAlienHouseholdHandinessSkill[1])); } Household.AlienHousehold.AddSilent(simDescription); simDescription.OnHouseholdChanged(Household.AlienHousehold, false); var aliensim = simDescription.Instantiate(Hit.mPoint); aliensim.GreetSimOnLot(Actor.LotCurrent); return true; }
where Genetics.MakeAlien is the most important part you can adapt into your own method
Posts: 1,500
Thanks: 4287 in 41 Posts
Posts: 1,500
Thanks: 4287 in 41 Posts
Posts: 3,860
Thanks: 8576 in 67 Posts
@lizacandor @Battery if I want to copy from a bin Sim or a downloaded Sim. How can I access that Sim through code? |
I've done something similair for the RPG manager, and Bin sims are a whole other beast
I'm not sure what type of info you'd like to gather from them, but bin sims only contain the bare basics. With that I mean: Gender, name, traits, zodiac signs, what clothing they're wearing (including hair/makeup). So anything you can select inside CAS basically.
To get the descriptions, this is how I did it: https://github.com/Lyralei1/RPGMana...agerRPG.cs#L216
The most important part of this is:
ResKeyTable SimDescriptions = DownloadContent.GetImportedSimResourceKeys(false); if (SimDescriptions == null) { return null; } List<SimDescription> arrayList = new List<SimDescription>(); for (int i = 0; i < SimDescriptions.Count; i++) { ResourceKeyContentCategory resourceKeyContentCategory = ResourceKeyContentCategory.kInstalled; SimDescription simDescription = CASLogic.Instance.LoadSimDescription(SimDescriptions[i], ref resourceKeyContentCategory); if(simDescription == null) { continue; } SimDescription CopiedDescription = simDescription; // Do coding magic here.... }
However, if this returns null, you probably will have to import them and try again: https://github.com/Lyralei1/RPGMana...nagerRPG.cs#L24
Make sure to either only import the sims you need, or either all of them. Simply loop through: BinModel.Singleton.mExportBin,
bool flag = content.IsLoaded(); if (!flag && !mHasDoneHouseholdDownload) { content.Import(false); }
I do need to add that I'm still working out some weird bugs, like for example, you can't double import a household (household here is also simply one sim). Otherwise your list will be empty, despite it being already imported. Not sure if that's an EA side issue or me, but I'll have to check that myself :p
I know it's not much, but hopefully this helps! Went through quite a lot of sweat, tears and pain to get this even to remotely work lol... it's still hacky as hell but it's something!
Posts: 1,500
Thanks: 4287 in 41 Posts
I am still really confused though lol. But I think by studying your code it will give me an idea.
Posts: 433
Thanks: 792 in 6 Posts
I've done something similair for the RPG manager, and Bin sims are a whole other beast I'm not sure what type of info you'd like to gather from them, but bin sims only contain the bare basics. With that I mean: Gender, name, traits, zodiac signs, what clothing they're wearing (including hair/makeup). So anything you can select inside CAS basically. To get the descriptions, this is how I did it: https://github.com/Lyralei1/RPGMana...agerRPG.cs#L216 The most important part of this is:
Code:
ResKeyTable SimDescriptions = DownloadContent.GetImportedSimResourceKeys(false); if (SimDescriptions == null) { return null; } List<SimDescription> arrayList = new List<SimDescription>(); for (int i = 0; i < SimDescriptions.Count; i++) { ResourceKeyContentCategory resourceKeyContentCategory = ResourceKeyContentCategory.kInstalled; SimDescription simDescription = CASLogic.Instance.LoadSimDescription(SimDescriptions[i], ref resourceKeyContentCategory); if(simDescription == null) { continue; } SimDescription CopiedDescription = simDescription; // Do coding magic here.... } However, if this returns null, you probably will have to import them and try again: https://github.com/Lyralei1/RPGMana...nagerRPG.cs#L24 Make sure to either only import the sims you need, or either all of them. Simply loop through: BinModel.Singleton.mExportBin,
Code:
bool flag = content.IsLoaded(); if (!flag && !mHasDoneHouseholdDownload) { content.Import(false); } I do need to add that I'm still working out some weird bugs, like for example, you can't double import a household (household here is also simply one sim). Otherwise your list will be empty, despite it being already imported. Not sure if that's an EA side issue or me, but I'll have to check that myself :p I know it's not much, but hopefully this helps! Went through quite a lot of sweat, tears and pain to get this even to remotely work lol... it's still hacky as hell but it's something! |
Interesting when i tried something similar:
SimDescription SimDesc = null; CASLogic CASLogicSingleton = CASLogic.GetSingleton(); for (int i = 0; i < CASLogicSingleton.SimDescriptions.Count; i++) { ResourceKeyContentCategory category = ResourceKeyContentCategory.kInstalled; SimDescription simDescription = CASLogicSingleton.LoadSimDescription(CASLogicSingleton.SimDescriptions[i], ref category); if(simDescription.FirstName == "Anna") { SimDesc = new SimDescription(simDescription); break; } } if(SimDesc != null) { SimDesc.FirstName = "Anna 2"; SimDesc.LastName = Sim.ActiveActor.Household.Name; Sim.ActiveActor.Household.AddSilent(SimDesc); var outfit = SimDesc.GetOutfit(OutfitCategories.Swimwear,0); SimDesc.OnHouseholdChanged(Sim.ActiveActor.Household, false); Sim sim = SimDesc.Instantiate(Hit.mPoint); Sim.ActiveActor.Household.AddSim(sim); MessageUtil.ConversationNotification(sim,"Hi " + Actor.FirstName); }
i always needed to recreate the outfits is that different for you @Lyralei ?
Posts: 1,500
Thanks: 4287 in 41 Posts
SimDescription simDescription = GeneticsPet.MakeRandomPet(CASAgeGenderFlags.Adult, Actor.SimDescription.Gender, CASAgeGenderFlags.Cat); Sim sim = simDescription.Instantiate(Vector3.Empty); if (sim != null) { Actor.Household.Add(sim.SimDescription); InteractionInstance entry = BeenSummoned.Singleton.CreateInstance(Actor, sim, new InteractionPriority(InteractionPriorityLevel.RequiredNPCBehavior), false, false); sim.InteractionQueue.AddNext(entry); }
Posts: 433
Thanks: 792 in 6 Posts
if not heres a full run method, my assumption would be that you need to add it to some household before instantiation
public override bool Run() { try { SimDescription SimDesc = null; CASLogic CASLogicSingleton = CASLogic.GetSingleton(); for (int i = 0; i < CASLogicSingleton.SimDescriptions.Count; i++) { ResourceKeyContentCategory category = ResourceKeyContentCategory.kInstalled; SimDescription simDescription = CASLogicSingleton.LoadSimDescription(CASLogicSingleton.SimDescriptions[i], ref category); if(simDescription.FirstName == "Anna" && simDescription.IsHuman ) // Do filtering here { SimDesc = new SimDescription(simDescription); break; } } if(SimDesc != null) { SimDesc.FirstName = "Anna"; // Rename if necessary SimDesc.LastName = Sim.ActiveActor.Household.Name; // Rename if necessary Sim.ActiveActor.Household.AddSilent(SimDesc); // Add to household SimDesc.OnHouseholdChanged(Sim.ActiveActor.Household, false); // Fire household event if desired SimTools.RefreshOutfits(SimDesc); //Maybe not needed for you (and unreleased ...= Sim sim = SimDesc.Instantiate(Hit.mPoint); //Instantiate at last MessageUtil.ConversationNotification(sim,"Hi " + Actor.FirstName); } } catch(Exception e) { Debug.ShowException(e); } return true; }
Posts: 3,860
Thanks: 8576 in 67 Posts
(This line I mean: )
SimDescription simDescription = CASLogicSingleton.LoadSimDescription(CASLogicSingleton.SimDescriptions[i], ref category);
There are a few problems though with the code logistically:
- Indeed, the description cannot be empty. So make sure to check for null references there, just in case. (also because it makes debugging easier)
- As battery said, the sim should be in a household. Even if it's the NPC household for the moment (or one you create specifically temporarily, through code). Otherwise, the cleanup code will nuke your sim immediately.
- You're currently creating the sim off-screen. While we, the player, see the world edges, the world itself is actually a bit bigger than what we see. The Vector3.Empty (also known as Vector3.Zero) in this case is basically under the terrain and completely away from the terrain.
- Because your sim is being instantiated off-screen, it finds itself possibly either getting destroyed by nraas (the game does this too, but on a later date, Nraas is just more consistent there). OR, the interaction is failing because something inside the generic interaction checking has gone wrong (meaning, not your own Test() function, but the one EA has set in place for bare basic checking, such as if the sim is in the world, inside a household).
i always needed to recreate the outfits is that different for you @Lyralei ? |
Technically, I didn't really have to deal with that for the RPG manager itself (since all I did was change the money value for the household), but I have had to do that in the past. That's probably because a lot of that data is covered inside the Sim class.
Because, something to remember is that the SimDescription === the sim's brain. the Sim class === the physical being of said sim.
That's why NPCs (maids, repairman, etc) for example, keep switching from ghosty (I guess with my logic, brainy but bodyless) beings. And therefore need to have their entire beings re-instantiated once they re-visit the world.
Also! I was thinking, it may be worth checking how Bonehilda is being spawned in. That's how I figured out how to instantiate sims
Posts: 1,500
Thanks: 4287 in 41 Posts
I thought simply doing this
SimDescription simDescription = GeneticsPet.MakeRandomPet(CASAgeGenderFlags.Adult, Actor.SimDescription.Gender, CASAgeGenderFlags.Cat);
will create a randomized cat sim description. But I guess that was just wishful thinking and the actual process is a lot more complicated. I am going to keep researching and working on it.
Posts: 1,500
Thanks: 4287 in 41 Posts
How can I add to NPC household instead of Actor Sim's household?
And is there a way to permanently invite a Sim into your household? The summoned sim will only be here temporarily tbf (moodlet based)but I wanted to know if I can have like many minon summoned spirits that aren't part of the household. Kinda like Bonehilda.
Posts: 433
Thanks: 792 in 6 Posts
OMG it's working. My cat spawned in. @Lyralei @Battery How can I add to NPC household instead of Actor Sim's household? |
Household.NpcHousehold.Add(YourSim);
Also you could look into the roommate code if thats the direction you wanted to go .
Posts: 1,500
Thanks: 4287 in 41 Posts
I will look into roommate code.
Posts: 3,860
Thanks: 8576 in 67 Posts
Code:
Household.NpcHousehold.Add(YourSim); Also you could look into the roommate code if thats the direction you wanted to go . |
Quick note though on that! Some people may have roommates turned as an option in their save (In fact I believe it's even a thing in Nraas' settings). So then nothing basically happens. I wouldn't rely on it... I made that mistake with the randomizer mod lol... just to save you the bug reports.
Posts: 1,500
Thanks: 4287 in 41 Posts
I am also interested in changing skin tone and outfit of a spawned Sim. How do I find out ID of skin tone? Like Red Skin that came with Supernatural for eg. And the Buisness Suit and Tie Outfit or Butler outfit from Late Night.
I'm going to do more research on it.
Posts: 433
Thanks: 792 in 6 Posts
@Lyralei and @Battery I am also interested in changing skin tone and outfit of a spawned Sim. How do I find out ID of skin tone? Like Red Skin that came with Supernatural for eg. And the Buisness Suit and Tie Outfit or Butler outfit from Late Night. I'm going to do more research on it. |
I am currently working of an update of the utility mod. these methods could be implemented without much trouble since they are already used as part of other already existing methods, so if using the utility is still an option for you let me know and i can speed up the process to a release within the next few days
You can use the simbuilder to set the outfit of an sim and then access the SkinTone property to get the reskey (the id you have been asking for)
you can change that in the same process. To change the SkinToneIndex you can use the very same method but use the SkinToneIndex property instead.
Posts: 1,500
Thanks: 4287 in 41 Posts
Thank you so much for replying.
Posts: 433
Thanks: 792 in 6 Posts
Cool yea Script Utility would be cool. This is for my Enhanced Witches mod which already uses it. reskey? Ok I will look at it. Thank you so much for replying. |
Hi PuddingFace, i have attached a new version of the utility mod
Unfortunately ive broken every other mod in the process since i changed the namespace from Battery to Battery.Utility i will keep the old version up but if you want to take the oportunity while working on your mod to update this could save you some headaches.
I know this is a inconvenience, so if yo need help with anything let me know
Here are the Methods you might be interested in
Get a list of all installed skins
List<ResourceKey> AllInstalledSkins = Battery.Utility.ResourceUtil.GetInstalledSkintones();
Set Skintoneindex for Sim
Battery.Utility.SimTools.SetSkintoneIndexAndSkin(Sim sim, Nullable<ResourceKey> SkinKey, Nullable<float> SkinToneIndex); //example just set skintone: using Battery.Utility.; ... SimTools.SetSkintoneIndexAndSkin(Sim.ActiveActor, null, 1f); // will set the skintone index to 1 and does not change the Skin
Set Skintoneindex for Sim as addin for Simbuilder process
Battery.Utility.SimTools.SetSkintoneIndexAndSkin(SimBuilder builder, Nullable<ResourceKey> SkinKey, Nullable<float> SkinToneIndex); //example just set skintone: using Battery.Utility.; ... SimTools.SetSkintoneIndexAndSkin(builder, null, 1f); // will set the skintone index to 1 and does not change the Skin
Battery_Utility_1.041.package.7z (767.3 KB, 0 downloads) |
Posts: 1,500
Thanks: 4287 in 41 Posts
Posts: 1,500
Thanks: 4287 in 41 Posts
I plan on using Genetics.MakeSim instead of GeneticsPet.MakePet
Specificially, this method:
MakeSim(SimBuilder builder, CASAgeGenderFlags age, CASAgeGenderFlags gender, ResourceKey skinTone, float skinToneIndex, Color[] hairColors, WorldName homeWorld, uint outfitCategoriesToBuild, bool isAlien)
My main issue is ResourceKey skinTone, float skinToneIndex, Color[] hairColors and uint outfitCategoriesToBuild. Like how do I find out what to put in those spaces? S3oc?
Posts: 433
Thanks: 792 in 6 Posts
Hi @Battery @Lyralei I have come back to this I already added animal familiar summoning in the previous update. And now I am looking to make Demon Summoning. So Make human Sim summons. I plan on using Genetics.MakeSim instead of GeneticsPet.MakePet Specificially, this method: MakeSim(SimBuilder builder, CASAgeGenderFlags age, CASAgeGenderFlags gender, ResourceKey skinTone, float skinToneIndex, Color[] hairColors, WorldName homeWorld, uint outfitCategoriesToBuild, bool isAlien) My main issue is ResourceKey skinTone, float skinToneIndex, Color[] hairColors and uint outfitCategoriesToBuild. Like how do I find out what to put in those spaces? S3oc? |
Well i would create a sim that just looks like the demon you want to create and then look at its data.
Posts: 1,500
Thanks: 4287 in 41 Posts
Posts: 433
Thanks: 792 in 6 Posts
Ah ok thank you! I will try this. |
in case you were unsure what to put into the color array heres the decoding:
index | HairType |
---|---|
0-3 | Main Hair |
4 | Eyebrow |
5-8 | Facial Hairs |
9 | Body Hair |
for the outfitCategoriesToBuild just put in the outfitcategories you want to use like (uint)(OutfitCategories.Naked|OutfitCategories.Everyday|OutfitCategories.Formalwear|OutfitCategories.Sleepwear ) etc
Who Posted
|