Jump to content


Updating Item Descriptions Dynamically

4 replies to this topic

#1 Luke

  • Members
  • 64 posts
  • Gender:Male

Posted 10 March 2018 - 11:05 AM

Suppose I want to edit the base damage of daggers from 1d4 to 1d7 -> How can I update the description (unidentified and identified) to take account of my change? 

Edited by Luke, 10 March 2018 - 01:06 PM.

#2 Mike1072

  • Gibberling Poobah
  • 2405 posts
  • Gender:Male
  • Location:Canada

Posted 10 March 2018 - 01:07 PM

I have a post here that's not specifically directed towards this, but it explains some of the concepts surrounding it.  It includes an example that changes the description dynamically, which I've copied below.


INNER_PATCH_SAVE new_description ~%description%~ BEGIN


That code looks nice but it only updates the unidentified description.  To modify both, you could repeat all of that but use DESC instead of UNIDENTIFIED_DESC.  Or you could use a loop which lets you perform the same changes on both descriptions.  This is the macro we use in IR to do that.

// stolen from BG2 Tweak Pack at G3
// modified to take parameter ~%text_update%~, the macro name of the REPLACE_TEXTUALLY to execute
DEFINE_PATCH_MACRO ~update_item_descriptions~ BEGIN
  FOR (index = 0x54 ; index >= 0x50 ; index -= 4) BEGIN // loop through descriptions
    READ_LONG index valid
    PATCH_IF (valid < 2147483646) AND (valid >= 0) BEGIN // verify description is valid
      READ_STRREF index description
      INNER_PATCH_SAVE new_desc ~%description%~ BEGIN
        LAUNCH_PATCH_MACRO ~%text_update%~
      SAY_EVALUATED index ~%new_desc%~

It doesn't contain any of the REPLACE_TEXTUALLYs that determine what changes are made to the text.  Those are defined in a separate macro.  What you do is call this macro and provide it the name of another macro that has those, like this.

DEFINE_PATCH_MACRO ~update_dagger_text~ BEGIN

TEXT_SPRINT text_update ~update_dagger_text~
LAUNCH_PATCH_MACRO update_item_descriptions

Both descriptions will then have all instances of 1d4 replaced with 1d7. Keep in mind that this might remove instances of 1d4 that you didn't really want to change.


The way we used to resolve this in IR was to instead look for a match of something like "Damage: 1d4" (but with regexp character classes to catch extra spaces and tabs and other stupid things that might otherwise prevent a match).


I don't have a good example of that in the current code because we now do all that in a giant macro that handles arbitrary changes to speed factor, THAC0, and damage.  I've never looked too carefully at it because it's complicated, but it's in here listed as wc_update if you want to try to take advantage of it.

#3 subtledoctor

  • Modders
  • 2346 posts
  • Gender:Male

Posted 10 March 2018 - 08:38 PM

I have a component with the simplistic version here:

The issue with using regexp to find and replace some text is, trying to do it in multiple languages can be a nightmare.

Faiths & Powers: Spell spheres and kit pack for priests and paladins
Might & Guile: Tweaks and kits for warriors and rogues
Scales of Balance: Game tweaks and rule overhauls
NPC_EE: More options for NPCs in BGEE, SoD, & BG2EE

#4 Ardanis


    A very GAR character

  • Modders
  • 2575 posts
  • Gender:Male
  • Location:Saint-Petersburg, Russia

Posted 11 March 2018 - 03:38 AM

but it's in here listed as wc_update if you want to try to take advantage of it.

Macro alone probably won't be of much help without context.

Here is the component launched in tp2 https://github.com/G...em_rev.tp2#L213
And here is the main installation code with links to other required files, so you can simply strip it of the stuff you don't want https://github.com/G...pon_changes.tpa

I've never looked too carefully at it because it's complicated

I remember that your unreleased v3 code for updated weapon speed factor component was very much similar to my version, which is basically a smaller variation of the general weapon changes.

The issue with using regexp to find and replace some text is, trying to do it in multiple languages can be a nightmare.

Yes, translators will need to understand the regexp to adjust the code to new language, but it didn't seem to be much of an issue with IR.

Edited by Ardanis, 11 March 2018 - 03:45 AM.

"Uguu~ Boku Ayu."

Before you start breaking wall tiles with your bare fists, ask yourself first - do you truly need it?

#5 Luke

  • Members
  • 64 posts
  • Gender:Male

Posted 11 March 2018 - 04:44 AM

Thank you for your suggestions!

Suppose I wanna edit the identified description only if such description exists (i.e., StringRef ~= -1) -> How can I do that?

Edited by Luke, 11 March 2018 - 04:51 AM.

Reply to this topic


0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users