Search this Thread |
![]() |
![]() |
Lyralei
Original Poster
|
The sims 3, it's a bit of a confusing... thing when you first start making a script mod for it. What the hell is the difference between "Sim" and "SimDescription"? Or "What was the code again for a simple notification? *scrolls massively*". That's basically how the idea was created between Zoeoe and me. So most of the credits go to her too, for the creation of this thread! Well, this thread will have covered with simple snippets as to what and when to use something, so both advanced, as well as beginners, can enjoy from it! ![]() I've got some good ones to include!Â* Make sure to list yours in such a way as shown below. Just so that everything is more organised and easier to find. If you've got an alternative way or even an easier way of doing a particular function, then it's totally fine to share this too, but preferably label these as "Alternative:" or "My way:" Or something like that ![]() Make sure however, not to copy paste your entire script or class. A simple function is fine though! ![]() What this thread isn't for: This is not a thread about how to fix your code or errors. If there's any errors you encounter and you need help, make sure to create a thread to ask that particular question. Your reply will get deleted/moved as a new thread. Of course, exceptions are for if any snippets happen to have a spelling mistake and it needs to be pointed outÂ* ![]() This thread is also not about asking questionsÂ* Snippet time! NOTIFICATIONS: All the notification Styles: kSimTalking kSystemMessage kGameMessagePositive kGameMessageNegative kDebugAlert kCustom kCelebrityUpdate |
|
Last edited by Lyralei : 13th Apr 2020 at 3:45 PM.
|
![]() |
#2 |
zoe22
|
Set game speed: Adding an alarm to an object: Remove an alarm on an object: Check if sim is in active household: Modify sim's household funds: Add to sim's household bills: Destroy an object in the game: |
|
|
![]() |
#3 |
Battery
|
If you need to need to get a translation Key directly from the game (for Resourceallergics like myself) you can use this If you need to Run an Action so that it doesnt block the main thread you can use this thats all im willing to share for now (thats actually more than i originally wanted to share), since i still need to sell my Script Utility Mod where these snippets are from, to some unsuspecting Modders.. and i did post a whole class. lets see if Lyralei notices |
|
Last edited by Battery : 8th Mar 2020 at 11:10 PM.
|
![]() |
#4 |
Battery
|
Enable Extension Methods in SharpDevelop |
|
|
![]() |
#5 |
Lyralei
Original Poster
|
Standard Statemachine setup, which you can use in run(): |
|
|
![]() |
#6 |
Lyralei
Original Poster
|
Make item stackable in inventory, this is also EA's default way of doing this: Making the object an inventory-enabled (aka, being able to be stored in inventories) Available types you can use for this:
|
|
Last edited by Lyralei : 18th Apr 2020 at 12:44 PM.
|
![]() |
#7 |
Lyralei
Original Poster
|
A snippet that makes it easier to figure out how long it took to load a function, loop, method, or anything alike. (Credits to Tashiketh as well). Usually, you'd use the StopWatch class for it. Unfortunately, EA took that out of their own System.Diagnostics version :/. So this is just a simple workaround! If you want to check multiple, then just do exactly the same repeatedly. |
|
|
![]() |
#8 | |
gamefreak130
|
Quote:
StopWatch was taken out of System.Diagnostics because EA implemented their own StopWatch class in SimIFace. ![]() Basic functionality is pretty much the same as the System StopWatch. Here's an example:
Code:
using Sims3.SimIFace; using Sims3.UI; internal void TimedProcedure() { StopWatch timer = StopWatch.Create(StopWatch.TickStyles.Microseconds).Start(); // Things // TODO More things // Optional: Maybe some more things here? timer.Stop(); SimpleMessageDialogue.Show("TimedProcedure() took " + timer.GetElapsedTimeFloat().ToString() + " microseconds to execute."); timer.Dispose(); } | |
"The Internet is the first thing that humanity has built that humanity doesn't understand, the largest experiment in anarchy that we have ever had." - Eric Schmidt
If you enjoy the mods I put out, consider supporting me on patreon: www.patreon.com/Gamefreak130 |
||
|
Last edited by gamefreak130 : 3rd May 2020 at 7:17 PM.
|
![]() |
#9 |
zoe22
|
Greyed out message for when you cannot do an interaction for some reason (in Test function of InteractionDefinition): |
|
Last edited by zoe22 : 20th Oct 2020 at 9:05 PM.
|
![]() |
#10 |
gamefreak130
|
This is a cleaned-up repost from another discussion thread. All interactions in the game have a priority level assigned to them. When the game adds an interaction to a Sim's queue, all lower-priority interactions already in the queue are automatically canceled. Most interactions share the same default priority, but certain interactions (mainly reactions to burglars, mummies, simbots, etc.) are labeled by the game as high priority, meaning they will rather annoyingly cancel all user-directed interactions in the queue when they are assigned. If you want to work around this for a custom interaction (or make an interaction with the same functionality), you'll need to make it high priority by adding the following to your interaction's class:
Code:
using Sims3.Gameplay.Interactions; public override void Init(ref InteractionInstanceParameters parameters) { parameters.Priority = new InteractionPriority(InteractionPriorityLevel.High); base.Init(ref parameters); } There are priority levels higher than high, but they shouldn't be used unless you know what you're doing. As an aside, if at any point in an interaction's Run() method you want it to become uncancellable (i.e. the user can't click to remove it from the queue), you can use the following property of InteractionInstance:
Code:
CancellableByPlayer = false; |
"The Internet is the first thing that humanity has built that humanity doesn't understand, the largest experiment in anarchy that we have ever had." - Eric Schmidt
If you enjoy the mods I put out, consider supporting me on patreon: www.patreon.com/Gamefreak130 |
|
|
|
![]() |
#11 |
Lyralei
Original Poster
|
Whenever your function happens to be somewhat heavy on the game, this method can help (Credits to gamefreak130 as well)
Code:
What it does, is it fires the function on a different thread whenever it can, meaning that there's less pressure onto the game for running said function. This function is an asynchronous function, as it waits till the game is ready to fire it on a different thread.Â* This is defined with using OneShotFunctionTask. Function, of course, just defines which function it should look at.public override bool Run() { // when adding the function, never add the () to the end. This is because it expects a delegate Simulator.AddObject(new OneShotFunctionTask(new Function(yourFunctionhere))); } public void yourFunctionhere() { // code you want to fire here. } Simulator.AddObject(), just adds this function for the simulator's 'todo list' so to speak. ![]() There is a way to parse any needed parameters for the function, but that I've never gotten to work beside a whole workaround. So I'd recommend keeping your function within the interaction bit you're using this in. So under the Run() function if you will ![]() |
|
|
![]() |
#12 |
gamefreak130
|
This is by no means a "snippet", but I just over-engineered a thing that I wanted to post here. ![]() PersistableStatic fields are very useful for pure script mods, since they can effectively serve as global variables whose values can be tied to a save game and automatically saved/loaded by the game. However, multiple worlds in a single save will maintain separate copies of these fields, and their current value will automatically become the default starting values in newly-exposed worlds. When you travel to China, attend university, start a new game after quitting to main menu, etc., the value of PersistableStatics at the time of world loading will be carried over, but any further changes in one world will not affect the values in another. This is useful in some situations (e.g. keeping track of the number of Sims in a world), but not in others (e.g. keeping track of how many sim-days have been simulated save-wide). To work around this, I created a generic static class (an obscure feature of C#, but a helpful one in this case) that can "ferry" any PersistableStatic data declared in a class or struct across worlds when traveling, effectively allowing an entire save to share a single copy. |
"The Internet is the first thing that humanity has built that humanity doesn't understand, the largest experiment in anarchy that we have ever had." - Eric Schmidt
If you enjoy the mods I put out, consider supporting me on patreon: www.patreon.com/Gamefreak130 |
|
|
Last edited by gamefreak130 : 12th Oct 2020 at 4:02 AM.
|
![]() |
#13 |
zoe22
|
Replacing an existing interaction - Should go in OnPreLoad() NOTÂ*OnWorldLoadFinished()(Thanks to Battery for this one ![]() Count number of objects on a lot: Get List of certain type of object in an Inventory: Route to an object's general area: Create an object: |
|
|
![]() |
#14 |
Lyralei
Original Poster
|
Not a code snippet, since it's a pretty big code snippet by itself, so here's the link:Â*https://www.modthesims.info/showthr...375#post5703375 This code snippet shows how to change the name of an object to rename the object's name. The name component is basically the functionality how we can name a sim's car whenever they're best friends with their car ![]() |
|
|
![]() |