Adding Tag-Based Scripting to OC Modules

Desiring to use some custom items in another play-through of the NWN Original Campaign, I discovered that I would need to modify each campaign Modules to enable Tag-Based Scripting. From those who have gone before, I learned that to enable Tag-Based Scripting in a Module, I would have to change the Module’s OnActivateItem and OnModuleLoad Event properties (run the NWN Toolset, open a Module, then Edit > Module Properties > Events) to the built-in x2_mod_def_act and x2_mod_def_load scripts, respectively.

But, if the Module already has a script in one of those properties, to avoid breaking the Module, I would first have to merge the existing script with the Tag-Based Scripting script, or determine a way to handle the existing script. I found that for the OC Modules, they all had a pre-existing script in the OnActivateItem Event, but that script existed for the sole purpose of handling the Stone of Recall item. In these cases, rather than try to merge the existing OnActivateItem script with the x2_mod_def_act script, theoretically I could use Tag-Based Scripting to handle the Stone of Recall by copying the pre-existing script to a new script nw_it_recall (matching the Item Tag of the Stone of Recall). After creating this new script, I could then delete the pre-existing OnActivateItem script and replace it with the x2_mod_def_act script.

However, I have been encountering problems with this approach and I would like to know why. I have found that, starting with the basic 1.69 OC Module, then in the NWN Toolset, changing the OnActivateItem to x2_mod_def_act and OnModuleLoad to x2_mod_def_load, copying the former script (e.g. M2ACTIVATED for Chapter 2) to nw_it_recall, then deleting the former script from the Module before saving, in-game the Module behaves as if it has nothing in the OnActivateItem Event. Even if I modify the script to add debug messages (SendMessageToPC), the messages never display on the activation of the Stone of Recall or any other item.

If I take all of those steps, except leave the former script in the module instead of deleting it, then the Module behaves as it still has the former script for the OnActivateItem Event, in that the Stone of Recall will work, but no item which uses Tag-Based Scripting will work.

If I leave the former script in the module, then edit it to match the contents of the x2_mod_def_act script, and compile it, then Tag-Based Scripting does seem to work. For example, in my Chapter 2 module, I have Tag-Based Scripting working with x2_mod_def_act as my OnActivateItem Event script, but with M2ACTIVATED still as a Script within the module and its content matching x2_mod_def_act.

In summary, in all of these cases, the Module acts as if I never changed the OnActivateItem Event script from the original script.

Initially, I had thought that my installation had issues, but then I tried on a different machine, and even with fresh installations and observed the same behavior. To me, this doesn’t make sense, and I’m wondering why I am encountering this behavior.

I’ve followed the steps you’ve described, and it seems to work just fine for me. Added tagbased scripts to some items in Chapter 1, including the Is_Recall() call to nw_it_recall. No trouble so far.

Eliminating some basic suspects:

  • Are you loading a saved game to test your edits? AFAIK changes to a module won’t show up unless you actually restart the module.

  • Are you attempting to load/reload the OC modules themselves after editing them? If you’ve edited them, and saved them, then they shouldn’t be overriding the originals, but rather saving as custom modules. No edits you made to the original would show up in the original, just in the edited custom module you just created.

1 Like

I think you hit the nail on the head there. I opened the save in Leto and saw that the save itself was saving the OnActivateItem property in the Mod_OnActivtItem variable (Leto Menu > Tools > Advanced Editor, then open Package files > Module (IFO) at the bottom of the list to see the variables). I modified the save properties and then, Tag-Based Scripting worked as I would expect upon the load of the save.

Thank you for identifying my glaring error!

I have had no problem loading the Modules in the NWN Toolset, modifying them, and then saving them in-place. I just save instead of selecting Save As.

1 Like

Thank you for sharing the workaround. :smiley: I didn’t even know that was possible. This looks like it could be super useful for fixing game-breaking scripting bugs even if they crop up mid-playthrough. No more “oh snap, it’s borked, you’re gonna need to start a new playthrough”!


^- You’re not getting these message at all? Ignore the “If you save your module with this name” part, even; it says “If you do it (which you can), there may be negative consequences”, but it’s enforcing saving as a separate file under a different name when I try. Has there been a way to disable that all this time?

I have never seen this first message, no. Have you included the unlock codes in your nwnplayer.ini file?

[Game Options]
CODEWORD XP1=ffrodriguez
CODEWORD XP2=barkeater

I do see this second message when I try to use the Save As feature to save a Module with the same name as a Campaign Module (e.g. Chapter1), and the Toolset refuses to save with the name. Even with this prevention, you can still save the Module under a different name (e.g. Chapter1-mod), then outside of the Toolset, move the file in the modules directory to overwrite the file in the nwm directory:

# in the base NWN directory
mv modules/Chapter1-mod.mod nwm/Chapter1.nwm
1 Like

I’ve got the unlock codes in, yes. :thinking: Odd.

In any case, thank you for the tips. :slight_smile: Noted 'em down for future reference.