Page 1 of 1

Object activation question

Posted: Tue Sep 14, 2021 4:27 pm
by Caffinator
I've had partial progress with a simple mod I'm building, but so far only by adding to existing source code. In order to make it a proper mod, I'm trying to use the PlayerActivate.RegisterCustomActivation method to inject the code.
The problem I'm running into is that PlayerActivate.RegisterCustomActivation requires that the referenced function must be static and I need to reference the activated object (specifically, getting to the loot data is there is any). I figure there is probably a way to use the RaycastHit object passed to the function to get the object instance, but not certain how to do so. Any suggestions? Thanks!

Re: Object activation question

Posted: Tue Sep 14, 2021 5:55 pm
by pango
Use PlayerActivate.LootCheck(), or some similar code?

Re: Object activation question

Posted: Tue Sep 14, 2021 6:22 pm
by Caffinator
pango wrote: Tue Sep 14, 2021 5:55 pm Use PlayerActivate.LootCheck(), or some similar code?
Well specifically, I want to modify properties of the in-world container object based on the contents of the container.
If I can use PlayerActivate.RegisterCustomActivation then I would want something like this:

Code: Select all

public static void ActivateContainer(RaycastHit hit)
    {
        GameObject go;
        go = hit.GetReferenceToInWorldContainerObject();
        UpdateContainer(go);
    }

Re: Object activation question

Posted: Tue Sep 14, 2021 6:41 pm
by Ralzar
Try registering to PlayerActivate.OnLootSpawned.

Like this:

https://github.com/Ralzar81/ThiefOverha ... aul.cs#L67

Re: Object activation question

Posted: Tue Sep 14, 2021 7:57 pm
by Caffinator
Ralzar wrote: Tue Sep 14, 2021 6:41 pm Try registering to PlayerActivate.OnLootSpawned.

Like this:

https://github.com/Ralzar81/ThiefOverha ... aul.cs#L67
Ah. great example! If the object parameter passed is what I hope it is, this should work fine. Thanks!

Re: Object activation question

Posted: Wed Sep 15, 2021 4:52 pm
by Caffinator
I've ended up going back to using PlayerActivate.RegisterCustomActivation as it seems like OnLootSpawned isn't being called in my case.
For anyone that wants to use PlayerActivate.RegisterCustomActivation, I noticed this code in PlayerActivate:

Code: Select all

        private bool LootCheck(RaycastHit hitInfo, out DaggerfallLoot loot)
        {
            loot = hitInfo.transform.GetComponent<DaggerfallLoot>();

            return loot != null;
        }
Further experimentation showed that the RaycastHit hitInfo parameter passed to Activate gives you the activated in-game world object (hitInfo.transform = in-world object instance... BINGO!).