- Site Map >
- Modding and Creation >
- Sims 3 Creation >
- Modding Discussion >
- Sleep on sofa
- Site Map >
- Modding and Creation >
- Sims 3 Creation >
- Modding Discussion >
- Sleep on sofa
#1
14th Apr 2010 at 12:06 AM
Last edited by lytefoot : 15th Apr 2010 at 1:51 AM.
Posts: 235
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:
Class1.cs.txt (17.0 KB, 205 downloads) | ||
Description: my code (updated 4/14) |
Advertisement
#2
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();
#3
14th Apr 2010 at 4:49 AM
Posts: 235
No, I have that. I gave it a constant float number (since the sofa lacks bed tuning).
#4
14th Apr 2010 at 6:41 PM
Posts: 1,115
Thanks: 37005 in 225 Posts
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.
You probably should call
base.BeginCommodityUpdate(CommodityKind.Energy, someNumber);
before
base.BeginCommodityUpdates();
If you already have that in, please update the code.
#5
15th Apr 2010 at 1:51 AM
Posts: 235
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
#6
15th Apr 2010 at 3:38 PM
Posts: 1,115
Thanks: 37005 in 225 Posts
Hmm, can you upload the whole package?
#7
16th Apr 2010 at 4:07 PM
Posts: 235
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).
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:
lytefoot_SleeperSofa.zip (871.6 KB, 174 downloads) - View custom content | ||||||||||
1132443 04-16-10 09:51 lytefoot_SleeperSofa.package -------- ------- 1132443 1 file |
#8
16th Apr 2010 at 9:50 PM
Posts: 1,115
Thanks: 37005 in 225 Posts
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.
- 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.
#9
17th Apr 2010 at 2:38 AM
Posts: 235
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
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
#10
28th Apr 2010 at 2:00 PM
Posts: 1,227
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...
...Titanium white...
Test Subject
#11
8th Aug 2011 at 12:54 AM
Posts: 2
Guess this never happened? Would be awesome if it did. How am i suppose to created my "Guy on the couch" sim without it?
#12
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.
#13
11th Nov 2011 at 4:14 AM
Posts: 474
Thanks: 205 in 1 Posts
I was wondering how this was coming along, and if you ever figured out how to do it.
#14
1st Aug 2012 at 3:22 AM
Posts: 5
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?
#15
1st Aug 2012 at 5:21 AM
Posts: 6,105
Thanks: 12809 in 71 Posts
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.
Ask here if you're trying to implement the thing yourself.
#16
2nd Aug 2012 at 1:25 AM
Posts: 5
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!
#17
2nd Aug 2012 at 1:55 AM
Posts: 6,105
Thanks: 12809 in 71 Posts
No worries! Just clarifying. Welcome to MTS
#18
2nd Aug 2012 at 2:37 AM
Posts: 5
Thank you!
Lab Assistant
#19
22nd Sep 2013 at 2:57 AM
Posts: 210
Thanks: 1249 in 3 Posts
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
Intersecting modular stairs.
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:
SofaSleep.rar (13.4 KB, 72 downloads) - View custom content | ||||||||||
Size Packed Ratio Date Time Attr CRC Meth Ver ------------------------------------------------------------------------------- SofaSleep.cs 15457 3613 23% 21-09-13 18:21 .....A. FB1DB2EC m3b 2.9 Instantiator.cs 1618 608 37% 21-09-13 17:26 .....A. 4D4F53E9 m3b 2.9 SleepOnSofa.package 11546 9296 80% 21-09-13 18:28 .....A. 479467E9 m3b 2.9 ------------------------------------------------------------------------------- 3 28621 13517 47% |
||||||||||
Description: contains code files and mod package for testing (built with 1.55) |
Intersecting modular stairs.
#20
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:
So you're better off applying the interaction to MultiSeatObject, Couch or IHasSeatingGroup.
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
22nd Sep 2013 at 1:07 PM
Posts: 210
Thanks: 1249 in 3 Posts
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.)
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.
Intersecting modular stairs.
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:
SofaSleep - fixed code.rar (4.0 KB, 69 downloads) - View custom content | ||
Size Packed Ratio Date Time Attr CRC Meth Ver ------------------------------------------------------------------------------- SofaSleep.cs 14513 3383 23% 22-09-13 02:59 .....A. 8BC3CD8F m3b 2.9 Instantiator.cs 1594 571 35% 22-09-13 02:47 .....A. B60A95A8 m3b 2.9 ------------------------------------------------------------------------------- 2 16107 3954 24% |
Intersecting modular stairs.
Lab Assistant
#22
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
Posts: 210
Thanks: 1249 in 3 Posts
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!
Intersecting modular stairs.
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:
SleepHere code.rar (5.4 KB, 289 downloads) - View custom content | ||||||||||
Size Packed Ratio Date Time Attr CRC Meth Ver ------------------------------------------------------------------------------- Instantiator.cs 2011 630 31% 23-09-13 21:32 .....A. 05103FC5 m3b 2.9 SofaDreamAbout.cs 4226 989 23% 23-09-13 21:33 .....A. 4D210964 m3b 2.9 SofaSleep.cs 15708 3696 23% 24-09-13 10:12 .....A. CE31B7D9 m3b 2.9 ------------------------------------------------------------------------------- 3 21945 5315 24% |
||||||||||
SleepOnSofa.package.rar (10.6 KB, 788 downloads) - View custom content | ||||||||||
Size Packed Ratio Date Time Attr CRC Meth Ver ------------------------------------------------------------------------------- SleepOnSofa.package 14814 10725 72% 24-09-13 11:30 .....A. 23BC4F1B m3b 2.9 ------------------------------------------------------------------------------- 1 14814 10725 72% |
Intersecting modular stairs.
#23
25th Sep 2013 at 1:43 AM
Posts: 504
A dumb question, is it compatible with the 1.57 patch? Would love to give it a try!
Lab Assistant
#24
25th Sep 2013 at 3:13 AM
Posts: 210
Thanks: 1249 in 3 Posts
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.
Intersecting modular stairs.
Test Subject
#25
8th Jul 2014 at 8:58 AM
Posts: 3
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?
Who Posted
|