Jump to content

New Spell Modding Question


Ayce

Recommended Posts

I was wondering how "special" spells like Harper's call (spja01) get handled in a spell mod, or rather, I'm wondering as to whether or not I can restrict a particular custom spell to a particular character/NPC?

 

Or rather, if I created spja02 and edited Jaheira .cre files so that she had it learned, would Wiedu just take it and stick in "the next availble priest spell slot" and reassign it a sppr### file name (thereby making it available to all priests)?

 

Are there different protocols for this, or is it sufficient to create the spell and edit the .cre files?

 

How would wiedu install the spell without making a avialable to all characters?

 

Hope I explained the question clearly enough.

 

Thanx

Link to comment
You just need to give the the spell a custom filename, copy it over, and either add it to the .cre file(s) or make a script that will add the spell to the character's spellbook.

 

 

That's what I thought, but how would I go about including it as part of an .exe mod?

Link to comment
You just need to give the the spell a custom filename, copy it over, and either add it to the .cre file(s) or make a script that will add the spell to the character's spellbook.

 

 

That's what I thought, but how would I go about including it as part of an .exe mod?

Which part are you stuck on? If you're created the .spl, just use a COPY ~mymod/myspell.spl~ ~override~ to get it into the game, then either patch the specific .cre files to give them the spell (ADD_KNOWN_SPELL) or make a script that applies a different spell using opcode 147 or 171 to make the creature learn the spell.

Link to comment

Which part are you stuck on? If you're created the .spl, just use a COPY ~mymod/myspell.spl~ ~override~ to get it into the game, then either patch the specific .cre files to give them the spell (ADD_KNOWN_SPELL) or make a script that applies a different spell using opcode 147 or 171 to make the creature learn the spell.

 

It was two things actually, I had forgotten how to use "COPY ~mymod/myspell.spl~ ~override~", now I remember.

 

The issue I'm more in the dark on (never done before) is how get weidu to do the .cre files. Would it be as simple as COPY ~mymod/mycre.cre~ ~override~ with the edited cre file?

 

Scripting isn't an option, I know nothing of writing them. I'd like to learn as I have some sto mods for BG1 and BG2 in mind, but now idea how to create them.

 

Anyway, thanx.

Link to comment
The issue I'm more in the dark on (never done before) is how get weidu to do the .cre files. Would it be as simple as COPY ~mymod/mycre.cre~ ~override~ with the edited cre file?

If the creatures already exist in-game, it's a better idea to patch in the new known spell, so that giving them this one spell won't invalidate all other previous changes to the file. If you are instead copying over a custom creature, patching things still has the benefit of being easier to change later (as you just need to modify some text instead of opening up game files with an editor), so overall, it's a good idea. WeiDU has some built-in commands and macros for dealing with creatures' spellbooks and items, so you won't really need to do anything complicated.

 

If you wanted to modify the level 8 version of Viconia's BG2 .cre file, you could add a level 2 divine spell "ayvic01.spl" to her spellbook (after COPYing it over) with the following:

 

COPY_EXISTING ~viconi8.cre~ ~override~
 PATCH_IF (SOURCE_SIZE > 0x2d3) BEGIN // file is not too small
ADD_KNOWN_SPELL ~ayvic01~ #1 ~priest~ // adds as 2nd-level divine spell
 END
 BUT_ONLY

The only oddity to note here is that the ADD_KNOWN_SPELL command makes you specify the spell's level as one less than it actually is, because this is how the game stores the spellbook information in the .cre file.

 

To do the same thing to all of Viconia's BG2 .cre files, the only thing you'd need to modify is which files are affected:

COPY_EXISTING_REGEXP GLOB ~viconi\([689]\|1[136]\)\.cre~ ~override~
 PATCH_IF (SOURCE_SIZE > 0x2d3) BEGIN // file is not too small
ADD_KNOWN_SPELL ~ayvic01~ #1 ~priest~ // adds as 2nd-level divine spell
 END
 BUT_ONLY

 

If you haven't already registered a modder prefix, now would be a good time, so that your custom spells don't clash with anyone else's. I used "ay" in the above example.

 

Edit: I should mention that altering .cre files will change how the mod works when installed on a game in-progress. Creatures that have been met in-game have their info stored in the savegame so that their equipment, statistics, and whatnot can be kept track of, which means that modifications made to the .cre files in the override will only be seen in the game in-progress if the creature has yet to be encountered. As scripts are not stored in the savegame, adding a block to a creature's script that gives them a custom spell if they don't already have it will have the effect of working on save games whether you've met the creature yet or not.

 

In other words, if you had a save game where Viconia was a party member and installed the mod at that point, if the mod edited her .cre, Viconia would not know the new spell in that save game, but would if the player started a new game. If the mod edited her script, she would spontaneously learn the spell after the save game was loaded, as she would when encountered in a new game.

 

Anyway, thanx.

No problem. :party:

Link to comment
just out of curiosity, what does the

 

BUT_ONLY line do?

I've not used BUT_ONLY, however I believe that it is a shortened form of BUT_ONLY_IF_IT_CHANGES.

 

When using weidu and you copy a file to the override and you wish to apply some patches to that file, weidu reads the current file and stores it in memory. The patches are applied and the file saved to the override directory. If you don't use BUT_ONLY_IF_IT_CHANGES the file will be saved to the override even if it didn't change. If you use BUT_ONLY_IF_IF_CHANGES the file will only be saved to the override if there were actual changes made.

 

Example:

COPY_EXISTING ~.*\.itm~ ~override~
READ_SHORT 0x0038 stack
PATCH_IF (%stack% > 1) BEGIN
WRITE_SHORT 0x0038 500
END

In this little example, I told weidu to 'copy' ALL item files look at the stack value and write a new value of 500 if the stack value was greater than 1. Even though items that had a stack value of 1 wouldn't get changed they would still be copied into the override. This can lead to a possibility of bloating the override directory and slowing down the game.

When I add BUT_ONLY_IF_IT_CHANGES, only those files that get modified will be copied to the override directory. As in this example:

COPY_EXISTING ~.*\.itm~ ~override~
READ_SHORT 0x0038 stack
PATCH_IF (%stack% > 1) BEGIN
WRITE_SHORT 0x0038 500
END
BUT_ONLY_IF_IT_CHANGES

Link to comment
I've not used BUT_ONLY, however I believe that it is a shortened form of BUT_ONLY_IF_IT_CHANGES.
Yeah. Can trim a number of bytes off a long tp2 :party:.

 

Incidentally, there's no reason to use REGEXP GLOB when you're patching known NPC files. "COPY_EXISTING ~viconi6.cre~ ~override~ ~viconi8.cre~ ~override~ ~viconi9.cre~ ~override~ ~viconi11.cre~ ~override~ ~viconi13.cre~ ~override~ ~viconi16.cre~ ~override~" beats "COPY_EXISTING_REGEXP GLOB ~viconi\([689]\|1[136]\)\.cre~ ~override~" speed-wise, any day of the week.

Link to comment
Incidentally, there's no reason to use REGEXP GLOB when you're patching known NPC files. "COPY_EXISTING ~viconi6.cre~ ~override~ ~viconi8.cre~ ~override~ ~viconi9.cre~ ~override~ ~viconi11.cre~ ~override~ ~viconi13.cre~ ~override~ ~viconi16.cre~ ~override~" beats "COPY_EXISTING_REGEXP GLOB ~viconi\([689]\|1[136]\)\.cre~ ~override~" speed-wise, any day of the week.

You may have a point, but then you'd have to ALLOW_MISSING the ToB version (thus far, I've managed to avoid using the command altogether).

Link to comment
You may have a point, but then you'd have to ALLOW_MISSING the ToB version (thus far, I've managed to avoid using the command altogether).
And you're right to avoid it, because it's a bad, bad command :party:. It just creates empty versions of the files in the override, which can be subverted with SOURCE_SIZE statements, but it still creates useless cruft. PATCH_IF or ACTION_IF commands are far more preferable.

COPY_EXISTING ~viconi6.cre~ ~override~
		  ~viconi8.cre~ ~override~
		  ~viconi9.cre~ ~override~
		  ~viconi11.cre~ ~override~
		  ~viconi13.cre~ ~override~
		 [Patch code]
BUT_ONLY

ACTION_IF GAME_IS ~tob~ THEN BEGIN
 COPY_EXISTING ~viconi16.cre~ ~override~
[Patch code]
 BUT_ONLY
END

Might want to use PATCH_INCLUDE or the like for the actual patches to conserve space, but that's my off-the-cuff pseudocode anyway :).

 

Edit: If you want to patch the Tutu/BGT versions of the CREs (and there's no reason not to, for what Ayce is doing), you'd need to declare %tutu_var% or whatever for the initial Tutu underscore (or lack of in BGT) and patch %tutu_var%viconi.cre, %tutu_var%viconi4.cre and %tutu_var%viconi6.cre as well (obviously, with another ACTION_IF those platforms are detected). I can give more pseudocode for that or take a look at BG1 NPC or similar mods that use this type of syntax.

Link to comment
Why not "simply" use
ACTION_FOR_EACH...

Aye, that is probably more efficient and what I tend to use in my mods if I had bothered to look at them first... you been peekin' at my code? :party:

 

Though I think ACTION_IF needs a THEN before the BEGIN for some odd reason, even though PATCH_IF does not, if I recall correctly...

Link to comment

We might be getting a bit off-topic now, hehe. Wisp's suggestion is probably the most user-friendly to modify and would easily support inserting Tutu/BGT resources as well. I used a regular expression in my example just because that's how I'd code it (since it takes the least amount of effort to write and I'm comfortable with using them), not in an effort to imply that learning regular expressions is a prerequisite for copying multiple files.

 

Edit:

Though I think ACTION_IF needs a THEN before the BEGIN for some odd reason, even though PATCH_IF does not, if I recall correctly...

THEN is not needed before BEGIN in either command, though the readme doesn't make this clear in the case of ACTION_IF.

Link to comment
We might be getting a bit off-topic now, hehe.
It ain't off-topic, because:
The issue I'm more in the dark on (never done before) is how get weidu to do the .cre files.
Wisp's suggestion is probably the most user-friendly to modify and would easily support inserting Tutu/BGT resources as well.
Quite right, because you could just do...
ACTION_FOR_EACH viconia IN _viconi _viconi4 _viconi6 viconi viconi4 viconi6 viconi8 viconi9 viconi11 viconi13 viconi16 BEGIN

...without bothering to check which platform (Tutu, BGT, BG2) the user is installing this on.

I used a regular expression in my example just because that's how I'd code it (since it takes the least amount of effort to write and I'm comfortable with using them)
Well that's where you're wrong, Mike, at least as far as the bolded part :party:.

 

Edit:

Though I think ACTION_IF needs a THEN before the BEGIN for some odd reason, even though PATCH_IF does not, if I recall correctly...
THEN is not needed before BEGIN in either command, though the readme doesn't make this clear in the case of ACTION_IF.
True in the latest WeiDU, though this has failed in previous versions (fairly recent ones I believe).
Link to comment

Archived

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

×
×
  • Create New...