Expanding spawnclasses without conflicts

DideroDidero Posts: 90
edited February 2014 in General Modding
The original idea for this method comes from Nanenj in this topic, but I think many of the people here haven't seen that topic.

Since Nanenj's explanation is a bit brief (no offense!), I'll try to explain it more extensively in this post. So brace yourself, this is going to be a long one :D
(If you just want the short explanation, scroll to the bottom of the post. If you don't understand it then though, read the whole post before posting your questions)

You can add to spawnclasses without overwriting them entirely. I use this with my Total Respec mod to add the potions to the general items vendor, and with the ferret mod to add the transformation fish to the Fishmonger from Lathlas's Merchant Pack. So if you're confused after reading this post, look in the 'media\Spawnclasses' folder of those mods for more examples of this method.

The method is this: Make a spawnclass file in the "YOURMOD\media\Spawnclasses" folder like normal, but only put the additions you want to make to the spawnclass in there, and the "<STRING>:NAME" of the spawnclass you want to add to. Make sure the filename is different though, otherwise the spawnclass will get overwritten. Another thing to keep in mind is that if you add items to your spawnclass that are also in the original spawnclass, the entire spawnclass will get overwritten, and the game will only use the spawnclass from the mod. So check the original spawnclass to prevent duplicates in the files and a malfunctioning spawnclass in the game.
The game first loads the normal spawnclass files included in the vanilla game, and then adds the data found in these spawnclass addition files.

I'll give an example, since it's rather hard to understand without one. I'm going to show how to add an item to the General items vendor without overwriting his default stock. The default "media\Spawnclasses\MERCHANT_GENERAL_INVENTORY.dat" looks like this:
&#91;SPAWNCLASS&#93;
&lt;STRING&gt;NAME:MERCHANT_GENERAL_INVENTORY
&#91;OBJECT&#93;
&lt;STRING&gt;UNIT:Identify Scroll
&lt;INTEGER&gt;WEIGHT:-1
&lt;INTEGER&gt;RARITY_OVERRIDE:1
&#91;/OBJECT&#93;
&#91;OBJECT&#93;
&lt;STRING&gt;UNIT:Town Portal Scroll
&lt;INTEGER&gt;WEIGHT:-1
&lt;INTEGER&gt;RARITY_OVERRIDE:1
&#91;/OBJECT&#93;
&#91;OBJECT&#93;
&lt;STRING&gt;UNIT:Health Potion
&lt;INTEGER&gt;WEIGHT:-1
&lt;INTEGER&gt;RARITY_OVERRIDE:1
&#91;/OBJECT&#93;
&#91;OBJECT&#93;
&lt;STRING&gt;UNIT:Mana Potion
&lt;INTEGER&gt;WEIGHT:-1
&lt;INTEGER&gt;RARITY_OVERRIDE:1
&#91;/OBJECT&#93;
&#91;OBJECT&#93;
&lt;STRING&gt;UNIT:Health Potion 2
&lt;INTEGER&gt;WEIGHT:-1
&lt;INTEGER&gt;RARITY_OVERRIDE:1
&#91;/OBJECT&#93;
&#91;OBJECT&#93;
&lt;STRING&gt;UNIT:Mana Potion 2
&lt;INTEGER&gt;WEIGHT:-1
&lt;INTEGER&gt;RARITY_OVERRIDE:1
&#91;/OBJECT&#93;
&#91;OBJECT&#93;
&lt;STRING&gt;UNIT:Health Potion 3
&lt;INTEGER&gt;WEIGHT:-1
&lt;INTEGER&gt;RARITY_OVERRIDE:1
&#91;/OBJECT&#93;
&#91;OBJECT&#93;
&lt;STRING&gt;UNIT:Mana Potion 3
&lt;INTEGER&gt;WEIGHT:-1
&lt;INTEGER&gt;RARITY_OVERRIDE:1
&#91;/OBJECT&#93;
&#91;OBJECT&#93;
&lt;STRING&gt;UNIT:Health Potion 4
&lt;INTEGER&gt;WEIGHT:-1
&lt;INTEGER&gt;RARITY_OVERRIDE:1
&#91;/OBJECT&#93;
&#91;OBJECT&#93;
&lt;STRING&gt;UNIT:Mana Potion 4
&lt;INTEGER&gt;WEIGHT:-1
&lt;INTEGER&gt;RARITY_OVERRIDE:1
&#91;/OBJECT&#93;
&#91;OBJECT&#93;
&lt;STRING&gt;SPAWNCLASS:PET_RETURN_FISH_SPAWN
&lt;INTEGER&gt;WEIGHT:-1
&#91;/OBJECT&#93;
&#91;/SPAWNCLASS&#93;
For this example, I'm going to add the Luck Potion (which is already included in the game) to his inventory. To do this, I create a new mod folder 'AddLuckPotionToVendor' (in the normal mod directory, I assume you know where that is). Inside that folder I make a subfolder 'media' and a subfolder in there called 'Spawnclasses'. There, I create a new file "GeneralItemsVendor_AddLuckPotion.dat". So I end up with "mods\AddLuckPotionToVendor\media\Spawnclasses\GeneralItemsVendor_AddLuckPotion.dat". This filename is different from the default spawnclass filename, "MERCHANT_GENERAL_INVENTORY.dat", so the game doesn't overwrite the default spawnclass with the spawnclass in this mod, but only adds them together. Now, I open up the file in a text editor, and type this in the file:
&#91;SPAWNCLASS&#93;
&lt;STRING&gt;NAME:MERCHANT_GENERAL_INVENTORY
&#91;OBJECT&#93;
&lt;STRING&gt;UNIT:Luck Potion
&lt;INTEGER&gt;WEIGHT:-1
&lt;INTEGER&gt;RARITY_OVERRIDE:1
&#91;/OBJECT&#93;
&#91;/SPAWNCLASS&#93;
The "<STRING>NAME:MERCHANT_GENERAL_INVENTORY" is very important, since it's the same as in the default spawnclass. This is what the game uses to recognise this file is meant to change or add to the stock of the General Items merchant. Now I save the file (making sure it doesn't get the extension '.txt', it won't work then). I then clear the mod cache (by deleting "massfile.dat", "masterresourceunits.dat" and their ".adm" files), and when I start up the game, the General Items vendor will have a new potion in stock, along with all his normal wares! (If it's not there, try going in the dungeon for a few minutes, and then return to the village. This will cause town merchants to restock. Also, the Luck potion will only show up for characters level 3 and up.)

If I would have added a health potion to the spawnclass in our mod too, like this:
&#91;SPAWNCLASS&#93;
&lt;STRING&gt;NAME:MERCHANT_GENERAL_INVENTORY
&#91;OBJECT&#93;
&lt;STRING&gt;UNIT:Luck Potion
&lt;INTEGER&gt;WEIGHT:-1
&lt;INTEGER&gt;RARITY_OVERRIDE:1
&#91;/OBJECT&#93;
&#91;OBJECT&#93;
&lt;STRING&gt;UNIT:Health Potion
&lt;INTEGER&gt;WEIGHT:-1
&lt;INTEGER&gt;RARITY_OVERRIDE:1
&#91;/OBJECT&#93;
&#91;/SPAWNCLASS&#93;
the game would see that both the default spawnclass and the spawnclass in the mod contain the same item, the health potion. The game will therefore assume the mod changes something in the spawnclass. It will drop the default spawnclass and will only use the spawnclass from the mod. That means the General Items vendor won't sell any of the advanced health potions anymore, no mana potions, and no identify and town portal scrolls, which is clearly not what I wanted. Be sure to pay good attention to the objects already in the spawnclass you're adding to with your mod, since you don't want to remove items from it!


This method works with all the spawnclasses. So not only does it work for extending merchant inventories, it also works on monster spawnclasses, so extending the default maps with custom monsters can be done this way too.


If you rather use TorchED to make a spawnclass, this method can be used too. Just edit the spawnclass normally with the "Spawnclasses" editor (I'm going to assume you know how to do this). When you're done, save all the changes and close TorchED. Then, navigate to the folder of the mod you just made, and find the spawnclass you've edited for your mod inside "media\Spawnclasses". Open it in a text editor (Notepad is included with Windows, and it works just fine for this purpose). Delete all the parts between the "[OBJECT]" and "[/OBJECT]" tags (and the tags themselves!) from the file that are also present in the default spawnclass. If you don't know what the default spawnclass contained anymore, navigate to where you installed TorchED, and find the spawnclass file in the "TorchED\media\Spawnclasses" folder. This is the default spawnclass, and you can compare it to the one in your mod folder to see the differences. Usually additions to a spawnclass are added at the bottom of the file, so it should be easy to find what was already present in the vanilla game and what was added by the mod. Make sure you leave the line at the top that stars with "<STRING>NAME:" though! This is what the game uses to recognise which spawnclass to add this file to. When you're sure all the duplicates are removed, save the file and close the text editor. Now you have to rename your spawnclass file, otherwise the game will only use the spawnclass from the mod instead of the combined spawnclass. Choose a filename that still makes it clear which spawnclass it adds to, but so that it's also clear it's not the default spawnclass. Also make the filename unique, so that if another person makes a mod that adds to the same spawnclass, their filename isn't the same as yours. Otherwise the game drops your spawnclass in favour of the newer one.


Holy wall of text, Batman! I'll try to summarize the procedure, to make it as clear as possible:
  1. Create a file in "YOURMOD\media\Spawnclasses". Name your file something different than the default spawnclass file. Make sure it's still recognisable which spawnclass it adds to, but unique enough that other modders don't use the same filename when adding to the same spawnclass;
  2. At the top of your file, after the obvious "[SPAWNCLASS]", add "<STRING>NAME:" and the name of the spawnclass you want to add to (not the filename, but the "<STRING>NAME:"!);
  3. Add the items you want to add to the spawnclass to your file, follwing the spawnclass formatting;
  4. Check if any of the items you added are in the default spawnclass file already. If they are, remove them from your spawnclass;
  5. Test the spawnclass in-game or in the editor. If there are items/monsters missing, double-check if you removed all duplicates;
  6. Done! You've made a modular, conflict-free spawnclass addition!


I hope that was clear (if a bit longwinded :P). If not, feel free to ask any questions you might have!
Creator of:
-Total Respec mod (v2.0, Jan. 10 2010)
-Faster Walking mod (v1.0, Nov. 11 2009)
Uploader of:
-Ferret Pet mod (ferret itself made by Runic) (v1.1.1, Jan. 4 2010)

Comments

Sign In or Register to comment.