- Site Map >
- Modding and Creation >
- Sims 3 Creation >
- Modding Discussion >
- The Code Snippet Jar!
- Site Map >
- Modding and Creation >
- Sims 3 Creation >
- Modding Discussion >
- The Code Snippet Jar!
#26
28th Jul 2022 at 10:15 AM
If you want sims to be able to talk with other sims around them while performing an interaction, place Actor.TryGroupTalk(true); or Actor.WaitAndGroupTalk(); in the loop.
Advertisement
#27
2nd Jan 2023 at 10:02 PM
Posts: 978
Thanks: 1929 in 13 Posts
You can change the color of visual effects. Here on my Grave Wound moodlet for Pet Fighting, I'm using the dripping effect from getting soak in a tomb in World Adventures and changing the color to red.
One thing to keep in mind that took me a while to figure out -- the color code is in RGB, but the scale is 0-1, not 0-255, which is what I was expecting. Any number higher than 1 will be treated as one.
(This is just the head effect. There are also dripping effects for arms and thighs. I'm pretty sure there's an actual dripping pet effect for dogs that go swimming in the pool. I don't know why I didn't use that one; I'll assume my past self knew what she was doing.)
Echo Weaver's Simblr: http://echoweaver.tumblr.com/
A portrait in stubbornness - Playing the same legacy since 2009
Sample a Brave Legacy: http://sims3sample.illation.net
One thing to keep in mind that took me a while to figure out -- the color code is in RGB, but the scale is 0-1, not 0-255, which is what I was expecting. Any number higher than 1 will be treated as one.
Code:
Vector3 fxColor = new Vector3(1f, 0f, 0f); // RGB for red mHeadFx = VisualEffect.Create("ep1SoakedDripsHead"); mHeadFx.ParentTo(owner, Sim.FXJoints.Head); mHeadFx.SetEffectColorScale(fxColor); mHeadFx.Start();
(This is just the head effect. There are also dripping effects for arms and thighs. I'm pretty sure there's an actual dripping pet effect for dogs that go swimming in the pool. I don't know why I didn't use that one; I'll assume my past self knew what she was doing.)
Echo Weaver's Simblr: http://echoweaver.tumblr.com/
A portrait in stubbornness - Playing the same legacy since 2009
Sample a Brave Legacy: http://sims3sample.illation.net
#28
4th Jan 2023 at 4:14 AM
Posts: 978
Thanks: 1929 in 13 Posts
I also thought I'd put this here from a different thread, since I just had to dig that thread up to check this information. This is about the order that the world events fire.
Echo Weaver's Simblr: http://echoweaver.tumblr.com/
A portrait in stubbornness - Playing the same legacy since 2009
Sample a Brave Legacy: http://sims3sample.illation.net
Quote: Originally posted by Lyralei
I should probably add this to the Code snippets thread, but gamefreak said this on the discord ages ago:
Quote:
|
Echo Weaver's Simblr: http://echoweaver.tumblr.com/
A portrait in stubbornness - Playing the same legacy since 2009
Sample a Brave Legacy: http://sims3sample.illation.net
#29
17th Apr 2023 at 3:54 AM
Posts: 268
Thanks: 1167 in 17 Posts
Code snippet to freeze/unfreeze a sims motive.
//Freezing motives for a sim
Code:
base.Actor.Motives.FreezeDecayEverythingExcept(); base.Actor.SimDescription.MotivesDontDecay = true;
//UnFreeze motives for a sim
Code:
base.Actor.Motives.RestoreDecays(); base.Actor.SimDescription.MotivesDontDecay = false;
#30
29th Apr 2023 at 5:02 PM
Last edited by Lyralei : 30th Apr 2023 at 11:19 AM.
Reason: forgot about spoiler
Posts: 3,860
Thanks: 8567 in 67 Posts
You need for science-y reasons get the item that has been placed down just now by a handtool, then this is the way to do it:
Code:
public class InstantiatorClass { World.OnObjectPlacedInLotEventHandler += CustomContentHelper.OnBuildBuy; } public static void OnBuildBuy(object sender, EventArgs args) { World.OnObjectPlacedInLotEventArgs onObjectPlacedInLotEventArgs = args as World.OnObjectPlacedInLotEventArgs; // This will get back the Game Object that has been placed. GameObject @object = GameObject.GetObject(onObjectPlacedInLotEventArgs.ObjectId); }
#31
6th May 2023 at 11:54 AM
Last edited by Lyralei : 7th May 2023 at 10:42 AM.
Posts: 3,860
Thanks: 8567 in 67 Posts
If you've worked with something like Unity before, you definitely understand how important it is to make your manager classes a Singleton (or, one instance per save). Though, for explanation:
Why should I use a singleton
When you have a class that generally takes care of everything in the world/save (called, a manager), you don't want 5 or even a thousand of those managers taking care of everything! One is, simply enough.
When to use a singleton
If you are thinking of making your class take care of the following things:
Generally speaking, you should see it sort of like this:
If you want a more in-depth talk, then this article helps (it's unity, but make sure to check my snippets of what's the sims equivelant of things): https://gamedevbeginner.com/singlet...-the-right-way/
NOTE: Shutdown, and Startup WILL work, despite not having derived the GameObject class.
EDIT: if "Startup()"doesn't 'start up' by itself, you can always call the function inside your "Onworldloadfinished"
Why should I use a singleton
When you have a class that generally takes care of everything in the world/save (called, a manager), you don't want 5 or even a thousand of those managers taking care of everything! One is, simply enough.
When to use a singleton
If you are thinking of making your class take care of the following things:
- Handles and curates everything that all sims/objects in the world should do (For example, for my Interest And Hobbies mod, it collects all sims in the world and figures out when to attach a new Interest to the sim depending on what they're doing)
- Handles world events.
- Handles any variables that count,
Generally speaking, you should see it sort of like this:
Quote:
Let's say, we have a GameObject (let's say, a chair), which is its own instance many times because we may have 200 chairs in the world. If we wanted to figure out per chair, how many times it's been sat on, then we want to do that per instance (aka, per chair). As one chair may be used more than the other. However, where a manager would be preferred, would be for something like gathering from all chairs, how often they've been sat on (or just a global count altogether). |
If you want a more in-depth talk, then this article helps (it's unity, but make sure to check my snippets of what's the sims equivelant of things): https://gamedevbeginner.com/singlet...-the-right-way/
Code:
public class EnergyManager { public static EnergyManager Instance { get; private set; } // We set it as private set, so nothing outside can re-set the instance/singleton. public EnergyManager() { EnergyManager singleton = Instance; } public static void Startup() // In unity terms this is "Awake" or "start" { if (Instance == null) { Instance = new EnergyManager(); } Instance.mShouldInflateDeflatePricesAlarm = AlarmManager.Global.AddAlarmRepeating(5, TimeUnit.Days, new AlarmTimerCallback(InflateDeflatePrices), 5f, TimeUnit.Days, "EnergyManager_Inflate_Deflate_Alarm", AlarmType.NeverPersisted, null); } public static void Shutdown() // In unity this isn't necessary, but for TS3's game engine we do need this. { if (Instance != null) { Instance.Dispose(); } Instance = null; } public void Dispose() // In unity terms this is "Destroy" { AlarmManager.Global.RemoveAlarm(mShouldInflateDeflatePricesAlarm); } }
NOTE: Shutdown, and Startup WILL work, despite not having derived the GameObject class.
EDIT: if "Startup()"doesn't 'start up' by itself, you can always call the function inside your "Onworldloadfinished"
#32
1st Jun 2023 at 6:44 AM
Posts: 268
Thanks: 1167 in 17 Posts
Code Snippet to check whether a sim is currently wearing a specific type of clothing. Can be CC or vanilla clothing
Code Snippet to retrieve the relationship number value between two sims and then compare it to a value
Code:
SimDescription simDescription = sim.SimDescription; if (sim.CurrentOutfitCategory == OutfitCategories.Everyday) { if (simDescription.GetOutfit(OutfitCategories.Everyday, 0).GetPartPreset(ResourceKey.FromString("0x034AEECB-0x00000000-0x5334BEA78911B570")) != null) { return true; } } else if (sim.CurrentOutfitCategory == OutfitCategories.Formalwear) { if (simDescription.GetOutfit(OutfitCategories.Formalwear, 0).GetPartPreset(ResourceKey.FromString("0x034AEECB-0x00000000-0x5334BEA78911B570")) != null) { return true; } return false; }
Code:
var rel = actor.SimDescription.GetRelationship(target.SimDescription, false); if ((rel != null && !(rel.CurrentLTRLiking >= 15))) { String message = "These two sims relationship value is 15 or more" }
#33
6th Aug 2023 at 12:50 PM
Posts: 156
Thanks: 1270 in 12 Posts
Checking whether a (script) mod is installed (regardless of it being instantiated):
To find the name of an assembly: Open the .package file containing the assembly with s3pe, click on the S3SA file, take the first value (the one that comes before Version) of FullName.
Code:
private static bool IsModInstalled { get { try { Assembly.Load("assembly name here"); //If the assembly (the S3SA file) doesn't exist, it will throw an exception in this line and thus jump to the catch block without returning true. //This method does not load a duplicate assembly, instead, it returns the existing assembly. return true; //If it does exist, it will continue without throwing an exception and it will return true. } catch { return false; } } }
#34
6th Aug 2023 at 4:11 PM
Posts: 3,860
Thanks: 8567 in 67 Posts
That's not a terrible way of doing it Eca! For Zoe's knitting mod, I did this instead in case you want to make it less exception dependant (And have multiple mods to check) which can be used OnAppStartup or OnWorldFinished:
Code:
AppDomain currentDomain = AppDomain.CurrentDomain; Assembly[] assems = currentDomain.GetAssemblies(); foreach(Assembly assembly in assems) { if(assembly.GetName().Name == "zoeoeKnitting") { IsYarnModByZoeInstalled = true; break; } }
Who Posted
|