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
Test Subject
Original Poster
#1 Old 19th Jun 2022 at 5:18 PM
Default Missing custom interactions when adding a lot from the library
Hi everyone,

I found that when I add a lot to my homeworld from my library and want to launch a custom interaction with an object (for example a custom interaction on a computer), the interaction will not show up until I save the game and reload the world...

Here's my OnWorldLoadFinished method:

Code:
public static void OnWorldLoadFinished(object sender, EventArgs e)
        {
            foreach (Computer computer in Sims3.Gameplay.Queries.GetObjects<Computer>())
            {
                AddInteractions(computer);
            }
            EventTracker.AddListener(EventTypeId.kBoughtObject, new ProcessEventDelegate(Instantiator.OnObjectChanged));
            EventTracker.AddListener(EventTypeId.kObjectStateChanged, new ProcessEventDelegate(Instantiator.OnObjectChanged));
            EventTracker.AddListener(EventTypeId.kInventoryObjectAdded, new ProcessEventDelegate(Instantiator.OnObjectChanged));


Is there any EventTracker that I'm missing for the library thing?

Thanks for your help,

P16
Advertisement
Field Researcher
#2 Old 19th Jun 2022 at 5:37 PM
I haven't tried it. But I just looked through the EventIDs and there is a: "EventTypeId.kBoughtObjectInEditTownMode" that might work? Might be at least worth a try.
Space Pony
#3 Old 19th Jun 2022 at 7:05 PM
You might want to try World.OnObjectPlacedInLotEventHandler:

Code:
public static void OnWorldLoadFinished(object sender, EventArgs e)
{
    foreach (Computer computer in Sims3.Gameplay.Queries.GetObjects<Computer>())
    {
        AddInteractions(computer);
    }
    World.OnObjectPlacedInLotEventHandler += OnObjectPlacedInLot;
    EventTracker.AddListener(EventTypeId.kObjectStateChanged, new ProcessEventDelegate(Instantiator.OnObjectChanged));
    EventTracker.AddListener(EventTypeId.kInventoryObjectAdded, new ProcessEventDelegate(Instantiator.OnObjectChanged));
}

private static void OnObjectPlacedInLot(object sender, EventArgs e)
{
    if (e is World.OnObjectPlacedInLotEventArgs onObjectPlacedInLotEventArgs && GameObject.GetObject(onObjectPlacedInLotEventArgs.ObjectId) is Computer computer)
    {
        AddInteractions(computer);
    }
}


I just ran a quick test in-game and it seems to work for me.

"The Internet is the first thing that humanity has built that humanity doesn't understand, the largest experiment in anarchy that we have ever had." - Eric Schmidt

If you enjoy the mods I put out, consider supporting me on patreon: www.patreon.com/Gamefreak130
Test Subject
Original Poster
#4 Old 19th Jun 2022 at 9:49 PM Last edited by P16 : 19th Jun 2022 at 10:17 PM.
Quote: Originally posted by gamefreak130
You might want to try World.OnObjectPlacedInLotEventHandler:

Code:
public static void OnWorldLoadFinished(object sender, EventArgs e)
{
    foreach (Computer computer in Sims3.Gameplay.Queries.GetObjects<Computer>())
    {
        AddInteractions(computer);
    }
    World.OnObjectPlacedInLotEventHandler += OnObjectPlacedInLot;
    EventTracker.AddListener(EventTypeId.kObjectStateChanged, new ProcessEventDelegate(Instantiator.OnObjectChanged));
    EventTracker.AddListener(EventTypeId.kInventoryObjectAdded, new ProcessEventDelegate(Instantiator.OnObjectChanged));
}

private static void OnObjectPlacedInLot(object sender, EventArgs e)
{
    if (e is World.OnObjectPlacedInLotEventArgs onObjectPlacedInLotEventArgs && GameObject.GetObject(onObjectPlacedInLotEventArgs.ObjectId) is Computer computer)
    {
        AddInteractions(computer);
    }
}


I just ran a quick test in-game and it seems to work for me.


I've tried your code, but the code didn't work and only give me an errror with the World.OnObjectPlacedInLotEventHandler part and cannot build the solution...
(they say that they didn't recognize the onObjectPlacedInLotEventArgs part and the Computer computer too.)

@KittyTheSnowcat I've also tried your method, but it didn't work in game.
Space Pony
#5 Old 20th Jun 2022 at 1:41 AM
Quote: Originally posted by P16
I've tried your code, but the code didn't work and only give me an errror with the World.OnObjectPlacedInLotEventHandler part and cannot build the solution...
(they say that they didn't recognize the onObjectPlacedInLotEventArgs part and the Computer computer too.)


Are you using SharpDevelop? If so, that code won't work. Try this instead:

Code:
World.OnObjectPlacedInLotEventArgs onObjectPlacedInLotEventArgs = e as World.OnObjectPlacedInLotEventArgs;
if (onObjectPlacedInLotEventArgs != null)
{
    Computer computer = GameObject.GetObject(onObjectPlacedInLotEventArgs.ObjectId) as Computer;
    if (computer != null)
    {
        AddInteractions(computer);
    }
}

"The Internet is the first thing that humanity has built that humanity doesn't understand, the largest experiment in anarchy that we have ever had." - Eric Schmidt

If you enjoy the mods I put out, consider supporting me on patreon: www.patreon.com/Gamefreak130
Test Subject
Original Poster
#6 Old 20th Jun 2022 at 3:07 AM Last edited by P16 : 23rd Jun 2022 at 12:26 PM.
Now the code is working (let me build the solution), but is not working in the game, so the computer won't have the interaction when I add a lot to my homeworld from my library...

At least it's a minor bug and only have to replace the computer by hand if I want to use the interaction before I reload the save...
Back to top