- Site Map >
- Modding and Creation >
- Sims 3 Creation >
- Modding Discussion >
- My apartments & roommates fix mod issues...
- Site Map >
- Modding and Creation >
- Sims 3 Creation >
- Modding Discussion >
- My apartments & roommates fix mod issues...
#51
15th Aug 2015 at 7:19 AM
Last edited by pjsutton : 15th Aug 2015 at 7:58 AM.
Posts: 289
Thanks: 1021 in 2 Posts
If anyone is still reading this ... I hope so! ... I'm having a problem with the HouseholdUpdateEvent:
The HouseholdUpdate does what I want it to the first time I switch active households, but then never again. I have this in my OnWorldLoadFinished:
Did I forget something somewhere? Do I need to put a "ListenerAction.Remove" somewhere?
I (sort of) think that I got this to work - I have multiple lots with roommates on them at the same time! I'm having a problem though ... let me share this:
One of the problems I'm having is that the "first" roommate on Lot A that it saves also reappears in Lot B when I switch. When I go back to Lot A, it also re-adds the same person. And that person keeps going back and forth. I don't understand if it's a problem with my code with all the "activeLotId" changes going on or not.
I didn't post the rest of the code because it doesn't really pertain to these 3 methods... Hopefully someone can follow my way of thinking there with all the for each loops. It looks convoluted, but I used a similar process for creating a list of lot IDs and adding it a set number of times based on how many roommates are selected, and then retrieving that number by counting the number of IDs == Household.Active Household.LotId. and that works successfully.
Code:
public static ListenerAction RestoreRoommateStatus(Event e) { HouseholdUpdateEvent h = e as HouseholdUpdateEvent; if (h != null) { Household newHousehold = h.Household; ulong activeLotId2 = h.Household.LotId; { if (Household.ActiveHousehold != null && Household.ActiveHouseholdLot != null && Household.ActiveHouseholdLot.IsApartmentLot) { // Lot oldActiveLot = e.OldActiveLot; // Lot newActiveLot = e.NewActiveLot; // ulong activeLotId2 = Household.ActiveHousehold.LotId; // RoommateStatusShown = false; string result; string NewAddress = Sims3.SimIFace.World.GetLotAddress(activeLotId2); if (Household.ActiveHousehold != null && RoommatesStatus.Contains(activeLotId2) && activeLotId2 == Household.ActiveHouseholdLot.LotId) { Household.RoommateManager.mAcceptingRoommates = true; result = Localization.LocalizeString("Gameplay/Interactions/Roommates:Disable", new object[0]); StyledNotification.Format formatC = new StyledNotification.Format("Roommate Services are currently enabled on " + NewAddress + ". This setting has been retrieved from the last time this lot was opened and reset to its previous state. ", ObjectGuid.InvalidObjectGuid, ObjectGuid.InvalidObjectGuid, StyledNotification.NotificationStyle.kGameMessagePositive); StyledNotification.Show(formatC); RoommatesFix.StartAcceptingRoommates(Household.ActiveHousehold); RoommatesFix.BuildRoommateDictionary(); } if (Household.ActiveHousehold != null && !RoommatesStatus.Contains(activeLotId2) && activeLotId2 == Household.ActiveHouseholdLot.LotId) { RoommatesStatus.Remove(activeLotId2); Household.RoommateManager.mAcceptingRoommates = false; // Household.RoommateManager.SetMaxRoommateNumber(0); Household.RoommateManager.KickExistingRoommates(); result = Localization.LocalizeString("Gameplay/Interactions/Roommates:Enable", new object[0]); StyledNotification.Format formatD = new StyledNotification.Format("Roommate Services are currently disabled on " + NewAddress + ". This setting has been retrieved from the last time this lot was opened and reset to its previous state. ", ObjectGuid.InvalidObjectGuid, ObjectGuid.InvalidObjectGuid, StyledNotification.NotificationStyle.kGameMessagePositive); StyledNotification.Show(formatD); RoommatesFix.RoommatesCheck(); } //Household.RoommateManager.StopAcceptingRoommates(true); RoommatesFix.RoommatesCheck(); RoommatesFix.AddRoommatesToCurrentLot(); } } } return ListenerAction.Keep; }
The HouseholdUpdate does what I want it to the first time I switch active households, but then never again. I have this in my OnWorldLoadFinished:
Code:
EventTracker.AddListener(EventTypeId.kHouseholdSelected, new ProcessEventDelegate(RestoreRoommateStatus));
Did I forget something somewhere? Do I need to put a "ListenerAction.Remove" somewhere?
I (sort of) think that I got this to work - I have multiple lots with roommates on them at the same time! I'm having a problem though ... let me share this:
Code:
public static void BuildRoommateDictionary() // Scans household and adds any NPC Roommates to RMDictionary in the form <CurrentLotId, Sim> { ulong activeLotId7 = Household.ActiveHousehold.LotId; int count2 = 0; foreach (ulong ID in RoommatesStatus) { if (ID == activeLotId7) { foreach (Sim RM in Household.ActiveHousehold.AllActors) { StyledNotification.Format formatJ = new StyledNotification.Format("YES THIS WORKS - SimDescriptions list ", ObjectGuid.InvalidObjectGuid, ObjectGuid.InvalidObjectGuid, StyledNotification.NotificationStyle.kGameMessagePositive); StyledNotification.Show(formatJ); if (!LotRoommates.Contains(RM)) { if (Household.RoommateManager.IsNPCRoommate(RM)) { LotRoommates.Add(RM); StyledNotification.Format formatK = new StyledNotification.Format("YES THIS WORKS - LotRoommates list ", ObjectGuid.InvalidObjectGuid, ObjectGuid.InvalidObjectGuid, StyledNotification.NotificationStyle.kGameMessagePositive); StyledNotification.Show(formatK); } } } foreach (Sim RM in LotRoommates) { RMDictionary.Add(activeLotId7, RM); count2 += 1; } } Household.RoommateManager.SetMaxRoommateNumber(count2); } } public static void AddRoommatesToCurrentLot() // Scans current sims and adds any that are in RMDictionary but not in the household { ulong activeLotId8 = Household.ActiveHousehold.LotId; foreach (ulong ID in RoommatesStatus) { if (ID == activeLotId8) { if (RMDictionary.ContainsKey(activeLotId8)) { foreach (Sim sim in Household.ActiveHousehold.AllActors) { if (RMDictionary.ContainsValue(sim)) { return; } } Sim roommate = RMDictionary[activeLotId8]; // SimDescription newRM = roommate.SimDescription; RoommatesFix.AddSim(roommate); StyledNotification.Format formatQ = new StyledNotification.Format("Your previous roommates have been returned to this active household.", ObjectGuid.InvalidObjectGuid, ObjectGuid.InvalidObjectGuid, StyledNotification.NotificationStyle.kGameMessagePositive); StyledNotification.Show(formatQ); } } } } public static void AddSim(Sim sim) // Physically add the Sims to the household { if (sim.Household == Household.ActiveHousehold) { return; } if (sim.Household != null) { sim.Household.RemoveSim(sim); } sim.SimDescription.IsNeverSelectable = true; Household.RoommateManager.mRoommates.Add(sim.SimDescription.SimDescriptionId); Household.ActiveHousehold.Add(sim.SimDescription); Household.RoommateManager.AddRoommateInteractions(sim); if (sim.SimDescription.Household != null) { foreach (SimDescription current in sim.Household.SimDescriptions) { if (current != sim.SimDescription) { Relationship relationship = current.GetRelationship(sim.SimDescription, true); relationship.Roommates = true; } } } if (sim.IsSelectable) { sim.OnBecameSelectable(); } Household.RoommateManager.SetupCallbacks(Household.ActiveHousehold); if (Household.ActiveHousehold != null) { Household.ActiveHousehold.OnMemberChanged(sim.SimDescription, sim); } }
One of the problems I'm having is that the "first" roommate on Lot A that it saves also reappears in Lot B when I switch. When I go back to Lot A, it also re-adds the same person. And that person keeps going back and forth. I don't understand if it's a problem with my code with all the "activeLotId" changes going on or not.
I didn't post the rest of the code because it doesn't really pertain to these 3 methods... Hopefully someone can follow my way of thinking there with all the for each loops. It looks convoluted, but I used a similar process for creating a list of lot IDs and adding it a set number of times based on how many roommates are selected, and then retrieving that number by counting the number of IDs == Household.Active Household.LotId. and that works successfully.
Advertisement
#52
16th Aug 2015 at 6:34 AM
Posts: 289
Thanks: 1021 in 2 Posts
Well ........... now I feel like a complete idiot! Somehow in one of my re-writes I borked up my .package file - the XML did not have my Namespace.Class for some reason.
I started completely over with a new package file and made a new The Sims 3 folder for testing purposes and only put in my mod and NoIntro - and it's working again! The HouseholdUpdateEvent it working perfectly now. And I currently -- somehow -- have 1 household with 5 roommates, another with 1. The numbers aren't quite right, but that's an entirely different issue to deal with!
So, thanks for the help -- even though it was mostly my (embarrassing!) problem - I really do feel pretty dumb about the whole thing right now...
I started completely over with a new package file and made a new The Sims 3 folder for testing purposes and only put in my mod and NoIntro - and it's working again! The HouseholdUpdateEvent it working perfectly now. And I currently -- somehow -- have 1 household with 5 roommates, another with 1. The numbers aren't quite right, but that's an entirely different issue to deal with!
So, thanks for the help -- even though it was mostly my (embarrassing!) problem - I really do feel pretty dumb about the whole thing right now...
#53
18th Aug 2015 at 6:04 AM
Posts: 289
Thanks: 1021 in 2 Posts
I finally have it working the way I want! I have multiple sets of roommates on multiple lots, and they stay there -- or at least the correct number will stay there when I switch active households!
The inherent "problem" is that EA uses a list of roommates "mRoommates" that they create and add to when roommates are enabled - which is fine. BUT, when running RoommateValidation (which adds the roommate), there is a part that uses the current number of roommates to determine how many should be added. All they do to get this number is mRoommates.Count - so, if you have roommates on one lot and then go to another to add more, it's still counting the previous ones. I copied/pasted the parts of RoommateValidation where that happens and added it to my custom one - which I'd already edited to change the way rent was collected. I simply changed the line that references mRoommates.Count and changed it to a function that counts roommates on the current lot and Voila! IT WORKS! Other parts of the roommate manager still refernce mRoommates, but they don't try to count it (they only add or remove items from it) so they still seem to function normally...
The inherent "problem" is that EA uses a list of roommates "mRoommates" that they create and add to when roommates are enabled - which is fine. BUT, when running RoommateValidation (which adds the roommate), there is a part that uses the current number of roommates to determine how many should be added. All they do to get this number is mRoommates.Count - so, if you have roommates on one lot and then go to another to add more, it's still counting the previous ones. I copied/pasted the parts of RoommateValidation where that happens and added it to my custom one - which I'd already edited to change the way rent was collected. I simply changed the line that references mRoommates.Count and changed it to a function that counts roommates on the current lot and Voila! IT WORKS! Other parts of the roommate manager still refernce mRoommates, but they don't try to count it (they only add or remove items from it) so they still seem to function normally...
Who Posted
|