Dynamically Adding Spells to Merchants

From the Oblivion ConstructionSet Wiki
Jump to navigation Jump to search

Here's a simple but effective way to get custom spells into merchants' inventories without directly modifying the NPC. This method will prevent conflicts that arise from multiple mods adding spells or items to the same merchant.

First, create an activator to place in the NPC's cell. You can place your activator outside the playable area of the cell, or you can choose a model without a visible mesh (meshes\magiceffects\null.nif works well). When placing the activator, make note of the actor's specific Reference ID in the cell dialog. This is the reference you'll need to use in the script. Also, take note of the NPC's starting cell - it may be better to place the activator in a different cell. For example, some of the mages in the Bruma Mages' Guild start in the basement, which is behind a door with a hard lock. In these instances, it would be better to add the activator to the Mage Guild's entrance - the spells will still be added if the NPC is in a different cell.

Once you have your activator placed in the cell, attach a customized script similar to the following:

Begin OnLoad

  NPCRef.AddSpell <SpellID1>
  NPCRef.AddSpell <SpellID2>
  ...

End

This script will cause the spells to be added to the specified NPC(s) each time the activator is loaded. If you load a mod that further changes the NPC in question, the spells will still be available the next time the cell is reloaded.


GuidoBot 01:43, 11 October 2006 (EDT) An alternative method is to just create a one-time-run Quest script that adds the spells to the NPCRef directly. For complicated effects, like inventory restocking and adding randomness, a scripted unplayable item (0-value ring), a token, can be added to the NPCRef directly. To ensure that the (GameMode) script only runs when the player is nearby, it is best to also add a GetInSameCell condition.