#2
27th Sep 2021 at 11:15 AM
Last edited by Lyralei : 27th Sep 2021 at
11:15 AM.
Reason: Woops screwed up the bbcode
Posts: 3,856
Thanks: 8483 in 67 Posts
28 Achievements
Hrm sounds complicated but doable. I actually did something similair for the sewing machine (where gifted items would later be 'worn' by the target).
What I did:
Code:
public static void SetUpAlarmForGiftedItems()
{
// Get CASP resource file from resource key: (Check whether the type and group is correct for you!!)
CASPart outfit = new CASPart(new ResourceKey(ResourceKey.FromString("CLOTHING NAME HERE"), 0x0333406C, 0x7354C1FC));
// I know I don't have a sim parameter or anything set, since I used an alarm, but basically, compare the age with the current target and the gender
if (outfit.Age == sim.Simdescription.mSimDescription.Age && outfit.Gender == sim.Simdescription.mSimDescription.Gender)
{
// This works more on an anonymous level, otherwise the target wasn't changing into their clothing. You may want to research the dresser, change outfit function if this isn't really working for you
ApplyGiftedSewingsToOutfits(outfit , sim);
OutfitCategories currentOutfitCategory = sim.CurrentOutfitCategory;
alarmTarget.RefreshCurrentOutfit(true);
alarmTarget.SwitchToOutfitWithoutSpin(sim.CurrentOutfitCategory);
}
}
// ClothingCategory is a bit version of the clothing categories (Everyday, formal, etc)
public static uint[] ClothingCategory =
{
2,
4,
8,
16,
32,
256,
};
// Modified but almost identical to the face paint code
public static void ApplyGiftedSewingsToOutfits(CASPart casPart, Sim desc)
{
List<uint> possibleOutfits = new List<uint>();
foreach (uint cat in ClothingCategory)
{
if ((casPart.CategoryFlags & cat) == cat)
{
//print("Match made! CAT: " + cat.ToString());
possibleOutfits.Add(cat);
}
}
// I did this since my top and skirts were possible for almost all categories. if you just want to apply it to one category, then simply remove the switch statement, the 'getrandomobject' function and set 'OutfitCategories cat = OutfitCategories.Everyday' or whatever category it needs to be
if (possibleOutfits.Count > 0)
{
uint randomed = RandomUtil.GetRandomObjectFromList(possibleOutfits);
OutfitCategories cat = OutfitCategories.None;
switch (randomed)
{
case 2:
{
cat = OutfitCategories.Everyday;
break;
}
case 4:
{
cat = OutfitCategories.Formalwear;
break;
}
case 8:
{
cat = OutfitCategories.Sleepwear;
break;
}
case 16:
{
cat = OutfitCategories.Swimwear;
break;
}
case 32:
{
cat = OutfitCategories.Athletic;
break;
}
case 256:
{
cat = OutfitCategories.Makeover;
break;
}
default:
{
cat = OutfitCategories.Everyday;
break;
}
}
SimBuilder simBuilder = new SimBuilder();
simBuilder.UseCompression = true; // funnily enough doesn't matter, since the game will always set a false 'UseCompression' back to true :p
simBuilder.Age = desc.mSimDescription.Age;
SimOutfit outfit = desc.mSimDescription.GetOutfit(cat, 0);
OutfitUtils.SetOutfit(simBuilder, outfit, desc.mSimDescription);
OutfitUtils.SetAutomaticModifiers(simBuilder);
simBuilder.RemoveParts(casPart.BodyType);
OutfitUtils.AddPartAndPreset(simBuilder, casPart, false);
ResourceKey key = simBuilder.CacheOutfit(string.Format("NAMEITWHATEVER_{0}_{1}_{2}", simBuilder.Age, desc.FirstName, cat));
SimOutfit outfit2;
if (OutfitUtils.TryGenerateSimOutfit(key, out outfit2))
{
desc.mSimDescription.RemoveOutfit(cat, 0, true);
desc.mSimDescription.AddOutfit(outfit2, cat, 0);
}
simBuilder.Dispose();
}
}
And voila! You got yourself some code that does what you want!
of course if you're curious about some part of the code, just lemme know! Since this stuff was pretty confusing for me too when I worked with it :p