First steps and problems in modding

Talk nerdy to us here.
Post Reply
User avatar
Knight
Reactions:
Posts: 390
Joined: October 28th, 2018, 3:28 am
Answers: 13

First steps and problems in modding

Post by Knight » August 10th, 2021, 9:26 am

I decided to practice a little in writing scripting mods, armed with VS2019 and unprotected libs from your git. I'm really newbie here, but at least was able to repeat "pausinator" from Buzzler's tutorial and it works correctly. Now I want to make a simple mod, which adding cheat for reset music in game. Sketched out a small script (code below), everything is fine, music really ends and starts again, but appeared endless loading while travelling in any other world and infinite exit from game. So I'm stuck, need advices from professionals. :)

Code: Select all

using Sims3.Gameplay.Core;
using Sims3.SimIFace;
using System;

...

        static ResetMusic()
        {
            World.sOnEnterNotInWorldEventHandler += Init;
        }

        private static void Init(object sender, EventArgs e)
        {
            Commands.sGameCommands.Register("rm", "Quickly resets current game music. Doesn't affects stereos.", Commands.CommandType.General, new CommandHandler(Cheat));
        }

        private static int Cheat(object[] parameters)
        {
            MusicMode curMM = AudioManager.mMusicMode;
            AudioManager.mMusicMode = MusicMode.None;
            if (CameraController.IsMapViewModeEnabled())
            {
                AudioManager.OnCameraMapViewEnabledEvent(true);
            }
            else
            {
                AudioManager.SetMusicMode(curMM);
            }
            return 1;
        }

User avatar
Knight
Reactions:
Posts: 390
Joined: October 28th, 2018, 3:28 am
Answers: 13

First steps and problems in modding

Post by Knight » August 11th, 2021, 7:57 am

Nevermind, problem is fixed.

Code: Select all

using Sims3.Gameplay.Core;
using Sims3.SimIFace;
using System;

...

        static ResetMusic()
        {
            World.sOnEnterNotInWorldEventHandler += Init;
            World.sOnWorldLoadFinishedEventHandler += Init;
            World.sOnLeaveNotInWorldEventHandler += Terminate;
            World.sOnWorldQuitEventHandler += Terminate;
        }

        private static void Init(object sender, EventArgs e)
        {
            inited = true;
            if (!cheatRegistered)
            {
                Commands.sGameCommands.Register("rm", "Quickly resets current game music. Doesn't affects stereos.", Commands.CommandType.General, new CommandHandler(Cheat));
                cheatRegistered = true;
            }
        }

        private static void Terminate(object sender, EventArgs e)
        {
            inited = false;
        }

        private static int Cheat(object[] parameters)
        {
            if (inited)
            {
                MusicMode curMM = AudioManager.mMusicMode;
                if (CameraController.IsMapViewModeEnabled())
                {
                    AudioManager.mMusicMode = MusicMode.None;
                    AudioManager.OnCameraMapViewEnabledEvent(true);
                }
                if (!CameraController.IsMapViewModeEnabled() & curMM != MusicMode.None)
                {
                    AudioManager.mMusicMode = MusicMode.None;
                    AudioManager.SetMusicMode(curMM);
                }
            }
            return 1;
        }

User avatar
Knight
Reactions:
Posts: 390
Joined: October 28th, 2018, 3:28 am
Answers: 13

First steps and problems in modding

Post by Knight » December 28th, 2022, 4:01 am

Yesterday I decided to look at the MSC Mod and find out why it causes infinite loading. The problem was similar, the author needed to unload the cheat before leaving the town. I left the fixed version in the comments on MTS. :)

Post Reply