Jump to content

Editing spells


Recommended Posts

I'm new to WeiDU and I'm looking for the easiest way to edit existing spells. This is the first bit of code I wrote to edit Meteor Swarm so that it does 12d6 damage and bypasses MR. Then I change it's description to match. 

Spoiler

ACTION_IF (FILE_EXISTS_IN_GAME "spwi911d.spl") BEGIN
    COPY_EXISTING "spwi911d.spl" override
      WRITE_BYTE 0x0a7 2
      WRITE_LONG 0x0b6 12
      WRITE_LONG 0x0ba 6
    BUT_ONLY
  END
    COPY_EXISTING 
    "spwi911.spl" override
    "scrl9t.itm" override
      SAY NAME1 @825    SAY UNIDENTIFIED_DESC @826
END

I'll admit, I'm still getting confused on the correct "WRITE_X" syntax to use and how to write the offset location in WeiDU. I think I've deduced that the size column in NI corresponds to the syntax. 1 for BYTE, 2 for SHORT, 4 for LONG, and 8+ ASCII. The offset part is also tripping me up. When using the Find tool in NI and searching for hex values I can't get anything to return so I must be entering something wrong. My best effort is that start offset | A7h (167) is written as 0x0a7. 

I see many mods using "LAF edit_spell STR_VAR..." which looks like a much cleaner and easier way to do this, but I couldn't find the right examples to feel confident enough.  

Link to comment

You're targeting effects a couple layers deep in nested structures by their exact offsets. That's bad practice, and it's liable to break in unexpected ways if the spell is modified in some way that moves things around. I'd only ever use explicit offsets like that for top-level elements, such as if I wanted to turn this into a conjuration spell and exclude it for diviners instead of enchanters.

For example, SCS has a component to prevent damage spells from interrupting spellcasters that are immune to their damage type. This is done by inserting an effect that grants immunity to the spell, at the beginning of the effect stack. Apply that here, and the damage effect's offset changes. Now your offsets point to a different effect, and your changes don't do what you wanted.

Also, there is no spwi911d.spl in the vanilla game, so you're looking at a modified spell already with that - which mod? The standard version of the spell doesn't have any subspells, and the damage effects belong to the main spell.

"edit_spell" is part of the SFO library used in SCS, and that stuff is a bit impenetrable to beginning modders. Simpler to use the functions built into WeiDU and described in the documentation there. For example, here's how I'd make the changes you wanted to the original version of Meteor Swarm:

COPY_EXISTING ~SPWI911.SPL~ ~override~
    LPF ALTER_SPELL_EFFECT // A function built into WeiDU. Does exactly what it says
      INT_VAR
        match_opcode = 12 // Alter damage effects only
        resist_dispel = 3 // Ignore MR
        dicenumber = 12 // Change damage to 12d6, part 1
        dicesize = 6 // Change damage to 12d6, part 2
    END // Done with function call
    SAY NAME1 @825 // Using your tra references here.
    SAY UNIDENTIFIED_DESC @826
BUT_ONLY // Don't write to override if no changes are made. Mostly just a marker that we're done.

All right, I wouldn't put quite so many comments in my own code. Or that much whitespace in the function call; I'd probably just run it all together in a single line.

Also, a minor technical note on this forum - the "code" button, which looks like two angle brackets, is useful for formatting code. Anything inside that comes out in a monospaced font, which makes the indentations work better. Since there's no option for WeiDU highlighting, I choose "No syntax highlighting" from the drop-down menu when posting WeiDU code.

Edited by jmerry
Added material
Link to comment
3 hours ago, WanderingScholar said:

The offset part is also tripping me up. When using the Find tool in NI and searching for hex values I can't get anything to return so I must be entering something wrong. My best effort is that start offset | A7h (167) is written as 0x0a7. 

Offsets are usually referred in hexadecimal system and by convention, if you want to indicated that number is hexadecimal, you strat it with '0x', e.g hex 0xa7 = 167 in decimal, that means in WieDU code 167 and 0xa7 points to the same place in file, however it is better to use hex number since it is used like this everywhere else.

Worth to note IESDP as a source of information. This contains pure technical specification of game files (and much more). 

Link to comment

@jmerry Thanks, that's just what I was looking for! Sure enough, LPF ALTER_SPELL_EFFECT is under the macro section in WeiDU doc, totally missed that. 

8 hours ago, jmerry said:

Also, there is no spwi911d.spl in the vanilla game, so you're looking at a modified spell already with that - which mod? The standard version of the spell doesn't have any subspells, and the damage effects belong to the main spell.

This is more concerning to me. Maybe I should mention the full context of what I'm trying to do. Spell Revisions makes changes to meteor swarm that I don't like so I've gone and edited out all the lines in spell_rev\components\main_component.tpa which add the new meteor swarm into the game. As well as the projectile change. That being done I'd like to make my own changes to the vanilla spell that remains.  

/*ADD_PROJECTILE ~spell_rev\projectles\dvmswarm.pro~
COPY ~spell_rev\spwi9##\spwi911.spl~     ~override~  // Meteor Swarm
  SAY NAME1 @825    SAY UNIDENTIFIED_DESC @826
  WRITE_SHORT 0x98 %dvmswarm%
COPY ~spell_rev\spwi9##\scrl9t.itm~      ~override~
  SAY NAME2 @825    SAY IDENTIFIED_DESC   @826
COPY ~spell_rev\spwi9##\dvmeteor.vvc~    ~override~*/

spwi911d.spl is in my game despite this being edited out. Indeed, it is a subspell with the damage effect for spwi911.spl. Now, I'm modding the originals so maybe this is a discrepancy between them and EE editions, but I doubt it. Else I'll have to figure out where spwi911d.spl is coming from. Here are some clues

Mods affecting SPWI911.SPL:
00000: /* created or unbiffed */ ~SPELL_REV/SETUP-SPELL_REV.TP2~ 0 20 // Mirror Image Fixv4 Beta 18 (Revised v1.3.900)
00001:  ~SPELL_REV/SETUP-SPELL_REV.TP2~ 0 55 // Spell Deflection blocks AoE spellsv4 Beta 18 (Revised v1.3.900)
00002:  ~STRATAGEMS/SETUP-STRATAGEMS.TP2~ 0 1000 // Initialise mod (all other components require this)v31 RC3 + kreso's Spell Revisions compatibility
00003: /* acted upon in an undefined manner */ ~GENERALIZED_BIFFING/GENERALIZED_BIFFING.TP2~ 0 1 // Generalized BiffingBiff all files (recommended by the Big World Dudes)v2.6
PS C:\Games\GOG\Baldurs Gate 2>

Well, my best guess is that the spell deflection component of spell_rev is editing meteor swarm (the vanilla in my case) so that it allows spell deflection to absorb it since "spwi911" is listed in spell_rev\components\nwn_spell_deflection.tpa. I'm still too green to understand how this setup file works, but if this is the case then I do indeed need to edit "spwi911d". I just need to make sure my code is executed after it's been created. Holy smokes, glad you caught that.  

Edit: Disregard this last part. I still suspect it's part of the spell deflection component. 

Edited by WanderingScholar
Link to comment

For offsets in NI, there is a “Show Hex Offsets” option you can turn on. Then it becomes very clear in a column. Also the IESDP file formats page shows you what field is at which offset. 

Regarding SR, you commented out the code relating to SPWI911.spl but you did not comment out anything relating to SPWI911D.spl - I can see that from your post. So SR is still adding the subspell to your game. But SR us not changing SPWI911 to use the subspell in any way, so you can ignore it. It is detritus. Just mod the main SPWI911.spl. 

EDIT - whoops, re-read the post and indeed that subspell is added by the NWN-style Spell Deflection component. Since you disabled SR’s changes to the base spell, the Deflection component transfers the vanilla spell’s effects into the ‘d’ subspell. So with NWN-style Deflection installed you would indeed have to aim your modifications at the subspell. Carry on. 

Link to comment

And, of course, mod order also matters. If you're looking to have this tweak installed before "NWN-style Spell Deflection", you just modify the original SPWI911, and trust that component to propagate your change to the new subspell. If you're looking to have this tweak installed after "NWN-style Spell Deflection", then you need to branch, editing SPWI911D if that spell exists and SPWI911 otherwise. Or ... actually, since we're testing for a damage effect when we run the function, running the edit code on SPWI911 even if the subspell exists is harmless. It'll throw a "nothing changed" warning, but warnings aren't errors.

(It's actually a bit more complicated than that; if some other mod already created a SPWI911D, then the deflection component will go down to the next option SPWI911E, and keep going if necessary until a letter is free.)

Edited by jmerry
Link to comment

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...