Hi there! You are currently browsing as a guest. Why not create an account? Then you get less ads, can thank creators, post feedback, keep a list of your favourites, and more!
Field Researcher
Original Poster
#1 Old 14th Apr 2010 at 12:06 AM Last edited by lytefoot : 15th Apr 2010 at 1:51 AM.
Default Sleep on sofa
So, I'm making a sofa sims can sleep on (as an object mod for now, planning on turning it into a scripting mod once I've got it working so that sims can sleep anywhere they can nap... anyway). So far I've got almost everything working... they curl up on the sofa and snore... the stager figures out how long they ought to sleep... but they don't actually gain energy, and so obviously if I tell them to sleep until fully rested they never wake up.

I've attached my code, in case it isn't immediately obvious to people who know how to do this stuff what my problem is. Keep in mind that (1) I'm doing this pretty much cargo cult and (2) I have an utterly ancient version of the game, so if my code looks funky, that's why (soon--SOON--the computer that's willing to run the sims will also be willing to talk to the internet, so I'll be able to get patches and start all my scripts over, oh joy).
Attached files:
File Type: txt  Class1.cs.txt (17.0 KB, 205 downloads)
Description: my code (updated 4/14)
Advertisement
The Attack Cat
retired moderator
#2 Old 14th Apr 2010 at 12:36 AM
Your probably missing something along the lines of what the bed has such as:
Code:
    float meditativeTranceSleepEnergyGainMultiplier = 1f;
    if (base.Actor.HasTrait(TraitNames.MeditativeTranceSleep))
    {
        meditativeTranceSleepEnergyGainMultiplier = TraitTuning.MeditativeTranceSleepEnergyGainMultiplier;
    }
    base.BeginCommodityUpdate(CommodityKind.Energy, base.Target.TuningBed.EnergyMultiplier * meditativeTranceSleepEnergyGainMultiplier);
    base.BeginCommodityUpdates();
Field Researcher
Original Poster
#3 Old 14th Apr 2010 at 4:49 AM
No, I have that. I gave it a constant float number (since the sofa lacks bed tuning).
Scholar
#4 Old 14th Apr 2010 at 6:41 PM
Hmm, I can't find a call to "BeginCommodityUpdate" in your code.

You probably should call
base.BeginCommodityUpdate(CommodityKind.Energy, someNumber);
before
base.BeginCommodityUpdates();

If you already have that in, please update the code.
Field Researcher
Original Poster
#5 Old 15th Apr 2010 at 1:51 AM
I think that I'd taken that out because it didn't seem to be helping (or something?)... it's in the latest version, I just updated it. Thanks for looking
Scholar
#6 Old 15th Apr 2010 at 3:38 PM
Hmm, can you upload the whole package?
Field Researcher
Original Poster
#7 Old 16th Apr 2010 at 4:07 PM
Sure, here. I would be shocked--Shocked!--if this worked in other people's games, since mine is totally unpatched...

In my game, the sofa loads up just fine, all of its usual interactions work properly, the "Sleep" interaction runs, the sim simply doesn't gain energy (and it doesn't set an end time for fully rested).
Attached files:
File Type: zip  lytefoot_SleeperSofa.zip (871.6 KB, 174 downloads) - View custom content
Scholar
#8 Old 16th Apr 2010 at 9:50 PM
I didn't tested your package yet, but two things:

- You know you can add the interaction to all sofas? Your package looks like it contains only one cloned. But of course that doesn't solve the general problem.
- I think the interaction probably needs a tuning xml. The interaction, not the object, because the sleep interaction of the beds contains some energy related markup. You should probably try to replicate that.
Field Researcher
Original Poster
#9 Old 17th Apr 2010 at 2:38 AM
I know I can add it to all sofas, but it's easier to get into the game attached to an object, and I wanted to get the interaction working before I tried to get it to load itself...

The interaction *itself* needs tuning? Hmm... I was thinking I could get away with just hard-coding the numbers... you're probably right, I'll try mucking about with that. Thanks
Scholar
#10 Old 28th Apr 2010 at 2:00 PM
I've just come across this thread - through Google, no less lol. I sure hope this project is still happening; I would love to have a sofa for my homeless sims to properly sleep on, rather than just nap. It kinda ruins it for me when they keep waking up with a smidgen of energy each time, lol.

...Titanium white...
Test Subject
#11 Old 8th Aug 2011 at 12:54 AM
Guess this never happened? Would be awesome if it did. How am i suppose to created my "Guy on the couch" sim without it?
Space Pony
#12 Old 27th Aug 2011 at 2:30 AM
I'll try to do this. Got a game plan set up, though if I have the same trouble concerning the sleep motive or not is yet to be seen.
Instructor
#13 Old 11th Nov 2011 at 4:14 AM
I was wondering how this was coming along, and if you ever figured out how to do it.
Test Subject
#14 Old 1st Aug 2012 at 3:22 AM
Does anyone have a completed mod for this? I'd like to have it, but if you can't gain any energy from it, like in this one, it's no good, you know?
Eminence Grise
#15 Old 1st Aug 2012 at 5:21 AM
Just a reminder that if you're looking for a completed mod, the WCIF forum under Help is the place to ask

Ask here if you're trying to implement the thing yourself.
Test Subject
#16 Old 2nd Aug 2012 at 1:25 AM
Okay. I'm sorry. I, as you can tell from my post numbers, I haven't posted much on here. I was eager to just post, and didn't read the section that this was in. I didn't mean that I was looking for a completed mod for it, I was just checking if anyone that was discussing this several years ago had finished this one. I did enough research to know that this is pretty much the only one that got started, so I was only wondering if it had ever been completed. Thank you for the advice, and I'll be sure to follow it/ be more clear in my posting in the future!
Eminence Grise
#17 Old 2nd Aug 2012 at 1:55 AM
No worries! Just clarifying. Welcome to MTS
Test Subject
#18 Old 2nd Aug 2012 at 2:37 AM
Thank you!
Lab Assistant
#19 Old 22nd Sep 2013 at 2:57 AM
Inspired by this thread, I have actually gotten a pure script version of the "Sleep on sofa" interaction working. It adds a custom interaction to all sofas, with most of the code pulled straight from Nap and BedSleep interactions. (I've been using the patch 1.55 dlls, but hopefully that hasn't changed in 1.57.) However, though it's mostly working, I'm still having a couple of problems with the mod. So I'd truly appreciate any advice to figure out what's wrong with me - er, I mean my code. =D

So, problem #1: This custom interaction only shows up on sofas with three seats! I have no idea why, as that part of the code is taken straight from Nap interaction.... I'll attach the code for anyone to look at. Any ideas?
(On second thought, that is semi-realistic; I wouldn't want to sleep on a loveseat all night either. :P)

Problem #2: Haven't been able to figure out why the WellRested buff gets added, whether I want it to or not. This is more of a minor bug, as it's easy to remove the buff when the sim quits the interaction. Still, I'd like to find out why it's happening in the first place, if possible.

Just attaching both my code and the mod package, for testing purposes or whatever. Thanks in advance for any help, ideas, or feed back :D
Attached files:
File Type: rar  SofaSleep.rar (13.4 KB, 72 downloads) - View custom content
Description: contains code files and mod package for testing (built with 1.55)

Intersecting modular stairs.
Instructor
#20 Old 22nd Sep 2013 at 6:20 AM
I haven't tested in my game, but I had a quick glance at the code and I can tell why the interaction's not showing up in loveseats. You're adding the interaction to the sofa class. In The Sims, sofas are three cushion couchs. Loveseats have two cushions and living chairs have one.

This is the hierarchy tree of couches:

Code:
MultiSeatObject : IHasSeatingGroup
    > Couch
        > ChairSectional
        > Loveseat
        > Sofa
    > ChairLiving


So you're better off applying the interaction to MultiSeatObject, Couch or IHasSeatingGroup.
Lab Assistant
#21 Old 22nd Sep 2013 at 1:07 PM
Yes, I was stupid! Thanks for replying SimsMX. I went through the whole SofaSleep class bit by bit before I realized the problem might be in Instantiator, where I was adding the interactions. In fact, it was exactly what you said!
I wrote that part of the code first and it never occurred to me then that the Sofa class doesn't actually include all couch/bench objects. (Actually, at that point I wasn't even expecting the mod to work, so it wouldn't have mattered lol).
The sad thing is, I stopped checking for replies before you posted and went through the code piece by piece on my own... All that work for no reason since the answer was waiting right here, if I would have checked again! Except I probably learned a lot by searching for the problem, so that's a good reason. Wow, I've been so discouraged by all my fail attempts at scripting, and then out of the blue this one suddenly works on me. And it even mostly makes sense to my brain! I'm so excited haha. xD

Ok, so now I use MultiSeatObject, it works great. In fact, it even adds the interaction to any Sectional seating that has at least two seats (which was next on my list to figure out). However for some reason I have to save & reload before it shows up on newly bought sectional seating. I guess that's an EA bug though, because their Nap interaction also doesn't show up right away.

Tried IHasSeatingGroup first by the way, but it didn't work, something about it doesn't have an AddInteraction method. Because it's an interface? Not even sure I know what an interface IS. Lol, oh well, I'm still learning a lot.

So here's the code I have now that adds the custom interaction correctly to all MultiSeatObjects. (I know, I put three giant smiles in one post... it's because my mood meter is Elated.)
(Thanks to Nona's tutorial for much of this code.)
Code:
private static void OnWorldLoadFinished(object sender, EventArgs e)
        {
            foreach (MultiSeatObject multiSeat in Sims3.Gameplay.Queries.GetObjects<MultiSeatObject>())
            {
                AddInteractions(multiSeat);
            }
            EventTracker.AddListener(EventTypeId.kBoughtObject, new ProcessEventDelegate(Instantiator.OnObjectChanged));
        }

        private static void AddInteractions(MultiSeatObject multiSeat)
        {
            foreach (InteractionObjectPair pair in multiSeat.Interactions)
            {
                if (pair.InteractionDefinition.GetType() == SofaSleep.Singleton.GetType())
                {
                    return;
                }
            }
            multiSeat.AddInteraction(SofaSleep.Singleton);
        }

        private static ListenerAction OnObjectChanged(Event e)
        {
            MultiSeatObject multiSeat = e.TargetObject as MultiSeatObject;
            if (multiSeat != null)
            {
                AddInteractions(multiSeat);
            }
            return ListenerAction.Keep;
        }


I'll attach the fixed version of the entire interaction code, for anyone that wants to look at it.
And now I guess.... I can go and upload the mod? Surely it can't be that easy, eh...? I know, I still haven't figured out how to keep the WellRested buff from appearing at all, but that's a fairly minor bug as it doesn't show up for long and has no mood effect.
Attached files:
File Type: rar  SofaSleep - fixed code.rar (4.0 KB, 69 downloads) - View custom content

Intersecting modular stairs.
Lab Assistant
#22 Old 24th Sep 2013 at 8:06 PM Last edited by sammonsim : 24th Sep 2013 at 8:10 PM. Reason: Reworded something that completely made no sense
I have fixed some more stuff, including that now the "Dream about..." interaction will be available on the object a child or teen is sleeping on. Though if they're on a sectional sofa, you have to click on the right section for it to show up.

The WellRested buff with no mood effect still apppears sometimes, but it is immediately removed (unless the sim oversleeps for a while), so I don't see it as much of a problem.

I set the chance of a Bad Night's Sleep buff to be related to the comfort score of the bench. Low comfort will have a higher chance, etc. (It actually works, even. )
Energy gain is also relative to comfort, via a multiplier. Since the energy gain is actually less than 1 for something with only +5 comfort like the park bench, it seems a sim will only sleep on it until almost fully rested. That's fine with me though, as it doesn't make sense to have a sim completely fill his energy bar by sleeping on a hard bench in the park. It's only a little off, anyway. I did attempt to fix it at first, but then I checked EA's beds with negative multipliers - the cheap Ambitions bed and the new trash heap bed. Sent my sim to sleep on one of them, and sure enough, his energy bar was not quite filled when he woke up. So that appears to be EA standard behavior, as far as I can tell.

It all seems to be working pretty well now, but so far I have only tested in a limited testing environment. So I'll go install the mod in my actual game and test in normal play for a while, just to make sure.

I'll attach the code that I'm finally finished working on for now (), and a copy of the package. Anyone want to play test it, go ahead, and let me know if you run into anything odd with it.

Thanks for watching, bye!
Attached files:
File Type: rar  SleepHere code.rar (5.4 KB, 289 downloads) - View custom content
File Type: rar  SleepOnSofa.package.rar (10.6 KB, 788 downloads) - View custom content

Intersecting modular stairs.
Instructor
#23 Old 25th Sep 2013 at 1:43 AM
A dumb question, is it compatible with the 1.57 patch? Would love to give it a try!
Lab Assistant
#24 Old 25th Sep 2013 at 3:13 AM
Yes, I've been testing it on 1.57 myself. =) Should be fine with either 1.57 or 1.55, I haven't tried it any further back than that (obviously. )

Intersecting modular stairs.
Test Subject
#25 Old 8th Jul 2014 at 8:58 AM
Default Still ok??
Quote: Originally posted by sammonsim
Yes, I've been testing it on 1.57 myself. =) Should be fine with either 1.57 or 1.55, I haven't tried it any further back than that (obviously. )


I know it's been a while, but I'm interested in the mod too. Is it compatible with 1.67?
Page 1 of 2
Back to top