Custom Flat & Model Activation

Discuss modding questions and implementation details.
User avatar
BadLuckBurt
Posts: 948
Joined: Sun Nov 05, 2017 8:30 pm

Custom Flat & Model Activation

Post by BadLuckBurt »

This is a quick tutorial for modders on how to add custom activation to flats and models which will become available in the next release.

PREREQUISITES

1. Load the UnityEngine and DaggerfallWorkshop.Game namespaces in your mod, you can achieve this by adding the following lines at the top of your mod class file:

Code: Select all

using UnityEngine;
using DaggerfallWorkshop.Game;
2. The model ID(s) and / or the texture archive - record combinations that you want to attach custom activation to. You can find these using Daggerfall Modeling (https://www.dfworkshop.net/downloads/da ... modelling/) and Daggerfall Imaging (https://www.dfworkshop.net/downloads/da ... l-imaging/).

3. Your mod class will need methods that handle the custom activation, they need to be set up as follows:

Code: Select all

private static void ExampleActivation(RaycastHit hit) {
//Your code here
}
When you have this in place and know what models / flats you want to attach the custom activation to, the next step is to add a call to PlayerActivate.RegisterCustomActivation like this:

Code: Select all

//For flats
PlayerActivate.RegisterCustomActivation(mod, 211, 20, ExampleActivation);
//For models
PlayerActivate.RegisterCustomActivation(mod, 41005, ExampleActivation);
I recommend you add the calls to RegisterCustomActivation in the init method of your mod.

LOAD PRIORITY
The RegisterCustomActivation method adheres to the load order priority for mods and will log any failed registration to the output_log so check there if you have trouble getting your activations registered.

Look for the following line: 'Denied custom activation registration from <Mod1> for <ObjectName> | <Mod2> has higher load priority'
This will tell you what mod is interfering with your registration.

I have put up a demo version that showcases the functionality through a mod: https://github.com/BadLuckBurt/dfu-cust ... o/releases. To try this showcase, go to the Daggerfall region and search for 'Custom' on the travel map, it's a tiny dungeon that consists of 1 room with various objects you can activate.

The source.zip on the release page contains the entire mod, the master branch on Github already contains code for the next stage: custom dialog buttons but until that is merged, it won't be compatible with the main DFU release.
DFU on UESP: https://en.uesp.net/w/index.php?title=T ... fall_Unity
DFU Nexus Mods: https://www.nexusmods.com/daggerfallunity
My github repositories with mostly DFU related stuff: https://github.com/BadLuckBurt

.

Asesino
Posts: 66
Joined: Fri Aug 16, 2019 3:14 am

Re: Custom Flat & Model Activation

Post by Asesino »

Hi @BadLuckBurt,
I just tried this out and it worked without a hitch! I added crates to it and was able to trigger them. I was thinking about creating a mod that puts loot into crates, bookshelves, weapon racks, etc. in dungeons so that they are more useful than just eye candy.

This turned that effort much easier!

Thank you so much for this.

a

User avatar
BadLuckBurt
Posts: 948
Joined: Sun Nov 05, 2017 8:30 pm

Re: Custom Flat & Model Activation

Post by BadLuckBurt »

Asesino wrote: Wed Apr 22, 2020 6:48 pm Hi @BadLuckBurt,
I just tried this out and it worked without a hitch! I added crates to it and was able to trigger them. I was thinking about creating a mod that puts loot into crates, bookshelves, weapon racks, etc. in dungeons so that they are more useful than just eye candy.

This turned that effort much easier!

Thank you so much for this.

a
You're welcome but model activation was already implemented by Hazelnut some time ago. I just extended it to flats and unified the code a bit. In any case, good to hear that it was so easy for you to use, hopefully more people will follow :D

Looking forward to what you're going to do with this!
DFU on UESP: https://en.uesp.net/w/index.php?title=T ... fall_Unity
DFU Nexus Mods: https://www.nexusmods.com/daggerfallunity
My github repositories with mostly DFU related stuff: https://github.com/BadLuckBurt

.

Asesino
Posts: 66
Joined: Fri Aug 16, 2019 3:14 am

Re: Custom Flat & Model Activation

Post by Asesino »

BadLuckBurt wrote: Wed Apr 22, 2020 7:30 pm
Asesino wrote: Wed Apr 22, 2020 6:48 pm Hi @BadLuckBurt,
I just tried this out and it worked without a hitch! I added crates to it and was able to trigger them. I was thinking about creating a mod that puts loot into crates, bookshelves, weapon racks, etc. in dungeons so that they are more useful than just eye candy.

This turned that effort much easier!

Thank you so much for this.

a
You're welcome but model activation was already implemented by Hazelnut some time ago. I just extended it to flats and unified the code a bit. In any case, good to hear that it was so easy for you to use, hopefully more people will follow :D

Looking forward to what you're going to do with this!
Ah, I was not aware of that. Thank you both; everytime I log in, there is something new to play with!

Keep up the excellent work!
a

User avatar
AlexanderSig
Posts: 324
Joined: Wed Jul 19, 2017 10:35 pm

Re: Custom Flat & Model Activation

Post by AlexanderSig »

Hey, is there any way to get this to work for flats and models after they have been replaced by a different 3d model? For example creating compatibility between viewtopic.php?t=3833 and viewtopic.php?f=27&t=583 mods?

User avatar
Hazelnut
Posts: 3015
Joined: Sat Aug 26, 2017 2:46 pm
Contact:

Re: Custom Flat & Model Activation

Post by Hazelnut »

It should just work when replacing models, but when replacing flats with models it depends what name the game object is given by the replacer code which I am not sure about.
See my mod code for examples of how to change various aspects of DFU: https://github.com/ajrb/dfunity-mods

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

Re: Custom Flat & Model Activation

Post by Ralzar »

I have heard that it sometimes works. For example: it’s possible to use the camp fire, but not the fire in a metal bowl.

User avatar
AlexanderSig
Posts: 324
Joined: Wed Jul 19, 2017 10:35 pm

Re: Custom Flat & Model Activation

Post by AlexanderSig »

Ralzar wrote: Sat Aug 22, 2020 5:12 pm I have heard that it sometimes works. For example: it’s possible to use the camp fire, but not the fire in a metal bowl.
I made some progress. By adding a collision box to the torch models it is possible to pick them up with torch taker and handpainted models loaded together. However, the torch doesn't disappear when it's picked up so you can pick up an infinite amount of torches...

Maybe I could add a script to the torch prefabs so it destroys them when activated? However I have no coding experience, if you could write the code I could implement it and send you a compatibility version.

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

Re: Custom Flat & Model Activation

Post by Ralzar »

Do you have your code on github or something? I'll take a look when I can. What is probably happening is that you're making a new object with a different name. My code does not deactivate that object and so it stays there to be clicked again.

User avatar
AlexanderSig
Posts: 324
Joined: Wed Jul 19, 2017 10:35 pm

Re: Custom Flat & Model Activation

Post by AlexanderSig »

Ralzar wrote: Sun Aug 23, 2020 7:59 am Do you have your code on github or something? I'll take a look when I can. What is probably happening is that you're making a new object with a different name. My code does not deactivate that object and so it stays there to be clicked again.
Probably best to check out the mesh replacement scripts that are part of DF Unity on github. I haven't written any code personally for my mod. I just create prefabs in unity with filenames like "210_16" and load them with the mod builder.

Post Reply