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!
Quick Reply
Search this Thread
Senior Moderator
staff: senior moderator
Original Poster
#1 Old 1st Jan 2020 at 12:01 PM
Default Event Listener for new non-buyable objects
Aaand I'm back with another question...

So I am trying to add a custom Clean Up interaction to dishes, and I have the interaction itself working, when it's added to all "serving containers" with the OnWorldLoadFinishedEventHandler.

For adding interactions to buyable objects like sinks, I used the kBoughtObject event listener thingy, but things like plates of food aren't bought, and so the interaction isn't added for dishes that weren't in the world to begin with. I couldn't find a suitable event for when an object like a serving container is added to the world, so I thought i would ask here before I completely give up on my dreams...
Just kidding

But I am really hoping this is possible, so if there is an event that would be suitable, or if there's another way to do this, I would be very grateful for some help.

(ps happy new year!)
Advertisement
Space Pony
#2 Old 1st Jan 2020 at 3:41 PM
Happy new Year !

well you could intercept the foodcreation and add an event (or just a methodcall) yourself eg. replacing Fridge_Have.Singleton wih your own version.
This would only apply to newly created dishes, so if already placed dishes needed to be changed you woul need to iterate through the objects and add the interaction to each dish object.

But probably the easiest solution would be to use the kObjectStateChanged event below is an example

Code:
//in your ctor
EventTracker.AddListener (EventTypeId.kObjectStateChanged, new ProcessEventDelegate (DishCreated));
//
		static ListenerAction DishCreated(Event e)
		{
			Sims3.Gameplay.Objects.CookingObjects.ServingContainerSingle dish = e.TargetObject as Sims3.Gameplay.Objects.CookingObjects.ServingContainerSingle;
			if(dish ==null){return ListenerAction.Keep;}
			
			//dish.Addinteraction ... implement me
			return ListenerAction.Keep;
		}


Monitor your ingame performance though
Senior Moderator
staff: senior moderator
Original Poster
#3 Old 1st Jan 2020 at 6:21 PM
Thanks for your help again, Battery.
I tried using kObjectStateChanged and it seems to work for some dishes but not all. Like a quick meal item like soup or bread and jam worked fine, my interaction was added, but for regular dishes like the autumn salad (both the plate with food and the empty plate, and also the empty serving dish) didn't have my interaction added.

In the method called by the kObjectStateChanged event, I added the interaction to ServingContainers, ServingContainerSingles, and ServingContainerGroup, though I'm not sure of this is necessary because the -Single and -Group ones are derived from the ServingContainer. And i think the Plate object is derived from ServingContainer Single. If you add an interaction to a class, will derived classes also inherit the added interaction?

i think they must do, as the quick meal plates had my interaction, and the Plate object is derived from the ServingContainerSingle, and i only added it to the ServingContainerSingles, not the Plate object, but then what is the difference between the regular plates and the quick meal plates?
Much confusion there
Space Pony
#4 Old 1st Jan 2020 at 6:29 PM
Hey Zoe,

Derived Types wont inherit changes made to their baseclasses at runtime at least they should not...

As for your other uestions i would have to do some "research" myself

ps if you give me the file i should be able to do the testing faster since i dont need to rip my mods apart and add the incomplete interactions plus i would know better in which way you are trying to alter the game (this is not necessary but it would help me saving some time )
Senior Moderator
staff: senior moderator
Original Poster
#5 Old 1st Jan 2020 at 6:45 PM Last edited by zoe22 : 4th Jan 2020 at 7:37 PM.
Here it is
Thank you
Space Pony
#6 Old 1st Jan 2020 at 7:40 PM
Thanks for trusting me,
here its a bit optimized

Code:
		protected static ListenerAction DishCreated(Event e)
		{
			ServingContainer servingContainer = e.TargetObject as  ServingContainer;
			if (servingContainer ==null)
			{
				return ListenerAction.Keep;
			}
			servingContainer.AddInteraction(Interactions.SinkInteractions.CustomCleanUp.Singleton);
			servingContainer.RemoveInteractionByType(ServingContainer.ServingContainer_CleanUp.Singleton);
                        return ListenerAction.Keep;
		}
 


add this for prepared meals
Code:
EventTracker.AddListener (EventTypeId.kCookedMeal, new ProcessEventDelegate (Instantiator.DishCreated));

Im doing some more testing but this seems to work
Senior Moderator
staff: senior moderator
Original Poster
#7 Old 1st Jan 2020 at 9:27 PM
haha of course I trust you! I couldn't do it without you

And it works for adding it to the prepared dish (yay), but when you do serve meal, and then grab a serving, the sim's plate of food doesn't have the custom interaction.
But when I put it in the fridge, and then had the sim get leftovers, the interaction is added then, which I guess is when the object state changes - but it mustn't count as changing state when you take 1 serving from a group serving thing. (In fact every time it's in the fridge and taken out again it adds the interaction again! So I will have to add in a check first so it doesn't keep adding it multiple times lol)

But thank you so much for getting this far!
Space Pony
#8 Old 1st Jan 2020 at 9:58 PM Last edited by Battery : 1st Jan 2020 at 10:43 PM.
Well i just noticed that you just wanted to replace an interaction... so you can ignore everything i wrote and just replace the Singleton

just modify your definition to be public

Code:
Sims3.Gameplay.Objects.CookingObjects.ServingContainer.ServingContainer_CleanUp.Singleton = new Interactions.SinkInteractions.CustomCleanUp.Definition();


Sorry i dont know what happened since i just did something like that a few days before. I was to focussed on the Event system that i didnt think what the problem actually was and which tool to use to solve it...
Senior Moderator
staff: senior moderator
Original Poster
#9 Old 1st Jan 2020 at 10:29 PM
Ahhhh I didn't know you could do that. That's a lot more convenient, with all the interactions I'm trying to add and remove.
So do I put this in the OnWorldLoadFinished method thing?
Space Pony
#10 Old 1st Jan 2020 at 10:42 PM
yes you can replace everything in your OnWorldLoadFinished method that was dedicated to add the interactions before with the one line ...
Back to top