Choose Your Language

Friday 23 January 2009

Custom Crafting With NWNX2

UPDATED (13th April): In the light of this forum post, I did some further experimentation with kinc_crafting (which I eventually found) and can now recommend the following structure for basic crafting. i.e. When not requiring TRADE ITEMS.

First of all locate kinc_crafting.NSS in the SoZ expansion campaign folder. Open this with a basic text editor (like notepad) and copy the script into the toolset as a new script and name it the same. i.e. kinc_crafting (without the NSS suffix). The only other file you require (to make this script compile correctly) is kinc_trade_constants, which can be located in the same way as described above for the previous script. Again, copy and paste the script into your own module, keeping the same name.

Open your kinc_crafting script and add the include line for the kinc_trade_constants file. i.e. Add the line #include "kinc_trade_constants" just below the other include files mentioned in the kinc_crafting script. Lastly, add the #include "kinc_crafting" include line inside your own On Module Activate script, which will also contain the modified script as mentioned below.

ORIGINAL POST

I have started to take a look at the new crafting system that comes with SoZ. For those that don't know, Obsidian released a tutorial on the subject that can be downloaded from the Vault here. However, what I have discovered (as well as a few others) is that the information it contains is inaccurate and not very helpful, especially with regards to include scripts.

After some time experimenting with the scripts, however, I did manage to discover which files do matter when it comes to the new crafting system and made a post at the forums explaining what I had found. I will now repeat that information here for those who might be considering doing something similar in the future.

The important include file that is wrongly named in the tutorial is kinc_trade and it is this include file that is required for the On Activate and On Acquire scripts when using recipes or incantations. However, this include file also makes reference to three other include files that the tutorial does not mention at all, which are: kinc_trade_constants, kinc_trade_crafting and kinc_trade_system. All four of these include files need to be copied across from the SoZ campaign directory to your own campaign directory if you wish your scripts to compile when using the code from the SoZ On Activate and On Acquire scripts.

The official On Acquire code, however, does not (as far as I can see) do much more than set a variable on every party member and force the item onto the Main PC independent of who picked up the recipe or incantation. This, in my opinion, is not how I want the game to work, and so I did not use the On Acquire code in the end and simply applied the variable (that was set in the On Acquire script) at the same time as the PC who activates the recipe or incantation. This then allows the recipe or incantation to stay on the PC who actually picked up the item.

Here is the edited part of the code I use in my On Activate script:

//////////////////////////////////////////////////////////////////////////////////////
// SOZ CRAFTING SYSTEM (v1.21) ///////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////
// This code is used to support NX2's crafting system.


if(GetBaseItemType(oItem) == 145) //Recipes are itemtype 145
{
//object oPC = GetItemActivator();
string sTag = GetTag(oItem);
SetLocalInt(oPC, sTag, TRUE); // ADDED FROM ACQUIRED

int nRecipeIndex = Search2DA(NX2_CRAFTING_2DA, "RECIPE_TAG", sTag, 1);

if(CheckCanCraft(nRecipeIndex, oPC, NX2_CRAFTING_2DA) )
CraftItem(nRecipeIndex, oPC, NX2_CRAFTING_2DA);
}

if(GetBaseItemType(oItem) == 146) //Incantations are itemtype 146
{
//object oPC = GetItemActivator();
object oItemToEnchant = GetItemActivatedTarget();
if(GetObjectType(oItemToEnchant) == OBJECT_TYPE_ITEM)
{
string sTag = GetTag(oItem);
SetLocalInt(oPC, sTag, TRUE); // ADDED FROM ACQUIRED

int nIncantIndex = Search2DA(NX2_ENCHANTING_2DA, "INCANTATION_TAG", sTag, 1);

if( CheckCanEnchant(nIncantIndex, oItemToEnchant, oPC, NX2_ENCHANTING_2DA) )
EnchantItem(nIncantIndex, oItemToEnchant, oPC, NX2_ENCHANTING_2DA);
}
}

You do also have to copy the two 2da files across (as explained in the tutorial), but the builder must also be aware that the 2da files may not make reference to the same tag as the blueprints the toolset has available. E.g. I had to change the tag of an alchemy table to match the tag reference in the crafting 2da file. (By the way, the crafting 2da file does not open properly in the toolset, so it may need some careful attention if the builder intends to add more recipes as I do.)

For testing, I also copied across the recipe items into my override folder, so that I could reference them inside my own module. I did a quick test on a Perfected Acid Flask, and the crafting worked fine: It checked my party to see if I had someone who had a high enough skill, checked the amount of gold, and also checked if an alchemy bench was nearby. And although I have not tested an incantation yet (for enchanting), I expect it will work just fine as well, as it uses a similar format to the crafting system.

Now it should just be a case of me adding my own recipes and the new system should be up and running for my campaign.

4 comments:

Wyrin said...

was going to post on the forums - thanks for this - good to have someone iron out issues and report back. I do like the new take on crafting, and think after all thetinkering they got somethign attractive to use

Lance Botelle (Bard of Althéa) said...

Thanks Wyrin,

Let me know if you get to play with this as well, and if anything is different from what I have discovered.

Lance.

EC said...

I was planning to enable SoZ style crafting in Trinity. Your post will come in really handy!

It would be great now if people started to share custom crafting recipes on the Vault.

Lance Botelle (Bard of Althéa) said...

Hi E.C. Patterson,

As long as people know how to create their own recipes, I suppose that is the main thing really. After all, if a builder is going to make their own "custom" recipes, we may find that they will be structured more for the campaign they are in than anything generic.

I know my own recipes will most likely have descriptions that will suit my own campaign rather than, say perhaps the world of Toril?

That said, I suppose their is no harm doing a little basic editing. :)

Lance.