[Tool] Adding class- or kit-specific spells
OlvynChuru
Member Posts: 3,079
This tool adds a versatile WeiDU function that can add or restrict spells to specific classes and/or kits. It could be useful either for modders making spell mods or modders making kit mods.
Here are things this function can do that were difficult or impossible to do before:
- Make it so only certain classes or kits can learn the spell on character creation or level up (e.g. so a particular spell could be learned by shamans but not by druids, or could be learned by paladins but not by clerics).
- Make it so only certain classes or kits can learn the spell from a scroll (e.g. so the "Learn Spell" button only appears for bards and not for mages).
- The above works both for existing spells and for custom spells. You could restrict an existing spell to certain classes or kits (e.g. you could make the Emotion: Courage and Emotion: Hope spells from IWDEE only learnable by bards).
- Make a spell learnable by all arcane/divine casters without having to prefix it with SPWI or SPPR; this means WeiDU's ADD_SPELL function isn't necessary.
- Bypass the 50 spell per spell level limit (normally the list of spells sorcerers and shamans can learn on level up only shows the first 50 spells of each level, so if there are more than 50 spells of a certain level the ones past 50 can't be learned. This function gets around that; the new spells will be displayed regardless of how many spells there are.).
- The function works with any spellcasting class.
Limitations:
- Spells it adds to clerics and druids won't be selectable as initial spells during character creation, but they'll still appear in the priest scroll when the game starts.
Here's an example of the function in use:
This makes the spell Summon Cow available to all mages and sorcerers, except the Dragon Disciple kit. It also makes the spell available to the Jester kit, but not to all bards. This means:
- A mage or a Jester can learn the spell from a scroll, but other bards can't.
- A sorcerer will be able to choose the spell on level up, unless they're a Dragon Disciple.
Function parameters:
If you want to use this function in your mod, download and unzip the file at the end of this post. Look in the ClassSpellTool folder and copy its contents into your mod folder. Then in your mod's tp2 file, include this line:
After that, you can use the ADD_CLASS_SPELL function as shown in the example above.
If you'd like your code to look through all the spells that have been added by this tool (in addition to the spells that already existed in the game), the tool records the resrefs of all the spells in the files MEWI[1-9].txt and MEPR[1-7].txt. You can read these files with WeiDU functions like READ_2DA_ENTRY, even though they aren't 2DA files.
Here are things this function can do that were difficult or impossible to do before:
- Make it so only certain classes or kits can learn the spell on character creation or level up (e.g. so a particular spell could be learned by shamans but not by druids, or could be learned by paladins but not by clerics).
- Make it so only certain classes or kits can learn the spell from a scroll (e.g. so the "Learn Spell" button only appears for bards and not for mages).
- The above works both for existing spells and for custom spells. You could restrict an existing spell to certain classes or kits (e.g. you could make the Emotion: Courage and Emotion: Hope spells from IWDEE only learnable by bards).
- Make a spell learnable by all arcane/divine casters without having to prefix it with SPWI or SPPR; this means WeiDU's ADD_SPELL function isn't necessary.
- Bypass the 50 spell per spell level limit (normally the list of spells sorcerers and shamans can learn on level up only shows the first 50 spells of each level, so if there are more than 50 spells of a certain level the ones past 50 can't be learned. This function gets around that; the new spells will be displayed regardless of how many spells there are.).
- The function works with any spellcasting class.
Limitations:
- Spells it adds to clerics and druids won't be selectable as initial spells during character creation, but they'll still appear in the priest scroll when the game starts.
Here's an example of the function in use:
LAF ADD_CLASS_SPELL STR_VAR resref=~SPWI299~ scroll=~SCRLZZ~ class_include=~{'MAGE_ALL', 'SORCERER'}~ kit_include=~{'JESTER'}~ kit_exclude=~{'DRAGON_DISCIPLE'}~ END
This makes the spell Summon Cow available to all mages and sorcerers, except the Dragon Disciple kit. It also makes the spell available to the Jester kit, but not to all bards. This means:
- A mage or a Jester can learn the spell from a scroll, but other bards can't.
- A sorcerer will be able to choose the spell on level up, unless they're a Dragon Disciple.
Function parameters:
- resref (Resref of the spell.)
- scroll (Resref of the scroll for the spell (optional, if you want to restrict who can learn the spell from the scroll).)
- class_include (A character with one of these classes (from CLASS.IDS) can learn the spell. Use the class wildcards (like 'MAGE_ALL' for all mages).)
- kit_include (A character with one of these kits can learn the spell, even if their class is not in the "class_include" list.)
- kit_exclude (A character with one of these kits cannot learn the spell, even if their class is in the "class_include" list. NOTE: YOU DO NOT HAVE TO SPECIFY THE SPECIALIST MAGE KITS THAT CANNOT LEARN THE SPELL; THE FUNCTION WILL HANDLE THOSE AUTOMATICALLY.)
If you want to use this function in your mod, download and unzip the file at the end of this post. Look in the ClassSpellTool folder and copy its contents into your mod folder. Then in your mod's tp2 file, include this line:
INCLUDE ~%MOD_FOLDER%/ClassSpellTool.TPA~
After that, you can use the ADD_CLASS_SPELL function as shown in the example above.
If you'd like your code to look through all the spells that have been added by this tool (in addition to the spells that already existed in the game), the tool records the resrefs of all the spells in the files MEWI[1-9].txt and MEPR[1-7].txt. You can read these files with WeiDU functions like READ_2DA_ENTRY, even though they aren't 2DA files.
Post edited by OlvynChuru on
7
Comments
Download the zip again and try it.
Thankee for releasing this tool to the public! Alleluia! You've done this community a great service!
Does this tool only work on EE versions of the games? Does it work on IWD1? IWD2? PST?
Does this tool have the ability to edit mods with new spells and strip off the SP__ prefix? (I'm looking at you, Darkest Day, Dark Side of the Sword Coast, Northern Tales of the Sword Coast, IWDification, and more!) If not, may we get it soon? I'd like to be able to play with all these spells and more in the same game!
Edit: annoyingly enough, doesn't seem to be a problem when the sorcerer levels up post-creation.
@Endarire
It's EE-only, since it requires UI modding.
No, it doesn't. However, once I update all the spells in my mod to use this function, you'll be much less likely to reach the 50 spells per level limit, since my spells won't count towards it.
This tool seems like it should be integrated into Weidu's ADD_SPELL function. I referred Wisp, the current maintainer of Weidu, to you so you two can talk more directly about this.
Thankee!
The ADD_CLASS_SPELL function requires certain files in order to work (like M_MEEXSP.lua). WeiDU is normally just a program by itself; it doesn't come with other files that are necessary for it to work. I'm not sure if it's a good idea.
Hence the conversation with Wisp.
Thank you, it's much appreciated!
But unfortunately, it's not working for me (BG2:EE v2.5, no EEEx...)
For instance, if I write then CLERICs, DRUIDs, FERALANs and the like are able to select Bless during Character Creation. Shouldn't that restrict Bless to Rangers only (in particular TRUECLASS and STALKER)?
I see. Will you able to do something about that?
You're the best @OlvynChuru !!!!
Edit: have to convert my 9th level spells to this system at the least.
Lol, when you are super stoked but you don't want to spam
Nice!
I've got two questions:
Put it in another way: is it possible to make a DRUID kit that can cast only, say, fifth level spells?
Yes, it's intended. And ending an array with a comma like that is perfectly okay in Lua.
Nope, not right now. That's another issue to fix.
Of course, thinking about it, I could just create a spell to be added at whatever level, ADD_SPELL it, ensure that it has a ref above xx50, and have it cast the original spell via #146/148.
That way, any protections, etc. that protect against the custom spell ref will also protect against the ADD_SPELL version which would be used in any scripts.
I think that solves the issue, posting so others can use the idea or critique
The issue previously with calling new spells by their resref rather than their spell.ids entry was that when spells were added with ADD_SPELL, they were assigned the next available SPWI or SPPR filename, which could vary. Depending on the game and the mods you had installed, a particular spell might've been added as SPWI435 or SPWI437. So writing something like SpellRES("SPWI435",Myself) was not reliable, since it could use the wrong spell.
But the ADD_CLASS_SPELL function bypasses this problem. It makes the spell available without having to give it a varying SPWI or SPPR filename, so you can simply use the spell's original filename in scripts. You don't need to use WeiDU's ADD_SPELL function if you use ADD_CLASS_SPELL.
Greetings, argent!
I'd love for your mods (Wild Mage and otherwise) to use this tool to increase inter-mod compatibility. Thankee!
The same happens for arcane classes as well...
Also, if it's possible to grey out each spellbook page that is unavailable, that'd be great (that is, if the Kit under consideration cannot cast, say, fifth level spells, then the related page in its spellbook should be greyed out...)
Greetings, all!
May we get a step-by-step tutorial on how to integrate this tool with a mod? I ask on behalf of Austin for Saradas Magic 2.
Thankee!
In the opening post here I already give instructions on how to integrate this tool with a mod.
Download and unzip the file ClassSpellTool.zip from the opening post. Look in the ClassSpellTool folder and copy the file ClassSpellTool.tpa and the folder called "no_overwrite" into your mod's folder.
In your mod's tp2 file, include this line:
Then you can use the ADD_CLASS_SPELL function. Here's the example from the opening post of the function in use:
This makes the spell Summon Cow available to all mages and sorcerers, except the Dragon Disciple kit. It also makes the spell available to the Jester kit, but not to all bards. This means:
- A mage or a Jester can learn the spell from a scroll, but other bards can't.
- A sorcerer will be able to choose the spell on level up, unless they're a Dragon Disciple.
Did you manage to have a look at the remaining issues (those pointed out by me and AionZ...)?
Edit: Hmm, okay, there seems to be a workaround. I added CLERIC_ALL, THIEF_ALL and FIGHTER_ALL to the class_include list. Might not need to pay attention to this then.
Edit: I tested it further. When I add something like this:
For some reason the kit_exclude also blocks all kits after the last listed entry in KIT.IDS rather than just the listed kits.
I agree with subtledoctor's sentiment from here about having a uniform system for spell adding that allows for learning spells from scrolls (for the classes that can) as well as from character creation, including for spontaneous casters.
May we also get the spells added by this tool to have the default option of being scribable and selectable via the spell learning UI if this isn't already true? Thankee!
To clarify, I am very glad Olvyn you gave us a way to bypass the 50 spells per spell level limit! It would be better to have some standardized system to allow Tome & Blood general compatibility, including spell swapping.
Thankee!