Object activation question

Discuss modding questions and implementation details.
Post Reply
Caffinator
Posts: 11
Joined: Wed Aug 11, 2021 9:34 pm

Object activation question

Post 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!

User avatar
pango
Posts: 3347
Joined: Wed Jul 18, 2018 6:14 pm
Location: France
Contact:

Re: Object activation question

Post by pango »

Use PlayerActivate.LootCheck(), or some similar code?
Mastodon: @pango@fosstodon.org
When a measure becomes a target, it ceases to be a good measure.
-- Charles Goodhart

Caffinator
Posts: 11
Joined: Wed Aug 11, 2021 9:34 pm

Re: Object activation question

Post 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);
    }

User avatar
Ralzar
Posts: 2211
Joined: Mon Oct 07, 2019 4:11 pm
Location: Norway

Re: Object activation question

Post by Ralzar »

Try registering to PlayerActivate.OnLootSpawned.

Like this:

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

Caffinator
Posts: 11
Joined: Wed Aug 11, 2021 9:34 pm

Re: Object activation question

Post 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!

Caffinator
Posts: 11
Joined: Wed Aug 11, 2021 9:34 pm

Re: Object activation question

Post 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!).

Post Reply