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
Lab Assistant
Original Poster
#1 Old 16th Dec 2021 at 3:57 PM
Default A mod for mummies - EventHandler Issues
Hello!
I am currently working on a mod for mummies.
I have added several abilities to them, but I have one problem. One of their powers is summoning a sarcophagus on their target location from thin air, it works just fine. But, I also want to make it so that they can click on the sarcophagus and summon mummies from it. It works! But... It only works on sarcopgahi bought from buy-mode, and thats probably because of the eventhandler I'm using (kBoughtObject).

Does anyone have any idea what evenhandler I should use to add my custom "summon mummy" interaction to sarcophagi created "out of thin air"?
Advertisement
Space Pony
#2 Old 17th Dec 2021 at 12:28 AM
Quote: Originally posted by xantak22
Hello!
I am currently working on a mod for mummies.
I have added several abilities to them, but I have one problem. One of their powers is summoning a sarcophagus on their target location from thin air, it works just fine. But, I also want to make it so that they can click on the sarcophagus and summon mummies from it. It works! But... It only works on sarcopgahi bought from buy-mode, and thats probably because of the eventhandler I'm using (kBoughtObject).

Does anyone have any idea what evenhandler I should use to add my custom "summon mummy" interaction to sarcophagi created "out of thin air"?


Instead of kBoughtObject, I usually use the World.OnObjectPlacedInLotEventHandler event delegate, which you use in a similar way to World.OnWorldLoadFinishedEventHandler:

Code:
World.OnObjectPlacedInLotEventHandler += OnObjectPlacedInLot;

public static void OnObjectPlacedInLot(object sender, EventArgs e)
{
    if (e is World.OnObjectPlacedInLotEventArgs onObjectPlacedInLotEventArgs)
    {
        if (GameObject.GetObject(onObjectPlacedInLotEventArgs.ObjectId) is Sarcophagus sarcophagus)
        {
            // Add interactions to sarcophagus
        }
    }
}


You might also consider using the kObjectStateChanged and kInventoryObjectAdded events as well.

"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
Lab Assistant
Original Poster
#3 Old 17th Dec 2021 at 8:15 AM Last edited by xantak22 : 17th Dec 2021 at 8:57 AM.
Quote: Originally posted by gamefreak130
Instead of kBoughtObject, I usually use the World.OnObjectPlacedInLotEventHandler event delegate, which you use in a similar way to World.OnWorldLoadFinishedEventHandler:

Code:
World.OnObjectPlacedInLotEventHandler += OnObjectPlacedInLot;

public static void OnObjectPlacedInLot(object sender, EventArgs e)
{
    if (e is World.OnObjectPlacedInLotEventArgs onObjectPlacedInLotEventArgs)
    {
        if (GameObject.GetObject(onObjectPlacedInLotEventArgs.ObjectId) is Sarcophagus sarcophagus)
        {
            // Add interactions to sarcophagus
        }
    }
}


You might also consider using the kObjectStateChanged and kInventoryObjectAdded events as well.


Thank you so much for your reply! Unfortunately that doesn't seem to work either.
Perhaps it's just not possible to add interactions to objects created in game from "thin air". But atleast it works on sarcophagi bought from buy mode and it also works if I move the sarcophagus in build mode.

Code:
        private static EventListener sNewSarco = null;

        private static EventListener sNewSarco2 = null;

        private static EventListener sNewSarco3 = null;

        static MummyInteractions()
        {
            World.OnObjectPlacedInLotEventHandler += OnObjectPlacedInLot;
            World.sOnWorldLoadFinishedEventHandler += new EventHandler(OnWorldLoadFinishedHandler);
        }

        public static void OnObjectPlacedInLot(object sender, EventArgs e)
        {
            if (e is World.OnObjectPlacedInLotEventArgs onObjectPlacedInLotEventArgs)
            {
                if (GameObject.GetObject(onObjectPlacedInLotEventArgs.ObjectId) is Sarcophagus sarco)
                {
                    AddSarcoInteractions(sarco);
                }
                sNewSarco = EventTracker.AddListener(EventTypeId.kInventoryObjectAdded, OnSarcoInstantiated);
                sNewSarco2 = EventTracker.AddListener(EventTypeId.kBoughtObject, OnSarcoInstantiated);
                sNewSarco3 = EventTracker.AddListener(EventTypeId.kObjectStateChanged, OnSarcoInstantiated);
            }
        }

        private static void AddSarcoInteractions(Sarcophagus sarco)
        {
            sarco.AddInteraction(MummySummonTest.Singleton, true);
        }
Lab Assistant
Original Poster
#4 Old 17th Dec 2021 at 9:04 AM
Never mind, I got it to work!
I simply added this line of code in the run method:
Code:
EventTracker.SendEvent(EventTypeId.kBoughtObject, base.Actor, gameObject);
Space Pony
#5 Old 17th Dec 2021 at 3:34 PM
Quote: Originally posted by xantak22
Never mind, I got it to work!
I simply added this line of code in the run method:
Code:
EventTracker.SendEvent(EventTypeId.kBoughtObject, base.Actor, gameObject);


I would actually advise against this if you can avoid it, since it could potentially cause issues with other game mechanics that rely on that event. For example, if a Sim has a wish to buy a sarcophagus, that wish could be fulfilled even though they didn't actually buy the object through build/buy.

Try using the World.OnObjectLotUpdateEventHandler instead, with the same syntax as OnObjectPlacedOnLot. I just tested in-game and it seems to work for objects created out of world and subsequently placed on a lot:

Code:
World.OnObjectLotUpdateEventHandler+= OnObjectLotUpdate;
     
public static void OnObjectLotUpdate(object sender, EventArgs e)
{
    if (e is World.OnObjectLotUpdateEventArgs onObjectLotUpdateEventArgs)
    {
        if (GameObject.GetObject(onObjectLotUpdateEventArgs.ObjectId) is Sarcophagus sarcophagus)
        {
            // Add interactions to sarcophagus
        }
    }
}

"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
Lab Assistant
Original Poster
#6 Old 17th Dec 2021 at 4:44 PM
Quote: Originally posted by gamefreak130
I would actually advise against this if you can avoid it, since it could potentially cause issues with other game mechanics that rely on that event. For example, if a Sim has a wish to buy a sarcophagus, that wish could be fulfilled even though they didn't actually buy the object through build/buy.

Try using the World.OnObjectLotUpdateEventHandler instead, with the same syntax as OnObjectPlacedOnLot. I just tested in-game and it seems to work for objects created out of world and subsequently placed on a lot:

Code:
World.OnObjectLotUpdateEventHandler+= OnObjectLotUpdate;
     
public static void OnObjectLotUpdate(object sender, EventArgs e)
{
    if (e is World.OnObjectLotUpdateEventArgs onObjectLotUpdateEventArgs)
    {
        if (GameObject.GetObject(onObjectLotUpdateEventArgs.ObjectId) is Sarcophagus sarcophagus)
        {
            // Add interactions to sarcophagus
        }
    }
}


Ok, luckily I don't think sims can get wants to buy a sarcophagus, but I'll definately keep that in mind for other objects in the future.
Space Pony
#7 Old 17th Dec 2021 at 7:11 PM
I am not sure why youre going the way of adding an event handler when you are in control of the objects creation (if i gathered that correctly). wouldnt just adding the interactions after instancing the object do just fine ?
Lab Assistant
Original Poster
#8 Old 17th Dec 2021 at 7:16 PM
Quote: Originally posted by Battery
I am not sure why youre going the way of adding an event handler when you are in control of the objects creation (if i gathered that correctly). wouldnt just adding the interactions after instancing the object do just fine ?

Maybe that could also work, but I think I can stick with eventhandlers for now.
Back to top