Locked thread | Replies: 92 (Who?), Viewed: 70557 times. | Locked by: HugeLunatic Reason: Please see updated tutorial in wiki, see first post.
Page 1 of 4
The Attack Cat
retired moderator
Original Poster
#1 Old 9th Aug 2009 at 1:14 AM Last edited by HugeLunatic : 21st Feb 2011 at 12:31 AM. Reason: fixed namespace
Default TUTORIAL: Object Modding (aka adding interactions) - UPDATE 1/17/10
This tutorial has been updated and wiki'd
Tutorial:Sims_3_Object_Moddingwiki


8 users say thanks for this. (Who?)
Advertisement
Instructor
#2 Old 9th Aug 2009 at 1:16 AM
This is absolutely awesome, thank you so so much for writing this tutorial!! This is great!

Find me on YouTube!
Flabaliki - General gaming
TheSimSupply - Videos all about The Sims!
Lab Assistant
#3 Old 9th Aug 2009 at 1:46 AM
Yes! I know a bit of Java and can kind of understand C, so I think I can maybe attempt this. Thanks!
Lab Assistant
#4 Old 15th Aug 2009 at 6:43 AM
Hello and thank you for this. I'm just having one problem importing my .dll into the package. At The Part at "Click on the S3SA and hit grid" Grid is grayed out and S3PE displays this in the value preview...
By Any Chance would you know what i missed or did'nt do right?

Smile tomorow will be worse.
The Attack Cat
retired moderator
Original Poster
#5 Old 15th Aug 2009 at 8:57 AM
Did you make sure to change the script of the OBJK to your new code instead of the old object code?
Lab Assistant
#6 Old 15th Aug 2009 at 8:40 PM Last edited by PigiePower : 15th Aug 2009 at 9:11 PM.
I have changed the second key in OBJK to KolipokiMod.TalkingTeddy. If that what your asking.

EDIT: I downgraded my S3PE to the second newest one and it works!

Smile tomorow will be worse.
Firestarter
#7 Old 16th Aug 2009 at 3:27 AM
I'm stuck on getting it to say what it's supposed to say. It just shows my namespace and class when it's moused over in game. I did the hashing and added a new key for the dialog, I even did it for all three STBL's. Just won't go. Deleted the game's cache files, too. Is there some missing step here, or when we hash it, does it have to have the dot in it or do you just hash it as a full name? I hashed it with the dot in it.
Test Subject
#8 Old 19th Aug 2009 at 5:45 AM
How would I go about getting it to perform an action of some sort?
The Attack Cat
retired moderator
Original Poster
#9 Old 19th Aug 2009 at 8:12 AM
bojinda: an action in what way? This tutorial shows you how to make it say something to you, but if you mean have your sims do something, there are many different ways in order to do that you just have to use the proper code to make it do what you want.
Test Subject
#10 Old 19th Aug 2009 at 11:19 PM Last edited by bojinda : 20th Aug 2009 at 12:56 AM.
Quote:
Originally Posted by Kolipoki
bojinda: an action in what way? This tutorial shows you how to make it say something to you, but if you mean have your sims do something, there are many different ways in order to do that you just have to use the proper code to make it do what you want.


Ah thanks for the reply sorry for not being more specific, I mean make it do something like the cheer that the sim (excitable ones maybe) will sometimes do autonomously if you just let them stand there for a while
Lab Assistant
#11 Old 24th Aug 2009 at 10:41 PM
If we wanted a certain item to do more than one ting (E.G, say hi for one interaction, then start a fire for another, etc.) could we organize each of these functions into different classes?
The Attack Cat
retired moderator
Original Poster
#12 Old 25th Aug 2009 at 1:52 AM
If you wanted to make the object have more then one interaction you would just make a new class such as "private sealed class TalktoMe : ImmediateInteraction<Sim, TalkingTeddy>". If you wanted to have it where you click on something, something else would come up try looking at the Chaos Mage Painting.
Test Subject
#13 Old 31st Aug 2009 at 6:38 PM
Thx this Thread is a great help !! would give 5 ***** if it would be possible

Regards
Kartesk
Test Subject
#14 Old 2nd Sep 2009 at 2:35 PM
Hello! I have a problem with microsoft visual c# 2008 express edition (german).
If I create a new Project, I can't select ".NET Framework 2.0".. Why?
Here a screenshot:
http://img90.imageshack.us/img90/6600/mvs.jpg
(Klassenbibliothek = Class Library)

And here the screenshot from the tutorial:
http://www.sims2wiki.info/images/0/...New_Project.png


(sorry for my english!)
Top Secret Researcher
#15 Old 2nd Sep 2009 at 6:07 PM
Quote:
Originally Posted by Cytron
Hello! I have a problem with microsoft visual c# 2008 express edition (german).
If I create a new Project, I can't select ".NET Framework 2.0".. Why?


The tutorial appears to have been written using the full version of Visual C# (or perhaps an older Express edition), rather than the current Express version.

You'll find the Setting for ".NET Framework 2.0" in the Properties for the project.

Right click on top-level item for your project in the Solution Explorer, and use the "Properties" menu operation. Then go to the "Application" tab, and the "Target Framework" should be there.

Cheers.
Test Subject
#16 Old 3rd Sep 2009 at 1:02 PM Last edited by Cytron : 4th Sep 2009 at 3:23 PM. Reason: another problem
Quote:
Originally Posted by twallan
The tutorial appears to have been written using the full version of Visual C# (or perhaps an older Express edition), rather than the current Express version.

You'll find the Setting for ".NET Framework 2.0" in the Properties for the project.

Right click on top-level item for your project in the Solution Explorer, and use the "Properties" menu operation. Then go to the "Application" tab, and the "Target Framework" should be there.

Cheers.

Thank you very much


EDIT: Next Problem: I can't find "TurnOnOff" .. Screenshot:
http://img257.imageshack.us/img257/9373/vs2o.jpg
Top Secret Researcher
#17 Old 4th Sep 2009 at 9:59 PM
Quote:
Originally Posted by Cytron
EDIT: Next Problem: I can't find "TurnOnOff"


If you are looking to turn off a Stereo, use the function
Sims3.Gameplay.Objects.Electronics.Stereo.TurnOff()

If you want to turn it on, use the function
Sims3.Gameplay.Objects.Electronics.Stereo.TurnOn()

The Sims3.Gameplay.Objects.Electronics.Stereo.ToggleStereo() function is a protected member of the class, and is not available for direct call. It is called by the TurnOn() and TurnOff() functions.

If you wish to call the ToggleStereo() function directly, you will need to change the protection level in the Sims3GameplaySystems.dll .

Cheers.
Test Subject
#18 Old 9th Sep 2009 at 7:52 PM
Quote:
Originally Posted by twallan
If you are looking to turn off a Stereo, use the function
Sims3.Gameplay.Objects.Electronics.Stereo.TurnOff()

If you want to turn it on, use the function
Sims3.Gameplay.Objects.Electronics.Stereo.TurnOn()

The Sims3.Gameplay.Objects.Electronics.Stereo.ToggleStereo() function is a protected member of the class, and is not available for direct call. It is called by the TurnOn() and TurnOff() functions.

If you wish to call the ToggleStereo() function directly, you will need to change the protection level in the Sims3GameplaySystems.dll .

Cheers.

Thanks again

EDIT: I copied the script from this thread, but I think the interaction-name is wrong.. where exactly can I edit this?:
http://img75.imageshack.us/img75/2271/bild2i.jpg
Top Secret Researcher
#19 Old 9th Sep 2009 at 9:28 PM
Quote:
Originally Posted by Cytron
Thanks again
EDIT: I copied the script from this thread, but I think the interaction-name is wrong.. where exactly can I edit this?:


This one provides the name for the menu item.

Code:
                      protected override string GetInteractionName(Sim a, TalkingTeddy target, InteractionObjectPair interaction)
                      {
                          return TalkingTeddy.TalktoMe.LocalizeString("TalktoMe", new object[0]);
                      }


It calls this function, which creates the long name you are seeing.

Code:
                  private static string LocalizeString(string name, params object[] parameters)
                  {
                   return Localization.LocalizeString("Gameplay/Objects/Miscellaneous/TalkingTeddy/TalktoMe:" + name, parameters);
                  }


Cheers.

NRaas Industries: Sims 3 Mods for the Discerning Player, hosted by The Wikispaces.
Test Subject
#20 Old 25th Sep 2009 at 1:30 PM Last edited by Jinxx : 25th Sep 2009 at 2:42 PM. Reason: Change Of Attack hehe
First of all thank you so much for this. its awesome!!

I think im in over my head a little though. What I want to do is make a BodySculptor (found in Sims3.Gameplay.Objects.Rewards) teach you a skill like logic, but at the same time, take hunger, bladder, and sleep down.

I figured I'd start simply with a copy and paste job of the bodysculptor code. With my namespace etc.

this is what I have:
Code:
using System;
using System.Collections.Generic;
using System.Text;
using Sims3.SimIFace;
using Sims3.UI;
using Sims3.Gameplay;
using Sims3.Gameplay.Abstracts;
using Sims3.Gameplay.Actors;
using Sims3.Gameplay.ActorSystems;
using Sims3.Gameplay.Autonomy;
using Sims3.Gameplay.Core;
using Sims3.Gameplay.Interactions;
using Sims3.Gameplay.Objects;
using Sims3.Gameplay.Objects.Rewards;
using Sims3.Gameplay.Skills;
using Sims3.Gameplay.Socializing;
using Sims3.Gameplay.Utilities;



namespace JinxxMod
{
    public class Simhancer : Rewards
    {
        protected Sim mRevealingSim;

        public static float[] kPowerLevelPercentages;
        public static float[] kChancesOfFailure;

        public static int[] kRunTimes;
        public static int[] kRechargeTimes;

        public static int kSocialFailureLtrDelta;
        public static int kSocialFailureStcDelta;

        public static string kSocialFailureStc;
        public static readonly string sLocalizationKey;

        private PowerLevel mPowerLevel;
        private DateAndTime mLastUsed;
        private PowerLevel mPowerLevelLastUsed;
        private AlarmHandle mRechargeAlarm;


        public override void OnStartup()
        {
            base.OnStartup();
            base.AddInteraction(SimhanceMe.Singleton);
        }


        private enum Option
        {
            Thin = 0,
            Fat = 1,
            Weak = 2,
            Strong = 3,
            Original = 4
        }

        private enum PowerLevel
        {
            Low = 0,
            Medium = 1,
            High = 2
        }

        
        
        internal void OnUse()
        {
            this.mLastUsed = SimClock.CurrentTime();
            this.mPowerLevelLastUsed = this.mPowerLevel;
            base.SetMaterial("Default");
            Audio.StartObjectSound(base.ObjectId, "bodysculpt_light_red", false);
            base.AddOrResetAlarm(ref this.mRechargeAlarm, (float)this.ChargeTimeRemaining, TimeUnit.Minutes, new AlarmTimerCallback(this.RechargeAlarmCallback), "RechargeAlarmCallback", AlarmType.AlwaysPersisted);
        }

        public bool Charged
        {
            get
            {
                return (SimClock.ElapsedTime(TimeUnit.Minutes, this.mLastUsed, SimClock.CurrentTime()) > kRechargeTimes[(int)this.mPowerLevelLastUsed]);
            }
        }

        public static string LocalizeString(Sim actor, string name, params object[] parameters)
        {
            return Localization.LocalizeString((actor != null) && actor.IsFemale, sLocalizationKey + ":" + name, parameters);
        }

 

 


        private sealed class SimhanceMe : Interaction<Sim, Simhancer>
        {
            // Fields
            private bool mFailure;
            private IGameObject mReservedTile;
            public static readonly InteractionDefinition Singleton = new Definition();

            // Methods
            public override void Cleanup()
            {
                if (this.mReservedTile != null)
                {
                    this.mReservedTile.Destroy();
                    this.mReservedTile = null;
                }
                base.Cleanup();
            }

            private void PlayStopSound(StateMachineClient smc, IEvent evt)
            {
                string name = "fx_bodysculpt";
                if (this.mFailure)
                {
                    name = name + "_fail";
                }
                Audio.StartObjectSound(base.Target.ObjectId, name, false);
                base.Target.SetMaterial("Default");
            }

            protected override bool Run()
            {
                Simhancer.Option mOption = (base.InteractionDefinition as ItemDefinition).mOption;
                Sim mInstigator = (base.InteractionDefinition as ItemDefinition).mInstigator;
                if (!base.Actor.RouteToSlotAndCheckInUse(base.Target, Slot.RoutingSlot_0))
                {
                    return false;
                }
                base.StandardEntry();
                this.mReservedTile = Sims3.Gameplay.GlobalFunctions.CreateObject("ReservedTile", base.Actor.Position, base.Actor.Level, base.Actor.ForwardVector);
                base.EnterStateMachine("Simhancer", "Enter", "x");
                base.SetActor("Simhancer", base.Target);
                base.SetParameter("Set", base.Actor.SimDescription.Child ? "child" : (base.Actor.IsFemale ? "female" : "male"));
                base.SetParameter("Q", (base.Actor.SimDescription.Child || base.Actor.IsFemale) ? "" : (RandomUtil.CoinFlip() ? "1" : "2"));
                Simhancer.PowerLevel mPowerLevel = base.Target.mPowerLevel;
                int num = Simhancer.kRunTimes[(int) mPowerLevel];
                float num2 = Simhancer.kPowerLevelPercentages[(int) mPowerLevel];
                float fitness = base.Actor.SimDescription.Fitness;
                float num4 = base.Actor.SimDescription.Weight + 1f;
                switch (mOption)
                {
                    case Simhancer.Option.Thin:
                        num4 -= num2 * num4;
                        break;

                    case Simhancer.Option.Fat:
                        num4 += num2 * (2f - num4);
                        break;

                    case Simhancer.Option.Weak:
                        fitness -= num2 * fitness;
                        break;

                    case Simhancer.Option.Strong:
                        fitness += num2 * (1f - fitness);
                        break;
                }
                num4--;
                float num5 = 0f;
                if (num4 < 0f)
                {
                    num5 = 1f + num4;
                    num4 = 0f;
                }
                this.mFailure = false;
                if (RandomUtil.RandomChance01(Simhancer.kChancesOfFailure[(int)mPowerLevel]))
                {
                    this.mFailure = true;
                    bool flag = false;
                    switch (RandomUtil.GetInt(2))
                    {
                        case 0:
                            fitness = 0f;
                            break;

                        case 1:
                            fitness = 1f;
                            break;

                        case 2:
                            flag = true;
                            break;
                    }
                    switch (RandomUtil.GetInt(flag ? 1 : 2))
                    {
                        case 0:
                            num4 = 1f;
                            num5 = 0f;
                            break;

                        case 1:
                            num4 = 0f;
                            num5 = 1f;
                            break;
                    }
                }
                base.BeginCommodityUpdates();
                base.AnimateSim("Use");
                base.Actor.WaitForExitReason((float) (num / 2), ExitReason.HigherPriorityNext);
                if ((mOption == Simhancer.Option.Original) && !this.mFailure)
                {
                    base.Actor.SimDescription.ResetBodyShape();
                }
                else
                {
                    base.Actor.SimDescription.SetBodyShape(num4 - num5, fitness);
                }
                base.Actor.WaitForExitReason((float) (num - (num / 2)), ExitReason.HigherPriorityNext);
                base.AddOneShotScriptEventHandler(0x3e9, new SacsEventHandler(this.PlayStopSound));
                base.AnimateSim("Get Out");
                base.EndCommodityUpdates(!this.mFailure);
                base.Target.OnUse();
                if (this.mFailure)
                {
                    base.Actor.PlayReaction(ReactionTypes.TantrumIntense, ReactionSpeed.ImmediateWithoutOverlay);
                    if (mInstigator != null)
                    {
                        Relationship relationship = Relationship.Get(base.Actor, mInstigator, true);
                        if (relationship != null)
                        {
                            relationship.UpdateSTCAndLTR(base.Actor, mInstigator, Simhancer.kSocialFailureStc, (float) Simhancer.kSocialFailureStcDelta);
                        }
                        if ((mInstigator.CurrentInteraction != null) && (mInstigator.CurrentInteraction.InteractionDefinition == Simhancer.WatchChange.Singleton))
                        {
                            mInstigator.AddExitReason(ExitReason.CanceledByScript);
                        }
                    }
                }
                else
                {
                    if (((mInstigator != null) && (mInstigator.CurrentInteraction != null)) && (mInstigator.CurrentInteraction.InteractionDefinition == Simhancer.WatchChange.Singleton))
                    {
                        mInstigator.AddExitReason(ExitReason.Finished);
                    }
                    base.AnimateSim("React " + mOption);
                }
                base.StandardExit();
                return true;
            }

            // Nested Types
            public sealed class Definition : InteractionDefinition<Sim, Simhancer, Simhancer.SimhanceMe>
            {
                // Methods
                protected override void AddInteractions(InteractionObjectPair iop, Sim actor, Simhancer target, List<InteractionObjectPair> results)
                {
                    InteractionInstanceParameters parameters = new InteractionInstanceParameters(iop, actor, actor.InheritedPriority(), false, true);
                    GreyedOutTooltipCallback greyedOutTooltipCallback = null;
                    if (this.Test(ref parameters, ref greyedOutTooltipCallback))
                    {
                        if (!target.Charged)
                        {
                            results.Add(iop);
                        }
                        else
                        {
                            Simhancer.Option option = actor.SimDescription.IsInitialBodyShape() ? Simhancer.Option.Strong : Simhancer.Option.Original;
                            for (int i = 0; i <= option; i++)
                            {
                                Simhancer.SimhanceMe.ItemDefinition interaction = new Simhancer.SimhanceMe.ItemDefinition();
                                interaction.mOption = (Simhancer.Option) i;
                                results.Add(new InteractionObjectPair(interaction, target));
                            }
                        }
                    }
                }

                protected override string GetInteractionName(Sim a, Simhancer target, InteractionObjectPair interaction)
                {
                    return Simhancer.LocalizeString(null, "SimhanceMe", new object[0]);
                }

                protected override bool Test(Sim a, Simhancer target, bool isAutonomous, ref GreyedOutTooltipCallback greyedOutTooltipCallback)
                {
                    GreyedOutTooltipCallback callback = null;
                    if (target.Charged)
                    {
                        return true;
                    }
                    if (callback == null)
                    {
                        callback = delegate {
                            return Simhancer.LocalizeString(null, "TipNotCharged", new object[] { target.ChargeTimeRemaining });
                        };
                    }
                    greyedOutTooltipCallback = callback;
                    return false;
                }
            }

            [DoesntRequireTuning]
            public sealed class ItemDefinition : InteractionDefinition<Sim, Simhancer, Simhancer.SimhanceMe>
            {
                // Fields
                public Sim mInstigator;
                public Simhancer.Option mOption;

                // Methods
                protected override string GetInteractionName(Sim a, Simhancer target, InteractionObjectPair interaction)
                {
                    return Simhancer.LocalizeString(null, "SimhanceMeOption" + this.mOption, new object[0]);
                }

                public override string[] GetPath()
                {
                    return new string[] { Simhancer.LocalizeString(null, "SimhanceMe", new object[0]) };
                }

                protected override bool Test(Sim a, Simhancer target, bool isAutonomous, ref GreyedOutTooltipCallback greyedOutTooltipCallback)
                {
                    return (target.Charged && !target.InUse);
                }
            }
        }
 



    }
}


I get a lot of errors just in that.... can anyone tell me what I'm doing wrong please
Thank you all in advance :D
Mad Poster
#21 Old 26th Sep 2009 at 9:51 PM Last edited by ani_ : 27th Sep 2009 at 11:15 AM.
Jinxx: VS usually gives you quite descriptive error messages, you should try reading them through.

I have a question about object modding.
Has anybody succesfully managed to get a custom JAZZ file attached to their object mod? Is there any specific thing one should take into consideration?
I can successfully get the game to use a pre-existing state, and do the animations in that, but not when I try it to use the jazz file I attached.

---edit---
ignore my question, figured it out.
Test Subject
#22 Old 28th Sep 2009 at 10:03 AM
thanks for your reply ani,
I have read the errors and not sure how to fix them. Sorry, I thought I'd put them in the original post.....

Error 1 The type or namespace name 'Rewards' could not be found (are you missing a using directive or an assembly reference?) C:\Games\The Sims 3\Mods\Jinxx.Sims3Game.Test\Jinxx.Sims3Game.Test\Class1.cs 23 30 Jinxx.Sims3Game.Test

Error 2 The type or namespace name 'IGameObject' could not be found (are you missing a using directive or an assembly reference?) C:\Games\The Sims 3\Mods\Jinxx.Sims3Game.Test\Jinxx.Sims3Game.Test\Class1.cs 101 21 Jinxx.Sims3Game.Test

from what I can see, I'm not missing a using directive. Any ideas?
Test Subject
#23 Old 28th Sep 2009 at 12:51 PM
Default Disassembler
How do I open the disassembler exactly, I am pressing the space bar yet nothing is coming up?
Mad Poster
#24 Old 28th Sep 2009 at 1:24 PM
Jinxx: Click on those two that are giving you a problem with your mouse right button, then select resolve and it should give you options on references you need, you can straight click them from the list it gives you.

cheezegrate: You as well need to click the class you want to see with the right side mouse button and selecte it from there, I also couldn't launce it with space.
Test Subject
#25 Old 30th Sep 2009 at 8:12 AM
Ah well
Locked thread | Locked by: HugeLunatic Reason: Please see updated tutorial in wiki, see first post.
Page 1 of 4
Back to top