Caedwyr Posted September 29, 2007 Share Posted September 29, 2007 In an attempt to promote better compatibility with other mods, I've got a question about selectively replacing certain phrases/words using Weidu. For example, I would like to do the following COPY_EXISTING ~sppr103.spl~ ~override/ca#ds103.spl~ /*cure light wounds*/ SAY UNIDENTIFIED_DESC @200 Now, instead of just overwriting the entire description of the spell using SAY UNIDENTIFIED_DESC @200, I would like to use Weidu to make some changes. Original text: Cure Light Wounds (Necromancy) Level: 1 Sphere: Healing Range: Touch Duration: Permanent Casting Time: 5 Area of Effect: Creature touched Saving Throw: None When casting this spell, and laying his hand upon a creature, the priest causes 8 points of wound or other injury damage to the creature's body to be healed. This healing cannot affect creatures without corporeal bodies, nor can it cure wounds of creatures not living or of extraplanar origin. Curing is permanent only insofar as the creature does not sustain further damage; caused wounds will heal - or can be cured - just as any normal injury. From my setup.tra file: @200=~Cure Light Wounds (Necromancy) Level: 1 Range: Touch Duration: Permanent Casting Time: 5 Area of Effect: Creature touched Saving Throw: None When casting this spell, and laying his hand upon a creature, the MYKIT causes 8 points of wound or other injury damage to the creature's body to be healed. This healing cannot affect creatures without corporeal bodies, nor can it cure wounds of creatures not living or of extraplanar origin. Curing is permanent only insofar as the creature does not sustain further damage; caused wounds will heal - or can be cured - just as any normal injury.~ What I want to do here as can be seen is to remove the "Sphere: Healing" line, I may want to change the level listed (ie: change the 'Level: 1' to a 'Level: 2', and change all the 'priest' in the text to 'MYKIT' So, can this be done, and how would I go about doing so? Link to comment
Caedwyr Posted October 1, 2007 Author Share Posted October 1, 2007 If anyone could point me in the direction of an example of this, it'd be much appreciated. Link to comment
berelinde Posted October 1, 2007 Share Posted October 1, 2007 I don't think that GTU would do it the way that it does if there was any other way to do it. But I could be wrong, and often am. Link to comment
Rabain Posted October 1, 2007 Share Posted October 1, 2007 There are two ways to get different text for an item: 1. You assigned a new string at install via @200 2. You change the existing string to say something else. Most likely using STRING_SET (see weidu documentation). Please Note that option 2 is generally considered bad. I would think for spell descriptions it would be less destructive but you can understand why it'd be considered bad form for normal dialog i.e you could change a string I use in a mod and totally change the context and sense of a dialog conversation. Link to comment
Caedwyr Posted October 1, 2007 Author Share Posted October 1, 2007 Given that I'm cloning whatever spell I make modifications to, and use the cloned/adjusted version for the mod, the modified strings would be applied to the cloned spell and not the original. That should take care of any sort of worries about compatibility issues. What I guess I'd need to do then, is to read in the spell description string on the cloned spell, save it as a new string, and then make my modifications by searching/replacing as described above. This seems a little more involved than a wholesale replacement with the SAY UNIDENTIFIED_DESC @200 and different than the STRING_SET option as I'm making the changes to a newly generated string. Of course, it gets really sticky when you are dealing with multiple languages. So, I'm wondering if Weidu has the capability to do that. Link to comment
CamDawg Posted October 1, 2007 Share Posted October 1, 2007 It can be done--in the newest release Tweaks now updates item descriptions on the fly for the two armor tweaks. While you do get the benefit of regular expression matching, it's still not fool-proof by any means. Basic idea is that you read the description into a variable: FOR (index = 0x50; index < 0x55; index = index + 0x04) BEGIN READ_LONG "%index%" "valid" PATCH_IF ("%valid%" < 2147483646) AND ("%valid%" >= 0) BEGIN READ_STRREF "%index%" "description" This adjusts both identified and unidentified descripts, assuming they're valid (the PATCH_IF check). INNER_PATCH ~%description%~ BEGIN PATCH_IF ("%LANGUAGE%" STRING_COMPARE_CASE "czech" = 0) BEGIN // if czech LAUNCH_PATCH_MACRO ~arcane_descripts_czech~ END ELSE PATCH_IF ("%LANGUAGE%" STRING_COMPARE_CASE "english" = 0) BEGIN // if english LAUNCH_PATCH_MACRO ~arcane_descripts_english~ END ELSE // etc SET char = 0 // different than the check FOR (i = 0; char != 0xfafa; i += 1) BEGIN READ_BYTE i char ELSE 0xfafa // if out of bounds, read my custom EOF signal/value END READ_ASCII 0 description (i - 1) END The macro was included before the patch, and consists of DEFINE_PATCH_MACRO ~arcane_descripts_english~ BEGIN REPLACE_TEXTUALLY ~\(Weight:[ %tab%]*[0-9]+\)~ ~\1 Miscast Arcane Magic: +%patch_miscast%%~ END So, this finds the 'Weight:' line of the armor descript, then adds a new line below it. The char loop progresses through the description a character at a time until the end (ask bigg for specifics, he's the one who showed me how to do this ). Now that %description% has been updated, you apply it back to the item: SAY_EVALUATED "%index%" ~%description%~ END END Link to comment
Guest erik Posted October 1, 2007 Share Posted October 1, 2007 Doing it once, for a single language, is vaguely easy. But once several mods do the same thing in unpredictable order, things get sticky. But in the interest of sharing knowledge: /* Macro to dynamically patch descriptions. Parameters: (string)file, (regexp string)txt_from, (string)txt_to */ DEFINE_ACTION_MACRO ~PATCH_UNID_DESC~ BEGIN COPY_EXISTING ~%file%~ ~override~ READ_STRREF UNIDENTIFIED_DESC "descstr" INNER_PATCH_SAVE newdescstr "%descstr%" BEGIN REPLACE_TEXTUALLY CASE_SENSITIVE EXACT_MATCH ~%txt_from%~ ~%txt_to%~ END SAY_EVALUATED UNIDENTIFIED_DESC ~%newdescstr%~ END /* Macro to dynamically patch descriptions. Parameters: (string)file, (regexp string)txt_from, (string)txt_to */ DEFINE_ACTION_MACRO ~PATCH_ID_DESC~ BEGIN COPY_EXISTING ~%file%~ ~override~ READ_STRREF IDENTIFIED_DESC "descstr" INNER_PATCH_SAVE newdescstr "%descstr%" BEGIN REPLACE_TEXTUALLY CASE_SENSITIVE EXACT_MATCH ~%txt_from%~ ~%txt_to%~ END SAY_EVALUATED IDENTIFIED_DESC ~%newdescstr%~ END ...defines the needed macros. Then, an example of use (patching the skull trap description after my tweaks to it) OUTER_SPRINT ~txt_from~ ~The damage inflicted is equal to 1d6 hit points per level of the caster,~ OUTER_SPRINT ~txt_to~ ~The damage inflicted is 2d4 hit points, plus 1d4 hit points per level of the caster (up to a maximum of 20d4),~ OUTER_SPRINT ~file~ ~spwi313.spl~ LAUNCH_ACTION_MACRO ~PATCH_UNID_DESC~ OUTER_SPRINT ~file~ ~scrl1p.itm~ LAUNCH_ACTION_MACRO ~PATCH_ID_DESC~ It works. But is unlikely to improve compatibility between mods much. Link to comment
Guest erik Posted October 1, 2007 Share Posted October 1, 2007 Cam beat me to it, I see. Still, interesting to see the differences. Link to comment
CamDawg Posted October 1, 2007 Share Posted October 1, 2007 I prefer the external macro approach mainly because it lets me stick the tpa files in the language folders. Link to comment
berelinde Posted October 1, 2007 Share Posted October 1, 2007 Hey! That's pretty cool stuff! Link to comment
DavidW Posted October 1, 2007 Share Posted October 1, 2007 There's some code in SCSII that does a lot of stuff like this, if you want some more examples... notably in changing various spell descriptions. Link to comment
Caedwyr Posted October 5, 2007 Author Share Posted October 5, 2007 I've been considering this a bit, and while the simple search and replace "priest" with "MYKIT" is fairly simple, deleting a line is a fair bit harder. Cure Light Wounds (Necromancy) Level: 1 Sphere: Healing Range: Touch Duration: Permanent Casting Time: 5 Area of Effect: Creature touched Saving Throw: None When casting this spell, and laying his hand upon a creature, the priest causes 8 points of wound or other injury damage to the creature's body to be healed. This healing cannot affect creatures without corporeal bodies, nor can it cure wounds of creatures not living or of extraplanar origin. Curing is permanent only insofar as the creature does not sustain further damage; caused wounds will heal - or can be cured - just as any normal injury. The hard part is that the order of Level: #Sphere: ******* isn't consistent in the original game. Sometimes it will be Spellname (School)Sphere: ************ and sometimes Spellname(School) Sphere: ******** Is there any sort of code that would let me search for Sphere: ******* and specifically remove that line, no matter where it is found? Note: ******* is a wildcard for whatever is listed after "Sphere:" on the same line. Hopefully this part is doable as well. Link to comment
CamDawg Posted October 6, 2007 Share Posted October 6, 2007 Use the extra_regexp_vars library from Tweaks or Fixpack. REPLACE_TEXTUALLY ~\([%lnl%%mnl%%wnl%]+\)Sphere: *[A-Za-z] *[%lnl%%mnl%%wnl%]+~ ~\1~ This should remove standalone Sphere: lines. Link to comment
Recommended Posts
Archived
This topic is now archived and is closed to further replies.