Skip to content

[Tool] Adding class- or kit-specific spells

OlvynChuruOlvynChuru Member Posts: 3,075
edited February 2023 in General Modding
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:
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
StummvonBordwehrRik_KirtaniyaGwendolyne_Luke_GrammarsaladPermidion_StarkAbel
«13

Comments

  •  TheArtisan TheArtisan Member Posts: 3,277
    I've tried to add the function to kit-specific spells, but that part doesn't seem to work. Only the class parameter does. Is that part dependent on EEex?
    OlvynChuru
  • OlvynChuruOlvynChuru Member Posts: 3,075
    @AionZ Okay, I fixed the problem. Kit-specific spells should work now. Download the zip again and try it.
  •  TheArtisan TheArtisan Member Posts: 3,277
    Works as intended now, thanks. I don't suppose there's a way for the kit parameter to parse a kit name instead of the number in the case of custom kits?
  • OlvynChuruOlvynChuru Member Posts: 3,075
    @AionZ Wish granted! I just released a new version in which you can do this, like:
    LAF ADD_CLASS_SPELL STR_VAR resref=~SPWI299~ scroll=~SCRLZZ~ class_include=~{'MAGE_ALL', 'SORCERER'}~ kit_include=~{'JESTER'}~ kit_exclude=~{'DRAGON_DISCIPLE'}~ END
    

    Download the zip again and try it.
  • EndarireEndarire Member Posts: 1,512
    edited October 2020
    @OlvynChuru
    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!
  •  TheArtisan TheArtisan Member Posts: 3,277
    edited October 2020
    Thanks for the update. I'm currently trying to integrate it into Shadow Magic to improve the spell selection process, but there's a few issues that still need sorting out. I'm not sure if there's an easier process but I've individually excluded every original mage spell to my kits and made the mod spells exclusive to the kits, but it seems somehow the system ends up believing the kit has no available spells at all and sets the number of allowed spells to zero:

    Edit: annoyingly enough, doesn't seem to be a problem when the sorcerer levels up post-creation.

    bzc7c0rokyjj.png
  • OlvynChuruOlvynChuru Member Posts: 3,075
    @AionZ That problem seems to have to do with the automatic spell picks. Try setting all the resrefs in SPLAUTOP.2DA to *******. From my tests just now, that should fix the problem.

    @Endarire
    Endarire wrote: »
    Does this tool only work on EE versions of the games? Does it work on IWD1? IWD2? PST?

    It's EE-only, since it requires UI modding.
    Endarire wrote: »
    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!

    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.
  • EndarireEndarire Member Posts: 1,512
    @OlvynChuru
    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!
  • OlvynChuruOlvynChuru Member Posts: 3,075
    @Endarire
    Endarire wrote: »
    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.
    Gwendolyne
  • EndarireEndarire Member Posts: 1,512
    @OlvynChuru
    Hence the conversation with Wisp.
  • _Luke__Luke_ Member, Mobile Tester Posts: 1,535
    edited October 2020
    @OlvynChuru
    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
    LAF ADD_CLASS_SPELL
    STR_VAR
    	resref = ~SPPR101~
    	class_include = ~{'RANGER_ALL'}~
    	kit_exclude = ~{'FERALAN', 'BEASTMASTER'}~
    END
    
    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)?
  • OlvynChuruOlvynChuru Member Posts: 3,075
    edited October 2020
    @Luke93 The function currently can't restrict existing spells for clerics, druids, rangers and paladins, though it can still add new spells for them after character creation.
  • _Luke__Luke_ Member, Mobile Tester Posts: 1,535
    OlvynChuru wrote: »
    @Luke93 The function currently can't restrict existing spells for clerics, druids, rangers and paladins, though it can still add new spells for them after character creation.

    I see. Will you able to do something about that?
    OlvynChuru
  • GrammarsaladGrammarsalad Member Posts: 2,582
    edited October 2020
    Awesome!

    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
    OlvynChuru
  • OlvynChuruOlvynChuru Member Posts: 3,075
    edited October 2020
    @Luke93 I fixed your issue. Priest spells should no longer be selectable on character creation if you've restricted them to other classes. Download the zip from the first post again.
    _Luke_Grammarsalad
  • _Luke__Luke_ Member, Mobile Tester Posts: 1,535
    edited October 2020
    OlvynChuru wrote: »
    @Luke93 I fixed your issue. Priest spells should no longer be selectable on character creation if you've restricted them to other classes. Download the zip from the first post again.

    Nice!

    I've got two questions:
    1. Is it intended for ["class_include"] to have a comma followed by a blank space?
      {3, 8, 14, 15, 17, 18, }
      
    2. Suppose you want to make a custom DRUID kit that cannot memorize vanilla spells. Will you get stuck during Character Creation? After a quick test, there's no way to get past that screen, so I'm wondering if I'm missing something... I tried editing, for instance, the first column of "SPLAUTOS.2DA" by putting "*******", but still no luck...
      Put it in another way: is it possible to make a DRUID kit that can cast only, say, fifth level spells?
    Post edited by _Luke_ on
  • OlvynChuruOlvynChuru Member Posts: 3,075
    @Luke93
    Luke93 wrote: »
    Is it intended for ["class_include"] to have a comma followed by a blank space?
    {3, 8, 14, 15, 17, 18, }
    

    Yes, it's intended. And ending an array with a comma like that is perfectly okay in Lua.
    Luke93 wrote: »
    Suppose you want to make a custom DRUID kit that cannot memorize vanilla spells. Will you get stuck during Character Creation? After a quick test, there's no way to get past that screen, so I'm wondering if I'm missing something... I tried editing, for instance, the first column of "SPLAUTOS.2DA" by putting "*******", but still no luck...
    Put it in another way: is it possible to make a DRUID kit that can cast only, say, fifth level spells?

    Nope, not right now. That's another issue to fix.
  • GrammarsaladGrammarsalad Member Posts: 2,582
    edited October 2020
    Okay, I have a question, or maybe I'm brainstorming, here. Is there a way to associate your spell with an entry in spell.ids? I ask because I understand that ResRef is not reliable for scripting (edit: according to a half remembered post by @DavidW sometime ago).

    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
  • OlvynChuruOlvynChuru Member Posts: 3,075
    @Grammarsalad
    Okay, I have a question, or maybe I'm brainstorming, here. Is there a way to associate your spell with an entry in spell.ids? I ask because I understand that ResRef is not reliable for scripting (edit: according to a half remembered post by @DavidW sometime ago).

    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.
    Grammarsalad
  •  TheArtisan TheArtisan Member Posts: 3,277
    Is there a solution for the blank button in the 'Write Spell' slot when a scroll designated for a kit is already scribed? Minor but kind of annoying.
    vrjuyuxc59zc.png

  • EndarireEndarire Member Posts: 1,512
    @argent77
    Greetings, argent!

    I'd love for your mods (Wild Mage and otherwise) to use this tool to increase inter-mod compatibility. Thankee!
  • _Luke__Luke_ Member, Mobile Tester Posts: 1,535
    OlvynChuru wrote: »
    Nope, not right now. That's another issue to fix.

    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...)
  • EndarireEndarire Member Posts: 1,512
    @OlvynChuru
    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!
  • OlvynChuruOlvynChuru Member Posts: 3,075
    @Endarire
    Endarire wrote: »
    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:
    INCLUDE ~%MOD_FOLDER%/ClassSpellTool.TPA~
    

    Then you can use the ADD_CLASS_SPELL function. Here's the example from the opening post 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.
    Adam_en_tium
  • EndarireEndarire Member Posts: 1,512
    Thankee!
  • _Luke__Luke_ Member, Mobile Tester Posts: 1,535
    @OlvynChuru

    Did you manage to have a look at the remaining issues (those pointed out by me and AionZ...)?
  •  TheArtisan TheArtisan Member Posts: 3,277
    edited December 2020
    Update: So, it seems this tool can cause issues with dual-classing. If you add an original mage spell with the class_include=~{'MAGE_ALL', 'SORCERER'}~ function it will NOT appear for classes dualling into mage, I think this has to do with the game believing the character is still a single-class thief, fighter or cleric until after the dual-class is complete. For my Shadow Magic mod this means when for example dualling Imoen into a mage she can't pick any spells at all and the game becomes stuck.

    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.
    Grammarsalad
  • EndarireEndarire Member Posts: 1,512
    OlvynSpells and Tome & Blood's Sorcerers weren't working well together. This page explains what problems Kaiiak experienced that were likely in relation to this mod and how he solved at least some of them.
  •  TheArtisan TheArtisan Member Posts: 3,277
    edited January 2021
    I’m running into more issues with this tool. I tried to add the same spells to be excluded to both my warlock and shadow adept mods and it resulted in the shadow adept losing the ability to select any of their spells. Is there a trick to adding to an existing spell in the lua file?

    Edit: I tested it further. When I add something like this:
    LAF ADD_CLASS_SPELL STR_VAR resref=~SPWI101~ scroll=~SCRL66~ class_include=~{202, 203, 205, 206}~ kit_exclude=~{'C0SADEPT', 'C0SASORC', 'C0SABARD', 'C0SAMT', 'C0SACM', 'C0SAFM', 'C0SAFMT', 'C0SAFMC',}~ END
    

    For some reason the kit_exclude also blocks all kits after the last listed entry in KIT.IDS rather than just the listed kits.
    Post edited by TheArtisan on
  • EndarireEndarire Member Posts: 1,512
    edited February 2021
    @OlvynChuru
    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!
    [The] only mod that pushes past this limit is OlvynSpells, which adds something like 200 new spells to the game. As Endarire said, Olvyn created a new system to allow those spells to be learned at CharGen/by sorcerers even if they use a modding prefix and are outside the normal 1-50 IDS number range. I don't love that system, because it uses a UI hack that might create compatibility issues with other UI hacks, and because it doesn't create a new centralized repository of just what spells sorcerers should get, so other mods (like mine) have no way of knowing how to treat sorcerers' spell lists. (My feeling is that modders should stick to the original system, and players should simply be choosy about what spells they add to their game, until a system is devised that is easy for all modders to hook into.)

    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!
    Post edited by Endarire on
Sign In or Register to comment.