Quick Reply
Search this Thread
Test Subject
Original Poster
#1 Old 11th Aug 2026 at 5:40 PM
Default How to code a simple script mod to add a moodlet while sleeping?
I am very new to creating mods for the Sims 3. I've seen tutorials on how to add custom moodlets to the game. I want to create a mod that adds a Relaxed moodlet (base game, NOT a custom moodlet) while a sim is sleeping in a bed. How can I code this? Does anyone have any tutorials? Thanks!
Test Subject
#2 Old 21st Aug 2026 at 2:02 AM
You can use Sim's .IsSleeping property, maybe in an alarm? Something like this, which checks every fifteen Sim minutes (untested):

Code:
using System;
using Sims3.SimIFace;
using Sims3.Gameplay.Actors;
using Sims3.Gameplay.ActorSystems;
using Sims3.Gameplay.Utilities;

namespace SleepRelaxedMod
{
    public class SleepRelaxed
    {
        [Tunable]
        protected static bool kInstantiator = false;

        private static AlarmHandle sAlarmHandle = AlarmHandle.kInvalidHandle;

        static SleepRelaxed()
        {
            World.OnWorldLoadFinishedEventHandler += new EventHandler(OnWorldLoadFinished);
            World.sOnWorldQuitEventHandler += new EventHandler(OnWorldQuit);
        }

        private static void OnWorldLoadFinished(object sender, EventArgs e)
        {
            sAlarmHandle = AlarmManager.Global.AddAlarmRepeating(
                15f, TimeUnit.Minutes,
                new AlarmTimerCallback(OnCheck),
                "SleepRelaxedCheck",
                AlarmType.NeverPersisted, null);
        }

        private static void OnWorldQuit(object sender, EventArgs e)
        {
            if (sAlarmHandle != AlarmHandle.kInvalidHandle)
            {
                AlarmManager.Global.RemoveAlarm(sAlarmHandle);
                sAlarmHandle = AlarmHandle.kInvalidHandle;
            }
        }

        private static void OnCheck()
        {
            Household house = Household.ActiveHousehold;
            if (house == null) return;

            foreach (Sim sim in house.Sims)
            {
                if (sim != null && sim.IsSleeping
                    && !sim.BuffManager.HasElement(BuffNames.Relaxed))
                {
                    sim.BuffManager.AddElement(BuffNames.Relaxed, Origin.None);
                }
            }
        }
    }
}
Reaper
staff: moderator
#3 Old 21st Aug 2026 at 12:56 PM
No need for alarms. There is an event that triggers when a Sim falls asleep. It also triggers when napping. You need to check if the Sim is using a bed and if the interaction is a sleep interaction.
An alarm could be useful if you want to give them this moodlet in mid-sleep, though.
Code:
private static void OnWorldLoadFinished(object sender, EventArgs e)
{
    EventTracker.AddListener(EventTypeId.kSimFellAsleep, OnSimFellAsleep);
    // There's also a waking up event with a custom event type: WokeUpEvent.
    EventTracker.AddListener(EventTypeId.kSimWokeUp, OnSimFellAsleep);
}

This is a signature.
Back to top