Jump to content

Spell modding question


Recommended Posts

I've created some custom spells for a mod. Looking at examples from other mods, I'm just COPYing them to override and assigning them names and descriptions from my TRA file. But the WeiDU documentation has an ADD_SPELL command that does the following:

adds newSPLfile as a spell of type and level into the game (IE, SPPR102 or whatnot), in the first empty slot possible, appends the idsName to spell.ids, and sets %idsName% to the 4-digit code associated with idsName in Spell.ids. While you copy newSPLfile to the override, you also apply the patches listed.
Would it be preferable to do this instead of (or in addition to) COPYing the spells?
Link to comment

ADD_KNOWN_SPELL is something you'll only be using if you need the spell to show up automatically in the priest spellbooks or sorcerer spell selection menu and you're not sure if other mods may be adding spells in the spwi[0-9]+ sppr[0-9]+ namespace.


There's only room for so many spells known in the book or selectable on the menu, so avoid if possible - otherwise you can end up with a TDD situation where spells late in the alphabet get pushed off of the selection menu and can't be accessed anymore.


You can use SpellRes() and the like to script spells whether they have a spell.ids entry or not (add in the ToB scripting actions if they're not present, CamDawg won't mind if you swipe the Fixpack code for this purpose :D )


Otherwise, APPEND ~spell.ids~ ~00xx SPELL_NAME_GOES_HERE~ UNLESS ~00xx~ will do the job.

Link to comment

Guessing from the description, I think you want to do this if you want your spells to be available when a brand-new character is picking his spells. As opposed to weird findable treasure from scrolls only, or npc special effects.


For example, wizard spells must be named SPWI<lvl><00-49> to be automatically picked up by the engine.

Link to comment

Actually, I think ADD_SPELL is a newer action (not ADD_KNOWN_SPELL) that works like ADD_KIT.


I wouldn't bother using it, though. Unless you need to detect your spell with SpellCastOnMe() or other scripting functions that don't support the RES parameter, just give your spell a unique name and use HaveSpellRES("unique") and SpellRES("unique",whoever) and stuff.

Link to comment
Guest Nythrun@work

Yeah, that should have been ADD_SPELL in the previous post.


Anyway - it's not going to give desirable behaviour with unique prefixes (i.e. - it won't have them) so it's not something you'll want to use as a replacement for COPY.

Link to comment

The main point of unique prefixes is to stop one mod from overwriting the files of another. ADD_SPELL itself shouldn't overwrite another mod's files since, according to the description, it finds the first available slot. However, there's nothing to stop another mod using the COPY command and overwriting one or more of your mod's .spl's (the WeiDU version of WeiDU would most likely do this, for example). You'd just need to tell people to be careful what order they install mods in.

Link to comment

Actually, this mod is adding a few lower-powered BG2 spells into BG1 late in the game via treasure scrolls. So they are in the SPWIxxx namespace. The spells exist in BGT and Tutu so this section is just for BG1.


So just COPY them and don't bother with ADD_SPELL? Should I throw in the APPEND to spell.ids?

Link to comment

I don't know that ADD_SPELL sets an internal variable with the new spell's resource reference, so you might need to bodge something together in order for your scrolls to "know" which spell they ought be casting. If you set the resref in the .itm file to be XsXpXlX something like this would probably work for some fourth level spell:

ADD_SPELL ~moddirectory/badsampl.spl~ 2 4 ~WIZARD_BAD_EXAMPLE~


 READ_ASCII 0x1 "digit1" (1)
 READ_ASCII 0x2 "digit2" (1)
 READ_ASCII 0x3 "digit3" (1)
 SPRINT ~spellresref~ ~spwi%digit1%%digit2%%digit3%~

COPY ~moddirectory/badsampl.itm~ ~override/namethiswhateveryouwant.itm~
 REPLACE_TEXTUALLY ~XsXpXlX~ ~%spellresref%~ // pick something seven characters long here


Probably there's a mistake in there (I'm real tired) and the CLEAR_IDS_MAP is almost certainly redundant.

Link to comment

ADD_SPELL is to be used only if you need to make the spell available to sorcerors (or to wizards/bards at the initial spell selection). For all other uses, plain COPY is better.


Nythun's code is right (or at least appears to be).

Link to comment

I'm back here again, trying to add a druid spell from BG2 to BG1. I've grabbed all the resources, made sure everything checks out for BG1 and tried both the COPY/APPEND and ADD_SPELL syntaxes. Both appear to work, in that the spell ends up in the game and the correct entry in spell.ids, but when I level a druid PC to allow him access to level 4 spells, he can't see it. What am I missing?

Link to comment

Are you using Divine Remix? If so, you have to adhere to their rules.


Anyhow, for Priest spells you should use COPY/APPEND and use some EXTEND_TOP to add the spell to the memorized list (ask any Divine Remix coder for the details).

Link to comment

No, I don't have DR on BG1 - I don't think it's even compatible. Though I did rip it apart and it looks like maybe there is some patching code in macro_spellbook_druid.tph or similar I would need to use. Hopefully a small subset of it, since I would hope to avoid putting in such a huge chunk of code for something (that should be) pretty simple. I guess I'll bug Cam about it since I haven't seen Andyr or NiGHTMARE around much lately.

Link to comment

Got around to reading this, finally, after Miloch sent me a PM. I've already answered there, but I thought I'd put it here too for those interested.


spells.2da is the key here. Spells beginning with sppr[1-5] are automatically added to divine casters as appropriate, up to the numbers set in this file. For example, the default value for divine spells at level 4 is 8--so sppr401 to sppr408 are added automatically. If ADD_SPELL assigns it a number higher than sppr408, you'll need to adjust this file as well. Perhaps ADD_SPELL could be altered to adjust spells.2da automatically? It works the same in BG2, except the default values there are 50 at every level.

Link to comment

I guess I'll post my response here too - no sense in clogging up Cam's PMs more than necessary :).

Bugger... I'm doing an ADD_SPELL ~MyMod/spells/sppr410.spl~ 1 4 ~CLERIC_CALL_WOODLAND_BEINGS~ and it shows up in the game as SPPR409, which is outside the PRIEST L4 range of 8 in spells.2da. Can I just mod spells.2da to increase that somehow? Maybe it's just not functional in BG1 - I don't think Echon bothered to add any of the FotD spells, he just copies them over.
So uh... would a SET_2DA_ENTRY take care of this? I haven't really messed around with changing 2DAs as yet.
Link to comment


This topic is now archived and is closed to further replies.

  • Create New...