- Site Map >
- Modding and Creation >
- Sims 3 Creation >
- Modding Discussion >
- C# Script Utility Overview
- Site Map >
- Modding and Creation >
- Sims 3 Creation >
- Modding Discussion >
- C# Script Utility Overview
Replies: 13 (Who?), Viewed: 2636 times.
#1
16th Oct 2021 at 8:53 PM
Last edited by Battery : 30th Sep 2022 at 8:25 PM.
Posts: 433
Thanks: 792 in 6 Posts
C# Script Utility Overview
Mod Page:What is the C# Script Utility ?
The C# Script Utility is a Library of Methods and Classes, which can be referenced and used in Script mods to implement somewhat complex features in a simpler way. This has the benefit that you dont have to create everything yourself and you can reference this utility instead of re implementing these features in every new mod.
Please do not answer on this thread, since it is work in Progress (and unsorted at the moment)
If you Have questions or you want to discuss something about the mod:
0: write a post on this mods discussion Thread
1: Write me a Private Message
2: Use the Mods Comments for short questions/suggestions
1: Write me a Private Message
2: Use the Mods Comments for short questions/suggestions
Table of Content
Other Tutorials and References
Installation
Sharp Develop
Visual Studio
Visual Studio
Sims 3 Script Extender Overview (S3SE)
The Overview for the Script Extender Part of the C# Script Utility
Auto Menu
Lets Players set values which were exposed by you (similar to NRaas retuner) Does NOT require the C# Utility to be referenced (so it is optional)
Artificial Neural Network Application (ANNA)
Use Anna to do Inference with your own Artificial Neural Network
Saving/loading Settings
Create a simple menu that lets the player Load / Save your custom Objects
Serializing Objects
Examples: Serializing Objects
Deserializing Saved Objects
Examples: Deserializing Saved Objects
Adding Interactions
Methods to Add Interactions to GameObjects
SimTools
Getting the real age of a sim
Modifying a sims Facial sliders
Modifying a sims Facial sliders
RemoteUtil
Methods that allow you to access other mods functionality without the need of referencing them
GetLoadedScriptmods
IsScriptModInstalled
CallStaticMethod
GetStaticMethodDelegate
CreateObject
CreateListfromType
CreateDictionaryfromType
GetInteractionDefinition
GetNestedInteractionDefinition
ListQueries
This is a LINQ inspired collection of methods that contains IList collection Queries
HasAny
CountItems
WhereItems
Union
Attached files:
ScriptUtility serializing Objects Example.7z (16.0 KB, 19 downloads) | |
ScriptUtility deserializing Objects Example.7z (17.3 KB, 9 downloads) |
Advertisement
#2
16th Oct 2021 at 8:57 PM
Last edited by Battery : 24th Oct 2021 at 5:38 PM.
Posts: 433
Thanks: 792 in 6 Posts
Attachments:
Attached files:
ScriptUtility using the Auto Menu.7z (11.5 KB, 23 downloads) | |
ScriptUtility Serialization Menu Example.7z (6.8 KB, 12 downloads) |
#3
16th Oct 2021 at 9:23 PM
Last edited by Battery : 22nd Oct 2021 at 8:53 PM.
Posts: 433
Thanks: 792 in 6 Posts
Installation:
Step 1
Put the C# Script Utility package somewhere in the packages folder
Step 2
Extract the DLL from the .package file
Step 3
3A Steps for Sharp Develop:
(1) Add the extracted utility dll to your Project by right clicking References
(2) select Add Reference
(3) in the new window go to the .Net Assembly Browser tab
(4) Click Browse...
(5) select the extracted Battery.Utility.dll on your drive, then finish by clicking OK
3B Steps for Visual Studio:
Step 4
You should now be able to access the Utility by start typing batt and the autocomplete should suggest the “Battery” Namespace
Step 1
Put the C# Script Utility package somewhere in the packages folder
Step 2
Extract the DLL from the .package file
Step 3
3A Steps for Sharp Develop:
(1) Add the extracted utility dll to your Project by right clicking References
(2) select Add Reference
(3) in the new window go to the .Net Assembly Browser tab
(4) Click Browse...
(5) select the extracted Battery.Utility.dll on your drive, then finish by clicking OK
3B Steps for Visual Studio:
Step 4
You should now be able to access the Utility by start typing batt and the autocomplete should suggest the “Battery” Namespace
#4
16th Oct 2021 at 10:40 PM
Last edited by Battery : 24th Oct 2021 at 5:39 PM.
Posts: 433
Thanks: 792 in 6 Posts
Auto Menu
Example Solution and package File
Usage: Lets Players set values which were exposed by you (similar to NRaas retuner) Does NOT require the C# Utility to be referenced (so it is optional)
To expose your mod to the auto menu you need to take the following steps:
0. name your assemblyname so it includes "_b_" in the name somewhere (example testmod could become _b_testmod or testmod_b_)
1. name the values you want to expose like in step 0
Note: The values need to be static !
The user can then change the values with an Terrain Interaction path Battery... -> Mod Auto Menu
Change the Assembly Name Sharp Develop:
Change the Assembly Name Visual Studio:
Example:
Note: If you expose a static field that holds an class instance you can change all the cointained settings
Example Solution and package File
Usage: Lets Players set values which were exposed by you (similar to NRaas retuner) Does NOT require the C# Utility to be referenced (so it is optional)
To expose your mod to the auto menu you need to take the following steps:
0. name your assemblyname so it includes "_b_" in the name somewhere (example testmod could become _b_testmod or testmod_b_)
1. name the values you want to expose like in step 0
Note: The values need to be static !
The user can then change the values with an Terrain Interaction path Battery... -> Mod Auto Menu
Change the Assembly Name Sharp Develop:
Change the Assembly Name Visual Studio:
Example:
Code:
public class Someclass { public static MyExposedString_b_ = "Hello"; }
Note: If you expose a static field that holds an class instance you can change all the cointained settings
Code:
public class ContainerClass { public int number; public float floatingpointnumber; } public class Someclass { public static ContainerClass_b_ = new ContainerClass(); // Users will be able to set number AND floatingpointnumber }
#5
16th Oct 2021 at 10:48 PM
Last edited by Battery : 27th Dec 2021 at 4:55 PM.
Posts: 433
Thanks: 792 in 6 Posts
Anna
Battery.AI.Anna
Anna LoadFromXML(string InstanceName)
Usage: Creates an Artificial Neural Network Application by parsing an xml containing a trained model
void ExportToXML(string Name)
Usage: Exports the current model to xml
Parameter:
string Name the string the assembly you want to check for needs to have
double[] Compute(params double[] input)
Usage: Computes the output with the current model
Parameter:
double[] input the normalized inputs as doubles
To ComputeClassification<To>(IList<To> PossibleOutputs, params double[] inputs)
Usage: Computes the output with the current model and assignes the most probable output
Parameter:
IList<To> PossibleOutputs the list to choose results from
params double[] inputs the normalized inputs as doubles
Battery.AI.Anna
Anna LoadFromXML(string InstanceName)
Usage: Creates an Artificial Neural Network Application by parsing an xml containing a trained model
void ExportToXML(string Name)
Usage: Exports the current model to xml
Parameter:
string Name the string the assembly you want to check for needs to have
double[] Compute(params double[] input)
Usage: Computes the output with the current model
Parameter:
double[] input the normalized inputs as doubles
To ComputeClassification<To>(IList<To> PossibleOutputs, params double[] inputs)
Usage: Computes the output with the current model and assignes the most probable output
Parameter:
IList<To> PossibleOutputs the list to choose results from
params double[] inputs the normalized inputs as doubles
#6
16th Oct 2021 at 10:50 PM
Last edited by Battery : 24th Oct 2021 at 11:43 AM.
Posts: 433
Thanks: 792 in 6 Posts
Export_Import
(Creating a simple menu that lets the player Load / Save your custom Objects)
Example Solution and package File
Battery.Export_Import
0 Create a method to handle the imported string
1 Create a method to export our object
2. Creating the Menu
3. Adding the Menu options
4. Opening our Menu
(Creating a simple menu that lets the player Load / Save your custom Objects)
Example Solution and package File
Battery.Export_Import
0 Create a method to handle the imported string
Code:
public static void OnImportSettings(string import) { if(!string.IsNullOrEmpty(import)) //check if there is a string at all to work with { try //optinoal but i recommend wrappingt he actual method in a try catch block { UserSettings sett = Export_Import.Deserialize<UserSettings>(import); //this will create an object of type UserSettings from the import string Main.mOptionen = sett; //Store the Settings somewhere } catch(Exception e) { Debug.ShowException(e); //if there is an error show it to the user (optional) } } }
1 Create a method to export our object
Code:
public static void ExportMySettings() { try { string export = Main.mOptionen.ToExportString(); //This will serialize(convert) mOptionen into a string and store it in "export" Export_Import.ExportObject("CreatorName","Modname",false, true, export); //The actual exporting happens here } catch(Exception e) { Debug.ShowException(e); } }
2. Creating the Menu
Code:
public static MenuContainer SerializationMenu; //Somewhere in your project SerializationMenu = new MenuContainer("MenuTitle") //Create a new Menu
3. Adding the Menu options
Code:
MenuGetter ImportSavedSettings = MenuContainer.Presets.CreateFileImportMenu_S3SE("CreatorName", "Modname", OnImportSettings); //Create The Menu to Import Settings performActionOption ExportSettings = new performActionOption("Export Settings", ExportMySettings); //Create an clickable option that will export your settings MenuSelectionOption SelectImportSavedSettings = new MenuSelectionOption("Import Settings", ImportSavedSettings ); //Add an option to the main menu that opens our Import Menu SerializationMenu.AddMenuObject(SelectImportSavedSettings,true,"SelectImportSavedSettings"); // Add the opening of the import menu to our menu SerializationMenu.AddMenuObject(ExportSettings,true,"ExportSettings"); // Add the exportoption to our menu
4. Opening our Menu
Code:
Battery.UI.Menus.MenuController.Show(SerializationMenu); //This will bring up the menu we created before
#7
17th Oct 2021 at 5:20 PM
Last edited by Battery : 23rd Oct 2021 at 9:40 PM.
Posts: 433
Thanks: 792 in 6 Posts
Export_Import
(Serializing Objects)
Battery.Export_Import
string ToExportString<T>(this T objecttoexport)
Usage: Converts an object into a serialized string, it is used like the ToString method
Note 0: This works only with classes that have a parameterless constructor and do NOT contain cyclical references*
Note 1: The Default Serializer is not capable of converting cyclical references
Example:
Overloads:
string ToExportString<T>(this T objecttoexport, bool MarkedOnly)
//This Serializes only Fields marked with the [MarkExportable] attribute
string ToExportString<T>(this T objecttoexport, bool MarkedOnly, BindingFlags flags)
//This Serializes only Fields marked with the [MarkExportable] attribute and the given BindingFlags
string ToExportString<T>(this T objecttoexport, bool MarkedOnly, BindingFlags flags, Dictionary<Type,ICustomSerializer> CustomSerializer)
//This Serializes only Fields marked with the [MarkExportable] attribute and the given BindingFlags you can supply a dictionary that allows you to serialize arbitrary types
Parameters:
bool MarkedOnly if this is set to true it will only serialize objects decorated with the [MarkExportable] attribute, Default setting false (this will serialize fields not marked with [MarkExportable(false)]
BindingFlags flags define the Bindingflags which a field needs to have in order to be serialized (default 62), example value "BindingFlags.Static|BindingFlags.Public" will only serialize fields which are public and static
Dictionary<Type,ICustomSerializer> CustomSerializer supply custom serialization instructions
interface ICustomSerializer
Usage: This can be used in conjunction with ToExportString to serialize/deserialize cyclical references or create objects without an parameterless constructor
Example: Serializing a field of type Vector3
(Serializing Objects)
Battery.Export_Import
string ToExportString<T>(this T objecttoexport)
Usage: Converts an object into a serialized string, it is used like the ToString method
Note 0: This works only with classes that have a parameterless constructor and do NOT contain cyclical references*
Note 1: The Default Serializer is not capable of converting cyclical references
Example:
Code:
UserSettings MySettings = new UserSettings (); string serialized = MySettings.ToExportString(); //saves/serializes the Data of MySettings into the string serialized
Overloads:
string ToExportString<T>(this T objecttoexport, bool MarkedOnly)
//This Serializes only Fields marked with the [MarkExportable] attribute
string ToExportString<T>(this T objecttoexport, bool MarkedOnly, BindingFlags flags)
//This Serializes only Fields marked with the [MarkExportable] attribute and the given BindingFlags
string ToExportString<T>(this T objecttoexport, bool MarkedOnly, BindingFlags flags, Dictionary<Type,ICustomSerializer> CustomSerializer)
//This Serializes only Fields marked with the [MarkExportable] attribute and the given BindingFlags you can supply a dictionary that allows you to serialize arbitrary types
Parameters:
bool MarkedOnly if this is set to true it will only serialize objects decorated with the [MarkExportable] attribute, Default setting false (this will serialize fields not marked with [MarkExportable(false)]
BindingFlags flags define the Bindingflags which a field needs to have in order to be serialized (default 62), example value "BindingFlags.Static|BindingFlags.Public" will only serialize fields which are public and static
Dictionary<Type,ICustomSerializer> CustomSerializer supply custom serialization instructions
interface ICustomSerializer
Code:
public interface ICustomSerializer { void Serialize(object objecttoserialize, BindingFlags flags, int Rekursion, Export_Import.SerializationData sData); object Deserialize(Type objectType, string source, int Rekursion, Export_Import.SerializationData sData); }
Usage: This can be used in conjunction with ToExportString to serialize/deserialize cyclical references or create objects without an parameterless constructor
Example: Serializing a field of type Vector3
Code:
public class Vector3_Serializer : ICustomSerializer { public void Serialize(object objecttoserialize, BindingFlags flags, int Rekursion, Export_Import.SerializationData sData) { Vector3 v = ((Vector3)objecttoserialize); //cast the object to Vector3 sData.mExportString.Append(v.x+","+v.y+","+v.z); //add the important information x, y ,z to our Exportstring and seperate them with "," } public object Deserialize(Type objectType, string source, int Rekursion, Export_Import.SerializationData sData) { string[] result = source.Split(','); //get the data seperated by "," return new Vector3(float.Parse(result[0]),float.Parse(result[1]) ,float.Parse(result[2])); //Create a new Vector with the 3 Axis values x,y,z } }
#8
22nd Oct 2021 at 8:44 PM
Last edited by Battery : 23rd Oct 2021 at 9:40 PM.
Posts: 433
Thanks: 792 in 6 Posts
(Example: Serializing Objects)
Example Solution and package File
Simple Example
0.Create the class that holds our Settings
1.Create an instance of our object and serialize it using ToExportString
Simple Example(only serialize some fields)
0.Create the class that holds our Settings
1.Create an instance of our object and serialize it using ToExportString
Advanced Example(using custom Serializing instructions)
0.Create the class that holds our Settings
1.Create custom serialization instructions for Vector3
2.Serialize our instance with the help of our custom serializer
Example Solution and package File
Simple Example
0.Create the class that holds our Settings
Code:
public class UserSettings { public string UserName; public int UserAge; public List<string> Friends = new List<string>(); public UserSettings() //Needs to have a parameterless Constructor { } }
1.Create an instance of our object and serialize it using ToExportString
Code:
UserSettings settings = new UserSettings(); // create an instance of our class settings.UserName = "SomeName"; //change some of the settings settings.UserAge = 23; //change some of the settings settings.Friends.Add("Friend1"); //change some of the settings settings.Friends.Add("Friend2"); //change some of the settings string exported = settings.ToExportString(); //Convert (serialize) our object into a string
Simple Example(only serialize some fields)
0.Create the class that holds our Settings
Code:
public class UserSettings { public string UserName; [MarkExportable(false)] //This Field will not be serialized/ converted to string public int UserAge; public List<string> Friends = new List<string>(); public UserSettings() //Needs to have a parameterless Constructor { } }
1.Create an instance of our object and serialize it using ToExportString
Code:
UserSettings settings = new UserSettings(); // create an instance of our class settings.UserName = "SomeName"; //change some of the settings settings.UserAge = 23; //change some of the settings Note this wont be exported settings.Friends.Add("Friend1"); //change some of the settings settings.Friends.Add("Friend2"); //change some of the settings string exported = settings.ToExportString(); //Convert (serialize) our object into a string
Advanced Example(using custom Serializing instructions)
0.Create the class that holds our Settings
Code:
public class UserSettings { public string UserName; public int UserAge; public Vector3 SomePosition; // Contains cyclical references will throw an error if not handled with special instructions public UserSettings() //Needs to have a parameterless Constructor { } }
1.Create custom serialization instructions for Vector3
Code:
public class Vector3_Serializer : ICustomSerializer { public void Serialize(object objecttoserialize, BindingFlags flags, int Rekursion, Export_Import.SerializationData sData) { Vector3 v = ((Vector3)objecttoserialize); // we need to cast our object to the desired type sData.mExportString.Append(v.x+","+v.y+","+v.z); //sData.mExportString is the export string add to it by using the Append method } public object Deserialize(Type objectType, string source, int Rekursion, Export_Import.SerializationData sData) { var result = source.Split(','); return new Vector3(float.Parse(result[0]),float.Parse(result[1]) ,float.Parse(result[2])); } }
2.Serialize our instance with the help of our custom serializer
Code:
UserSettings settings = new UserSettings(); // create an instance of our class settings.UserName = "SomeName"; //change some of the settings settings.SomePosition = new Vector3(1,2,3); //change some of the settings settings.Friends.Add("Friend1"); //change some of the settings settings.Friends.Add("Friend2"); //change some of the settings Dictionary<Type,ICustomSerializer> CustomSerializerInstructions = new Dictionary<Type, ICustomSerializer>(); //Create a dictionary with custom instructions CustomSerializerInstructions.Add(typeof(Vector3), new Vector3_Serializer()); //Add our custom instructions to the dictionary targeted at Vector3 (typeof(Vector3)) string exported = settings.ToExportString(false, (BindingFlags)62, CustomSerializerInstructions); //Convert (serialize) our object into a string with our dictionary
#9
22nd Oct 2021 at 8:50 PM
Last edited by Battery : 23rd Oct 2021 at 9:41 PM.
Posts: 433
Thanks: 792 in 6 Posts
Export_Import
(Deserializing Saved Objects)
Battery.Export_Import
T Deserialize<T>(string ExportString)
Usage: Converts the string created with ToExportString back into an Object (cant deserialize a static class therefore)
Overloads:
T Deserialize<T>(string ExportString, Dictionary<Type,ICustomSerializer> CustomSerializer)
//This creates an object from the ExportString using a custom serialization dictionary
Parameter:
string ExportString the settings previously serialized to a string
Dictionary<Type,ICustomSerializer> CustomSerializer
(Deserializing Saved Objects)
Battery.Export_Import
T Deserialize<T>(string ExportString)
Usage: Converts the string created with ToExportString back into an Object (cant deserialize a static class therefore)
Code:
UserSettings MySettingsReserialized = Deserialize<UserSettings>(serialized); //where serialized is the string we created with ToExportString
Overloads:
T Deserialize<T>(string ExportString, Dictionary<Type,ICustomSerializer> CustomSerializer)
//This creates an object from the ExportString using a custom serialization dictionary
Parameter:
string ExportString the settings previously serialized to a string
Dictionary<Type,ICustomSerializer> CustomSerializer
#10
23rd Oct 2021 at 9:41 PM
Posts: 433
Thanks: 792 in 6 Posts
(Example: Deserializing Saved Objects)
Example Solution and package File
Simple Example
0. Using an Example Container class
1. Deserialize our exportstring
Advanced Example
0. Using an Example Container class
1.Create custom serialization instructions for Vector3
2. Deserialize our exportstring
Example Solution and package File
Simple Example
0. Using an Example Container class
Code:
public class UserSettings { public string UserName; public int UserAge; public List<string> Friends = new List<string>(); public UserSettings() //Needs to have a parameterless Constructor { } }
1. Deserialize our exportstring
Code:
UserSettings deserialized = Export_Import.Deserialize<UserSettings >(exported); // create an object instance of type UserSettings back from our serialized string
Advanced Example
0. Using an Example Container class
Code:
public class UserSettings { public string UserName; public int UserAge; public Vector3 SomePosition; // Requires Special instructions since Vector3 contains cyclical references see Advanced Saving Objects example public UserSettings() //Needs to have a parameterless Constructor { } }
1.Create custom serialization instructions for Vector3
Code:
public class Vector3_Serializer : ICustomSerializer { public void Serialize(object objecttoserialize, BindingFlags flags, int Rekursion, Export_Import.SerializationData sData) { Vector3 v = ((Vector3)objecttoserialize); // we need to cast our object to the desired type sData.mExportString.Append(v.x+","+v.y+","+v.z); //sData.mExportString is the export string add to it by using the Append method } public object Deserialize(Type objectType, string source, int Rekursion, Export_Import.SerializationData sData) //Implement deserialization method { var result = source.Split(','); return new Vector3(float.Parse(result[0]),float.Parse(result[1]) ,float.Parse(result[2])); } }
2. Deserialize our exportstring
Code:
Dictionary<Type,ICustomSerializer> CustomSerializerInstructions = new Dictionary<Type, ICustomSerializer>(); //Create a dictionary with custom instructions CustomSerializerInstructions.Add(typeof(Vector3), new Vector3_Serializer()); //Add our custom instructions to the dictionary targeted at Vector3 (typeof(Vector3)) UserSettings deserialized = Export_Import.Deserialize<UserSettings >(exported, CustomSerializerInstructions); // create an object instance of type UserSettings back from our serialized string using Custom Instructions on how to deserialize the type Vector3
#11
1st Nov 2021 at 10:57 AM
Last edited by Battery : 1st Nov 2021 at 11:14 AM.
Posts: 433
Thanks: 792 in 6 Posts
InteractionsUtility
(Adding Interactions)
Battery.Interactions.InteractionsUtility
void AddInteraction(GameObject o, InteractionDefinition Singleton)
Usage: Adds the Interactiondefinition "Singleton" to the Gameobject "o"
Note 0 : Will check for duplicates
Note 1 : Only Adds the Interaction Once Objects entering the Gameworld after this Method was called are unaffected (you need to use that method on the new Object again if you want it to have the interaction)
Example:
void AddinteractionToObjectsOfType<type>(InteractionDefinition Singleton)
Usage: Adds the Interactiondefinition "Singleton" to all GameObjects of type "type"
Note 0 : Will check for duplicates
Note 1 : Only Adds the Interaction Once . Objects entering the Gameworld after this method was called are unaffected (you need to use that method on the new Object again if you want it to have the interaction)
Example:
Overloads:
void AddinteractionToObjectsOfType<type>(InteractionDefinition Singleton, bool IsInventoryInteractionOnly, bool AddInventoryInteraction=false)
Parameter:
<type> the GameObjecttype you want to add the interactions to examples: ( Sim, ICityHall, Computer )
InteractionDefinition Singleton the InteractionDefinition to Add
bool IsInventoryInteractionOnly Set true if this is only an inventory Interaction
bool AddInventoryInteraction=false Set true if this is also an inventory Interaction
void AddTerrainnteraction(InteractionDefinition Singleton)
Usage: Adds the Interactiondefinition "Singleton" to the Terrain
Note 0 : Will check for duplicates
Note 1 : Only Adds the Interaction Once Objects entering the Gameworld after this Method was called are unaffected (you need to use that method on the new Object again if you want it to have the interaction)
Example:
(Adding Interactions)
Battery.Interactions.InteractionsUtility
void AddInteraction(GameObject o, InteractionDefinition Singleton)
Usage: Adds the Interactiondefinition "Singleton" to the Gameobject "o"
Note 0 : Will check for duplicates
Note 1 : Only Adds the Interaction Once Objects entering the Gameworld after this Method was called are unaffected (you need to use that method on the new Object again if you want it to have the interaction)
Example:
Code:
AddInteraction(Sim.ActiveActor, MyInteractionDefinition) // Adds MyInteractionDefinition to the currently active sim
void AddinteractionToObjectsOfType<type>(InteractionDefinition Singleton)
Usage: Adds the Interactiondefinition "Singleton" to all GameObjects of type "type"
Note 0 : Will check for duplicates
Note 1 : Only Adds the Interaction Once . Objects entering the Gameworld after this method was called are unaffected (you need to use that method on the new Object again if you want it to have the interaction)
Example:
Code:
AddinteractionToObjectsOfType<Sim>(MyInteractionDefinition) // Adds MyInteractionDefinition to every sim currently in the world
Overloads:
void AddinteractionToObjectsOfType<type>(InteractionDefinition Singleton, bool IsInventoryInteractionOnly, bool AddInventoryInteraction=false)
Parameter:
<type> the GameObjecttype you want to add the interactions to examples: ( Sim, ICityHall, Computer )
InteractionDefinition Singleton the InteractionDefinition to Add
bool IsInventoryInteractionOnly Set true if this is only an inventory Interaction
bool AddInventoryInteraction=false Set true if this is also an inventory Interaction
void AddTerrainnteraction(InteractionDefinition Singleton)
Usage: Adds the Interactiondefinition "Singleton" to the Terrain
Note 0 : Will check for duplicates
Note 1 : Only Adds the Interaction Once Objects entering the Gameworld after this Method was called are unaffected (you need to use that method on the new Object again if you want it to have the interaction)
Example:
Code:
AddTerrainnteraction(MyTerrainInteractionDefinition) // Adds MyInteractionDefinition to the Terrain
#12
20th Nov 2021 at 7:08 PM
Last edited by Battery : 20th Nov 2021 at 9:23 PM.
Posts: 433
Thanks: 792 in 6 Posts
SimTools
(Converting the Age of a sim to real world years)
Battery.SimTools
float GetAgeInRealYears(Sim s,float MaxBabyAge=1f, float MaxToddlerAge=4f, float MaxChildAge=13f, float MaxTeenAge=19f, float MaxYoungAdultAge=35f, float MaxAdultAge=60f, float NormalLifeTime=86f)
Usage: Converts the Sims age to its real world age in years
Note 0 : Only works for human sims
Example:
float GetPetAgeInRealYears(Sim s, float MaxChildCatAge = 1f, float MaxAdultCatAge = 7f, float MaxNormalCatLifeTime = 12f, float MaxChildDogAge = 1f, float MaxAdultDogAge = 9f, float MaxNormalDogLifeTime = 12f, float MaxChildHorseAge = 3f, float MaxAdultHorseAge = 15f, float MaxNormalHorseLifeTime = 20f)
Usage: Converts the Sims age to its real world age in years
Note 0 : Only works for pets
Example:
(Modifying a sims facial/body sliders)
Battery.SimTools.Slider
float Get_Value(Sim sim, Sliders slider)
Usage: returns the slider value of the given slider and sim
Note 0 : It is highly recommended to use "Tasks" i nconjunction with setting sliders so your game wont stall while the sliders are set
Overloads:
float Get_Value(Sim sim, ResourceKey key)
Parameter:
Sim sim the Sim whoms slider value you want to obtain
Sliders slider the slider whichs value you want to obtain
ResourceKey key the resourcekey of the slider whichs value you want to obtain
bool mod_Value(Sim sim, float ModifyBy, Sliders slider)
Usage: modifies the FacialSlider value of the given sim by the given amount
Overloads:
bool mod_Value(Sim sim, float ModifyBy, ResourceKey key)
bool mod_Value(Sim sim,string ResourceKeyString, float ModifyBy)
Parameter:
Sim sim the Sim whoms slider value you want to modify
float ModifyBy the value you want to alter the given slider by
Sliders slider the slider whichs value you want to modify
ResourceKey key the resourcekey of the slider whichs value you want to modify
string ResourceKeyString the resourcekey of the slider you want to modify as string
bool Set_Value(Sim sim, Sliders slider, float value)
Usage: Sets the FacialSlider value of the given sim to the given amount
Example:
Example (Task):
Overloads:
bool Set_Value(Sim sim,string ResourceKeyString, float value)
bool Set_Value(Sim sim, ResourceKey key, float value)
Parameter:
Sim sim the Sim whoms slider value you want to modify
float value the value you want to set the given slider to
ResourceKey key the resourcekey of the slider whichs value you want to modify
(Converting the Age of a sim to real world years)
Battery.SimTools
float GetAgeInRealYears(Sim s,float MaxBabyAge=1f, float MaxToddlerAge=4f, float MaxChildAge=13f, float MaxTeenAge=19f, float MaxYoungAdultAge=35f, float MaxAdultAge=60f, float NormalLifeTime=86f)
Usage: Converts the Sims age to its real world age in years
Note 0 : Only works for human sims
Example:
Code:
int Age = (int)GetAgeInRealYears(Sim.ActiveActor);
float GetPetAgeInRealYears(Sim s, float MaxChildCatAge = 1f, float MaxAdultCatAge = 7f, float MaxNormalCatLifeTime = 12f, float MaxChildDogAge = 1f, float MaxAdultDogAge = 9f, float MaxNormalDogLifeTime = 12f, float MaxChildHorseAge = 3f, float MaxAdultHorseAge = 15f, float MaxNormalHorseLifeTime = 20f)
Usage: Converts the Sims age to its real world age in years
Note 0 : Only works for pets
Example:
Code:
int Age = (int)GetPetAgeInRealYears(Sim.ActiveActor);
(Modifying a sims facial/body sliders)
Battery.SimTools.Slider
float Get_Value(Sim sim, Sliders slider)
Usage: returns the slider value of the given slider and sim
Note 0 : It is highly recommended to use "Tasks" i nconjunction with setting sliders so your game wont stall while the sliders are set
Overloads:
float Get_Value(Sim sim, ResourceKey key)
Parameter:
Sim sim the Sim whoms slider value you want to obtain
Sliders slider the slider whichs value you want to obtain
ResourceKey key the resourcekey of the slider whichs value you want to obtain
bool mod_Value(Sim sim, float ModifyBy, Sliders slider)
Usage: modifies the FacialSlider value of the given sim by the given amount
Overloads:
bool mod_Value(Sim sim, float ModifyBy, ResourceKey key)
bool mod_Value(Sim sim,string ResourceKeyString, float ModifyBy)
Parameter:
Sim sim the Sim whoms slider value you want to modify
float ModifyBy the value you want to alter the given slider by
Sliders slider the slider whichs value you want to modify
ResourceKey key the resourcekey of the slider whichs value you want to modify
string ResourceKeyString the resourcekey of the slider you want to modify as string
bool Set_Value(Sim sim, Sliders slider, float value)
Usage: Sets the FacialSlider value of the given sim to the given amount
Example:
Code:
Battery.SimTools.Slider.Set_Value(Sim.ActiveActor, Sliders.NoseLength, 0.5f) //Sets the ActiveActors Noselength to 0.5
Example (Task):
Code:
Battery.Threading.Task_GenericAction.Start(()=> { Battery.SimTools.Slider.Set_Value(Sim.ActiveActor, Sliders.NoseLength, 0.5f) //Sets the ActiveActors Noselength to 0.5, will not stall the game when run in Battery.Threading.Task_GenericAction.Start });
Overloads:
bool Set_Value(Sim sim,string ResourceKeyString, float value)
bool Set_Value(Sim sim, ResourceKey key, float value)
Parameter:
Sim sim the Sim whoms slider value you want to modify
float value the value you want to set the given slider to
ResourceKey key the resourcekey of the slider whichs value you want to modify
#13
27th Dec 2021 at 3:25 PM
Last edited by Battery : 6th Jan 2022 at 7:41 PM.
Posts: 433
Thanks: 792 in 6 Posts
RemoteUtil
Battery.RemoteUtil
List<string> GetLoadedScriptmods()
Usage: returns a list with the names of the currently loaded assemblies
bool IsScriptModInstalled(string ModName)
Usage: returns true if an assemblie with the given name was found among the loaded assemblies
Overloads:
bool IsScriptModInstalled(string ModName, bool ExactName)
Parameter:
string ModName the string the assembly you want to check for needs to have
bool ExactName set true if the parameter ModName should be the exact name rather than a part of the assembly you want to check for
object CallStaticMethod(string typeName, string methodName, Type[] ArgumentTypes, params object[] methodArgs)
Usage: call a static method of another mod.
Parameter:
string typeName this is the type which contains the method you want to call Namespace.Typename, Assemblyname e.g. "Battery.UI.CustomizableNotification, Battery.Utility" //I am using the utility here since you need to use it anyways (you could call it directly this is just an example but any other mod should do too)
string methodName the name of the method you want to call e.g. "Show" //CustomizableNotification has a method called Show
Type[] ArgumentTypes an array of the parameter types the method you want to call takes e.g. new Type[]{typeof(string)} /// CustomizableNotification.Show has an overload that takes one string as parameter
params object[] methodArgs an array of the parameters you want to pass to the method e.g. new object[]{"hallo"} // passing the string "hallo"
Example:
object CallInstanceMethod(object Instance, string methodName, Type[] ArgumentTypes, params object[] methodArgs)
Usage: see method "CallStaticMethod" above, just for instances
Parameter:
object Instance the instance of the object whichs method you want to call
... see method "CallStaticMethod" above
TDelegate GetStaticMethodDelegate<TDelegate>(Type t, string MethodName)
Usage: creates a a delegate of type TDelegate to a static method of type t (use this isntead of CallStaticMethod if you want to call the method more than once [since its about 50x faster after the first call]
Parameter:
<TDelegate> the type of the delegate you want to create (this ofcourse has to match the method you want to call)
Type t the type which contains the method you want to call)
string MethodName the name of the method you want to call)
Type[] ArgumentTypes an array of the parameter types the method you want to call takes
Example:
object CreateObject(string typeName, params object[] ctorArgs)
Usage: creates an instance of the given runtime type
Parameter:
string typeName this is the type which contains the method you want to call Namespace.Typename, Assemblyname
params object[] ctorArgs the parametes the constructor takes
System.Collections.IList CreateListfromType(Type t)
Usage: creates a List from the given runtime types
Parameter:
Type t the type which the list should contain
System.Collections.IDictionary CreateDictionaryfromType(Type KeyType, Type ValueType)
Usage: creates a Dictionary from the given runtime types
Parameter:
Type KeyType the type of the Keys
Type ValueType the type of the values
InteractionDefinition GetInteractionDefinition(string FullNamespace, string InteractionClassName, string Assemblyname, string InteractionSingletonName)
Usage: get the InteractionDefinition of another assembly
Parameter:
string FullNamespace the full namespace
string InteractionClassName the name of the Interactionclass
string Assemblyname the name of the Assembly
string InteractionSingletonName the name of the Interaction singleton (needs to have a singelton to work)
InteractionDefinition GetNestedInteractionDefinition(string FullNamespace, string Assemblyname, string InteractionSingletonName, params string[] ClassNames)
Usage: get the InteractionDefinition of another assembly with a nested class
Parameter:
string FullNamespace the full namespace
string InteractionClassName the name of the Interactionclass
string Assemblyname the name of the Assembly
string InteractionSingletonName the name of the Interaction singleton (needs to have a singelton to work)
params string[] ClassNames the classed from top level to the containing class
Example:
Battery.RemoteUtil
List<string> GetLoadedScriptmods()
Usage: returns a list with the names of the currently loaded assemblies
bool IsScriptModInstalled(string ModName)
Usage: returns true if an assemblie with the given name was found among the loaded assemblies
Overloads:
bool IsScriptModInstalled(string ModName, bool ExactName)
Parameter:
string ModName the string the assembly you want to check for needs to have
bool ExactName set true if the parameter ModName should be the exact name rather than a part of the assembly you want to check for
object CallStaticMethod(string typeName, string methodName, Type[] ArgumentTypes, params object[] methodArgs)
Usage: call a static method of another mod.
Parameter:
string typeName this is the type which contains the method you want to call Namespace.Typename, Assemblyname e.g. "Battery.UI.CustomizableNotification, Battery.Utility" //I am using the utility here since you need to use it anyways (you could call it directly this is just an example but any other mod should do too)
string methodName the name of the method you want to call e.g. "Show" //CustomizableNotification has a method called Show
Type[] ArgumentTypes an array of the parameter types the method you want to call takes e.g. new Type[]{typeof(string)} /// CustomizableNotification.Show has an overload that takes one string as parameter
params object[] methodArgs an array of the parameters you want to pass to the method e.g. new object[]{"hallo"} // passing the string "hallo"
Example:
Code:
Battery.RemoteUtil.CallStaticMethod("Battery.Abductor.APIMethods, Battery.Abductor", "AbductSim", new Type[]{typeof(Sim)}, new object[]{Sim.ActiveActor}); //Calls Battery.Abductor.APIMethods.AbductSim(Sim.ActiveActor);
object CallInstanceMethod(object Instance, string methodName, Type[] ArgumentTypes, params object[] methodArgs)
Usage: see method "CallStaticMethod" above, just for instances
Parameter:
object Instance the instance of the object whichs method you want to call
... see method "CallStaticMethod" above
TDelegate GetStaticMethodDelegate<TDelegate>(Type t, string MethodName)
Usage: creates a a delegate of type TDelegate to a static method of type t (use this isntead of CallStaticMethod if you want to call the method more than once [since its about 50x faster after the first call]
Parameter:
<TDelegate> the type of the delegate you want to create (this ofcourse has to match the method you want to call)
Type t the type which contains the method you want to call)
string MethodName the name of the method you want to call)
Type[] ArgumentTypes an array of the parameter types the method you want to call takes
Example:
Code:
Delegate_Generic<bool,Sim,Sliders,float> SetSliderDelegate; SetSliderDelegate = RemoteUtil.GetStaticMethodDelegate<Delegate_Generic<bool, Sim, Sliders, float>>(typeof(SimTools.Slider), "Set_Value", new Type[]{typeof(Sim), typeof(Sliders),typeof(float)}); SetSliderDelegate (Sim.ActiveActor, Sliders.NoseLength, 2f); // call the delegate whenever its needed
object CreateObject(string typeName, params object[] ctorArgs)
Usage: creates an instance of the given runtime type
Parameter:
string typeName this is the type which contains the method you want to call Namespace.Typename, Assemblyname
params object[] ctorArgs the parametes the constructor takes
System.Collections.IList CreateListfromType(Type t)
Usage: creates a List from the given runtime types
Parameter:
Type t the type which the list should contain
System.Collections.IDictionary CreateDictionaryfromType(Type KeyType, Type ValueType)
Usage: creates a Dictionary from the given runtime types
Parameter:
Type KeyType the type of the Keys
Type ValueType the type of the values
InteractionDefinition GetInteractionDefinition(string FullNamespace, string InteractionClassName, string Assemblyname, string InteractionSingletonName)
Usage: get the InteractionDefinition of another assembly
Parameter:
string FullNamespace the full namespace
string InteractionClassName the name of the Interactionclass
string Assemblyname the name of the Assembly
string InteractionSingletonName the name of the Interaction singleton (needs to have a singelton to work)
InteractionDefinition GetNestedInteractionDefinition(string FullNamespace, string Assemblyname, string InteractionSingletonName, params string[] ClassNames)
Usage: get the InteractionDefinition of another assembly with a nested class
Parameter:
string FullNamespace the full namespace
string InteractionClassName the name of the Interactionclass
string Assemblyname the name of the Assembly
string InteractionSingletonName the name of the Interaction singleton (needs to have a singelton to work)
params string[] ClassNames the classed from top level to the containing class
Example:
Code:
InteractionDefinition playchessdef = GetNestedInteractionDefinition("Sims3.Gameplay.Objects.Electronics", "Sims3GameplayObjects", "Singleton", new string[]{"Computer", "PlayChess"})
#14
30th Sep 2022 at 8:10 PM
Last edited by Battery : 2nd Oct 2022 at 5:55 PM.
Posts: 433
Thanks: 792 in 6 Posts
ListQueries
Battery
bool HasAny<T>(this IList<T> source, Predicate<T> condition)
Usage: Checks if the Ilist collection has at least one element matching the condition
Parameter:
IList<T> source The Collection to check
Predicate<T> condition The condition that must be met by any element
Example:
int CountItems<T>(this IList<T> source, Predicate<T> condition)
Usage: counts all Items in the Ilist collection matching the condition
Parameter:
IList<T> source The Collection to check
Predicate<T> condition The condition that must be met by any element
Example:
List<T> WhereItems<T>(this IList<T> source, Predicate<T> condition)
Usage: Returns a List of Elements matching the defined conditions
Parameter:
IList<T> source The Collection to check
Predicate<T> condition The condition that must be met by any element
Example:
List<T> Union<T>(this IList<T> IlistOne, IList<T> UnionWith)
Usage: Returns a complimentary list of the items from two IList collections
Parameter:
IList<T> IlistOne The Collection to check
IList<T> UnionWith The other IList collection to use
Example:
Battery
bool HasAny<T>(this IList<T> source, Predicate<T> condition)
Usage: Checks if the Ilist collection has at least one element matching the condition
Parameter:
IList<T> source The Collection to check
Predicate<T> condition The condition that must be met by any element
Example:
Code:
List<int> mylist = new List<int>(); mylist.AddRange(1,2,4); bool hasAThree = mylist.HasAny(x=> x==3); // will be false
int CountItems<T>(this IList<T> source, Predicate<T> condition)
Usage: counts all Items in the Ilist collection matching the condition
Parameter:
IList<T> source The Collection to check
Predicate<T> condition The condition that must be met by any element
Example:
Code:
List<int> mylist = new List<int>(); mylist.AddRange(1,2,4); int NumbersSmallerThan4 = mylist.CountItems(x => x<4); // NumbersSmallerThan4 = 2
List<T> WhereItems<T>(this IList<T> source, Predicate<T> condition)
Usage: Returns a List of Elements matching the defined conditions
Parameter:
IList<T> source The Collection to check
Predicate<T> condition The condition that must be met by any element
Example:
Code:
List<int> mylist = new List<int>(); mylist.AddRange(1,2,4); List<int> NumbersSmallerThan4 = mylist.WhereItems(x => x<4); // The List will contain 1,2
List<T> Union<T>(this IList<T> IlistOne, IList<T> UnionWith)
Usage: Returns a complimentary list of the items from two IList collections
Parameter:
IList<T> IlistOne The Collection to check
IList<T> UnionWith The other IList collection to use
Example:
Code:
List<int> mylist = new List<int>(); mylist.AddRange(1,2,4); List<int> myotherlist = new List<int>(){1,3,5}; List<int> Combined = mylist.Union(myotherlist ); // Combined List 1,2,3,4,5
Who Posted
|