- Site Map >
- Modding and Creation >
- Sims 3 Creation >
- Modding Discussion >
- Setting an object to a preset by code
- Site Map >
- Modding and Creation >
- Sims 3 Creation >
- Modding Discussion >
- Setting an object to a preset by code
Replies: 5 (Who?), Viewed: 253 times.
#1
30th Jun 2022 at 8:03 AM
Posts: 224
Thanks: 997 in 7 Posts
Setting an object to a preset by code
Hi everyone,I am trying to set a gameobject to a BuildBuy preset, but I can't figure out how it is done.
I can't really imagine there is no way, somehow the game loads the presets when in build buy and applies them when clicking, right?
From what I can understand the presets are in the OBJD under Materials numbered from Materials[0] to Materials[7], they have to get loaded into the game as something.
If anyone can share any insights into this and if it just explaining how presets are build from an objects creators perspective so I can better understand I would be so happy.
Thank you and have a nice day
Snow
Advertisement
#2
30th Jun 2022 at 1:00 PM
Posts: 3,860
Thanks: 8567 in 67 Posts
Hey!
Zoe and I at sopme point went through this as well it's really not an easy one to figure out, but the sleeping bag does have a way to "select" presets in code (Assuming you mean like the pre-made colour items)
bascially, it's something like so:
I'm not 100% sure how it works, but this should give you a base to work with though
Zoe and I at sopme point went through this as well it's really not an easy one to figure out, but the sleeping bag does have a way to "select" presets in code (Assuming you mean like the pre-made colour items)
bascially, it's something like so:
Code:
SortedList<string, bool> sortedList = new SortedList<string, bool>(); SortedList<string, Complate> originalPatterns = Complate.ExtractPatterns(base.Target.ObjectId, sortedList); SleepingBag sleepingBag = base.Target as SleepingBag; if (sleepingBag != null) { sleepingBag.SetComplates(sortedList, originalPatterns); } // then just add this to your project: public void SetComplates(SortedList<string, bool> originalStencils, SortedList<string, Complate> originalPatterns) { bool flag = true; ResourceKey resourceKey = base.GetResourceKey(); ContentSourceType contentSource = DownloadContent.GetContentSource(resourceKey); if (contentSource == ContentSourceType.kContentType_Download) { string presetString = UserToolUtils.GetPresetString(resourceKey); ObjectDesigner.SetPresetInfo(base.ObjectId, presetString); flag = false; } if (flag) { ObjectDesigner.ClearObjectDesignPreset(base.ObjectId); } DesignModeSwap designModeSwap = Complate.SetupDesignSwap(base.ObjectId, originalPatterns, false, originalStencils); if (designModeSwap != null) { designModeSwap.ApplyToObject(); } }
I'm not 100% sure how it works, but this should give you a base to work with though
#3
30th Jun 2022 at 1:22 PM
Posts: 224
Thanks: 997 in 7 Posts
Ah so I was at the right class this morning when I was looking through designModeSwap. But I dismissed it for some reason. THANK YOU!!!!
#4
30th Jun 2022 at 1:36 PM
Posts: 224
Thanks: 997 in 7 Posts
One more question: how do i select which preset?
#5
30th Jun 2022 at 3:24 PM
Posts: 224
Thanks: 997 in 7 Posts
i have figured out everything except how to get a list of all presets ingame. So here is my a bit hacky method:
Add this to an interaction on the object you want to get the preset off or in the OnStartup() method (you need to change Target to this if you do).
Add the AddToXMLFile function as well:
Now buy the object ingame set it to the preset you want and run the interaction, or buy it in the preset you want.
You now have new file in you Ea games folder.
Copy everything in it and set a string variable to the content.
(You can remove the code in the interaction again, it has served its purpose)
Add this to you Object class:
YOUROBJECT needs to be a Gameobject of your object class:
Code:
WriteToXMLFile("Preset", ObjectDesigner.GetObjectDesignPreset(Target.ObjectId));
Add this to an interaction on the object you want to get the preset off or in the OnStartup() method (you need to change Target to this if you do).
Add the AddToXMLFile function as well:
Code:
public static void WriteToXMLFile(string fileName, string stuffToWrite) { uint num = 0u; string s = Simulator.CreateExportFile(ref num, fileName); if (num != 0) { CustomXmlWriter customXmlWriter = new CustomXmlWriter(num); customXmlWriter.WriteToBuffer(stuffToWrite); customXmlWriter.WriteEndDocument(); } }
Now buy the object ingame set it to the preset you want and run the interaction, or buy it in the preset you want.
You now have new file in you Ea games folder.
Copy everything in it and set a string variable to the content.
(You can remove the code in the interaction again, it has served its purpose)
Add this to you Object class:
Code:
public void SetComplates(SortedList<string, bool> originalStencils, SortedList<string, Complate> originalPatterns) { ObjectDesigner.SetPresetInfo(this.ObjectId, YOUrSTRINgVARIABLeWIThTHePRESEtCODE); DesignModeSwap designModeSwap = Complate.SetupDesignSwap(this.ObjectId, originalPatterns, false, originalStencils); if (designModeSwap != null) { designModeSwap.ApplyToObject(); } }
YOUROBJECT needs to be a Gameobject of your object class:
Code:
SortedList<string, bool> sortedList = new SortedList<string, bool>(); SortedList<string, Complate> originalPatterns = Complate.ExtractPatterns(YOUROBJECT.ObjectId, sortedList); YOUROBJECT.SetComplates(sortedList, originalPatterns);
#6
30th Jun 2022 at 6:01 PM
Posts: 224
Thanks: 997 in 7 Posts
So I figured out the not hacky method and it is pretty simple:
You can just copy and paste this
On your GameObject instance:
Example from my own code:
You can just copy and paste this
Code:
public void SetPreset(uint presetIndex) { uint index; index = (presetIndex > (this.mProduct.NumPresets -1)) ? 0 : presetIndex; SortedList<string, bool> sortedList = new SortedList<string, bool>(); SortedList<string, Complate> originalPatterns = Complate.ExtractPatterns(this.ObjectId, sortedList); ObjectDesigner.SetObject(this.ObjectId); ObjectDesigner.SetPresetInfo(this.ObjectId, ObjectDesigner.GetDesignPreset(index)); DesignModeSwap designModeSwap = Complate.SetupDesignSwap(this.ObjectId, originalPatterns, false, sortedList); if (designModeSwap != null) { designModeSwap.ApplyToObject(); } }
On your GameObject instance:
Code:
YOUrOBJECT.SetPreset(PRESEtNUMBER);
Example from my own code:
Code:
Sims.Gameplay.Objects.Snow.RecipeBag recipeBag = GlobalFunctions.CreateObjectOutOfWorld("SnowRecipeBag") as Sims.Gameplay.Objects.Snow.RecipeBag; recipeBag.SetPreset(20);
Who Posted
|