Skip to content

-HOW TO DO STUFF IN WEIDU-

SystemSystem Administrator Posts: 199
edited March 2020 in General Modding
In the last year or two, I have picked up a lot of little techniques to mod many aspects of the game. Occasionally people ask me for advice (even though I am still a rank amateur), and I try to help. But rather than answer this question here, that question there, etc., I thought it would be nice to publish a FAQ-style thread with lots of tips and stuff. The goal is, people can pick up this code and drop it into a mod they are working on, rather than having to reinvent the wheel. Every mod is individual and involves individual effort, but say someone want to make stat-based kit effects; I can at least help you drop in to code for handling opcode 326 and splprot.2da, and then you can focus on making whatever cool effects you can imagine.

There will be no particular order for this stuff; I'll publish what I can, when I have time, if the mood strikes.

First up, in answer to a request from @Reddbane: how to make stat-based effects with opcode 326.

Second: how to add kit effects to all kits of a given class (including mod-added ones)

Third: how to target your mod kit with unique effects

Fourth: how to alter class/kit descriptions and not worry about string references
Post edited by Tresset on
mf2112AquadrizztRavenslightargent77GrammarsaladJuliusBorisovBillyYanktbone1elminsterProontNoloirlolienDaeros_Trollkiller
«13456789

Comments

  • The user and all related content has been deleted.
  • BillyYankBillyYank Member Posts: 2,768
    edited November 2016
    You should add your tutorial/template on how to add an item here also.

    Edit: Also, someone should sticky this thread. @JuliusBorisov
    JuliusBorisov
  • The user and all related content has been deleted.
  • BillyYankBillyYank Member Posts: 2,768
    edited November 2016
  • [Deleted User][Deleted User] Posts: 0
    edited September 2018
    The user and all related content has been deleted.
    Post edited by [Deleted User] on
    GrammarsaladNoobaccaJuliusBorisovProont
  • BCaesarBCaesar Member Posts: 452
    Ok so I want to change the description (column 5) for the Sun Soul Monk for example (and the Trueclass Monk and Dark Moon Monk, but lets start with Sun Soul). I only need to change the SWASHBUCKLER to SUN_SOUL and then I'm only patching column 5 in both files. So it looks like this:

    In my TP2 file I write:
    ACTION_IF (FILE_EXISTS_IN_GAME ~clastext.2da~) BEGIN
    COPY_EXISTING ~clastext.2da~ ~override~
    COUNT_2DA_COLS cols // amount of columns
    READ_2DA_ENTRIES_NOW rows cols // read all file into memory
    FOR (row = 1; row < rows; ++row) BEGIN // iterate over rows
    READ_2DA_ENTRY_FORMER rows row 0 ~kit_name~ // read column value
    PATCH_IF ~%kit_name%~ STRING_EQUAL_CASE ~SUN_SOUL~ BEGIN
    SET patch_row = %row%
    END
    END
    SET_2DA_ENTRY %patch_row% 5 cols RESOLVE_STR_REF (@20002)
    BUT_ONLY
    END
    ACTION_IF (FILE_EXISTS_IN_GAME ~kitlist.2da~) BEGIN
    COPY_EXISTING ~kitlist.2da~ ~override~
    COUNT_2DA_COLS cols // amount of columns
    READ_2DA_ENTRIES_NOW rows cols // read all file into memory
    FOR (row = 1; row < rows; ++row) BEGIN // iterate over rows
    READ_2DA_ENTRY_FORMER rows row 1 ~kit_name~ // read column value
    PATCH_IF ~%kit_name%~ STRING_EQUAL_CASE ~SUN_SOUL~ BEGIN
    SET patch_row = %row%
    END
    END
    SET_2DA_ENTRY %patch_row% 5 cols RESOLVE_STR_REF (@20003)
    BUT_ONLY
    END

    The part I don't understand is, "change the @_____ tra references to your own strings"

    So I need to create a .tra file and put my new class description text in there? What is a .tra file and how do I create one? Sorry for the really basic questions. I only learned what TP2 files were and how to make/open them by asking in this thread: https://forums.beamdog.com/discussion/15010/short-introduction-to-weidu-and-simple-mod-template/p3

    I figure by asking maybe other aspiring modders will be able to search and find the answers. Because I spent a while searching back when I knew absolutely nothing and most of the tutorials already assumed I knew many things that I didn't know. Like a book telling me how to row when I live in the desert, don't know how to swim, and have never seen a body of water.

    Thanks.
  • BCaesarBCaesar Member Posts: 452
    edited December 2016
    Also while I'm asking questions, if I have a mod that is only for Baldur's Gate 1:EE version 2.0 and later without SoD, so I am fine with editing a single string of dialog.tlk how to I do that?

    Also what's the easiest way to edit a single line of a file? For example with my monk mod I change HPCLASS.2DA and change only monks to HBBARB and leave the rest intact. I could create a whole new file with Near Infinity (that's what I'm doing now) but then that creates compatibility issues with other mods. I'd prefer just to edit one line and I'm assuming there's an easy code to do that in my TP2 file in WeiDU and then I wouldn't have to overwrite the whole HPCLASS.2DA file.
  • [Deleted User][Deleted User] Posts: 0
    edited December 2016
    The user and all related content has been deleted.
  • BCaesarBCaesar Member Posts: 452



    This depends. For any given file, there may or may not be a good way to do something like this. But specifically for .2da files, which are always sort of arranged like a spreadsheet, Weidu has nice tools to analyze and edit them. Some of which I've used in the posts above.

    For your edit to HPCLASS.2DA, it is a simple matter: you wan to use SET_2DA_ENTRY:

    COPY_EXISTING ~hpclass.2da~ ~override~
    SET_2DA_ENTRY 44 1 2 ~HPBARB~
    SET_2DA_ENTRY 45 1 2 ~HPBARB~
    SET_2DA_ENTRY 46 1 2 ~HPBARB~
    That will change the entries for Monk, Sun Soul, and Dark Moon. (Which are in the 44th, 45th, and 46th rows of that file that have at least two colunms. That explains the 1st and 3rd numbers in those lines. The 2nd number, "1," is slightly trickier: it tells Weidu to edit the entry in the second column... because for whatever reason, in this instance, it starts counting at zero.)
    Ok so for my monk mod here, I deleted a bunch of my 2da files and achieved the same thing using my tp2 file. It took a number of tests to get it right but it seems to work now.

    So the first part of my tp2 file looks like this:
    BACKUP ~WarriorMonkMod/backup~

    AUTHOR ~Brandon Caesar at caesarbran@gmx.com~

    VERSION ~Version1.03~

    BEGIN ~BCaesar's Warrior Monk Mod~

    COPY ~WarriorMonkMod/copy~ ~override~

    COPY_EXISTING ~alignmnt.2da~ ~override~
    SET_2DA_ENTRY 49 4 9 ~1~
    SET_2DA_ENTRY 57 4 9 ~1~
    SET_2DA_ENTRY 49 5 9 ~1~
    SET_2DA_ENTRY 49 6 9 ~1~
    SET_2DA_ENTRY 56 6 9 ~1~

    COPY_EXISTING ~clsrcreq.2da~ ~override~
    SET_2DA_ENTRY 55 2 7 ~1~
    SET_2DA_ENTRY 55 3 7 ~1~
    SET_2DA_ENTRY 55 4 7 ~1~
    SET_2DA_ENTRY 55 5 7 ~1~
    SET_2DA_ENTRY 55 6 7 ~1~
    SET_2DA_ENTRY 55 7 7 ~1~
    SET_2DA_ENTRY 57 2 7 ~1~
    SET_2DA_ENTRY 57 3 7 ~1~
    SET_2DA_ENTRY 57 4 7 ~1~
    SET_2DA_ENTRY 57 5 7 ~1~
    SET_2DA_ENTRY 57 6 7 ~1~
    SET_2DA_ENTRY 57 7 7 ~1~
    SET_2DA_ENTRY 58 2 7 ~1~
    SET_2DA_ENTRY 58 3 7 ~1~
    SET_2DA_ENTRY 58 4 7 ~1~
    SET_2DA_ENTRY 58 5 7 ~1~
    SET_2DA_ENTRY 58 6 7 ~1~
    SET_2DA_ENTRY 58 7 7 ~1~

    COPY_EXISTING ~hpclass.2da~ ~override~
    SET_2DA_ENTRY 44 1 2 ~HPBARB~
    SET_2DA_ENTRY 45 1 2 ~HPBARB~
    SET_2DA_ENTRY 46 1 2 ~HPBARB~

    COPY_EXISTING ~profs.2da~ ~override~
    SET_2DA_ENTRY 19 1 3 ~5~
    SET_2DA_ENTRY 19 2 3 ~2~

    COPY_EXISTING ~profsmax.2da~ ~override~
    SET_2DA_ENTRY 19 1 6 ~1~
    SET_2DA_ENTRY 19 2 6 ~1~
    SET_2DA_ENTRY 19 3 6 ~1~
    SET_2DA_ENTRY 19 4 6 ~2~

    COPY_EXISTING ~thiefscl.2da~ ~override~
    SET_2DA_ENTRY 3 48 58 ~0~
    SET_2DA_ENTRY 3 52 58 ~0~
    SET_2DA_ENTRY 3 56 58 ~0~
    SET_2DA_ENTRY 6 48 58 ~100~
    SET_2DA_ENTRY 6 52 58 ~100~
    SET_2DA_ENTRY 6 56 58 ~100~

    COPY_EXISTING ~thiefskl.2da~ ~override~
    SET_2DA_ENTRY 7 1 2 ~24~
    SET_2DA_ENTRY 7 2 2 ~24~

    But that brings me to WEAPPROF.2DA and the way I'm doing it now I'd need a separate entry for each weapon per each monk (which comes to something like 60 entries). Please tell me there's a better way to do that, like one single long entry that changes every row for a column or every column for a row.

    Also I did what you suggested for the classes and it worked! I did it for clastext.2da for the monk and both kits and then for kitlist.2da for both kits. But I didn't use a .tra file instead I did it all in my .tp2 file using the way you mentioned. It makes my .tp2 file really long though, so I'm going to try the .tra thing tomorrow when I have time.

    Question, is there a tool that can create a blank .tp2 or .tra file, or is the easiest way just to download a mod with a .tra file, delete what they wrote and write mine instead? That's how I got the .tp2 file I'm using.
  • The user and all related content has been deleted.
  • BCaesarBCaesar Member Posts: 452

    @BCaesar Look up the --traify argument. I forget exactly how, but you run Weidu with that argument and it generates one automatically.

    Thanks, I just copied the .tra file from the Imoen Romance and then wiped it and set mine up the same way they did and that worked fine.

    Ok I think I'm almost able to consider this mod a finished product and get it added to the mod list, but I have another couple of questions (for you or anyone else reading this) if you're willing.

    First is, I want to use WeiDU to modify WEAPPROF.2DA instead of overwriting the whole file and the way I did everything else in WeiDU I'd need a separate entry for each weapon per each monk (which comes to something like 60 entries). Do you know of a better way to do that, like one single long entry that changes every row for a column or every column for a row?

    Secondly, for editing each file I followed your example and used:
    SET_2DA_ENTRY #1 #2 #3 ~XXX~

    With XXX being what I wanted to set it to, #1 being the row (minus the first three rows which are not part of the table), and #2 being the column (minus the first column as that's not part of the table either).

    However I wasn't really sure what to put in #3. For the example you gave there were two columns total (including the 1st column which doesn't count for #2) so you used 2. So when I did it for the other files I usually put in a number equal to the total number of columns in the file, but often it edited a different line then the one I wanted and then I would keep trying slightly different numbers until it became right, but I'm sure there's a correct way for me to do it that avoids the futzing. Any advice?
  • The user and all related content has been deleted.
  • BCaesarBCaesar Member Posts: 452

    @BCaesar There's no shorter way to deal with weapprof.2da. One of my mods affects every class and kit, it has like 800 lines of SET_2DA_ENTRY's. It's insane.

    The #3 number is the "minimum column count." So when you say row # whatever, if that row has fewer columns than the number in #3, it will be ignored. WHat this really means is that there are only two things you should put here: 1, or the actual column count of the 2da table. For a file like weapprof.2da, just put 1. The only issue this causes is that some rows, like the very first one with some garbage text, get counted in your row count - because that garbage is considered a column. All this means is that your row number might be different. But that doesn't matter because you just put whatever row number works.

    If you use 1 in #3 with weapprof, I believe row 11 is bastard sword, and row 34 is dual-wielding, and everything else you could possibly want to change is between those two rows. (I think those are the numbers you would use in #1... easy enough to double-check.)

    Thanks! I did all that and it worked. I also changed the 3rd column for all of my previous .tp2 file edits to be 1 and that worked better (for anyone reading this who wants to know the details of what I did it's all in my thread here: https://forums.beamdog.com/discussion/62614/warrior-monk-mod-version-1-05-for-bg1-ee

    One last questions, which I believe will actually be my final question for this mod:

    In this mod I add two rows to STYLBONU.2DA. How would I do that in WeiDU (I'm not editing any rows, just adding two at the bottom.)

    I add:
    SINGLEWEAPON-3 0 0 0 0 -3 0 0 1
    TWOHANDED-3 1 0 0 0 -1 0 -4 1

    which just allows monks to put a 3rd point on Single weapon or two handed weapon which will give a 1 point AC bonus.

    Thanks for all of your help!
  • [Deleted User][Deleted User] Posts: 0
    edited January 2017
    The user and all related content has been deleted.
  • BCaesarBCaesar Member Posts: 452
    edited January 2017

    @BCaesar look up APPEND

    EDIT - in fact I use it in the 2nd post in this thread. Just:

    APPEND ~stylbonu.2da~ ~string~
    Just, with .2da files, make sure you get the number of columns right.
    Ok I used:
    APPEND ~stylbonu.2da~ ~SINGLEWEAPON-3 0 0 0 0 -3 0 0 1~
    APPEND ~stylbonu.2da~ ~TWOHANDED-3 1 0 0 0 -1 0 -4 1~

    and it worked (in the tp2 file there's a lot more space in between all the numbers so they line up right, but it doesn't show in this post).

    So that's it! I'm done. Thank you so much for all of your help. And hopefully this helps other future modders searching for how to do stuff.
  • OlvynChuruOlvynChuru Member Posts: 3,075
    I'm having trouble figuring out how to give effects to creatures in WeiDU. For example, I want to give the level 6 Minsc file "MINSC6" a minimum damage effect (opcode 250) and set the first parameter to 20. What would be the code for that?
  • The user and all related content has been deleted.
    OlvynChuru
  • OlvynChuruOlvynChuru Member Posts: 3,075
    It works! Thank you!
  • OlvynChuruOlvynChuru Member Posts: 3,075
    Now I'm wondering how to set a parameter in an effect to a negative value in WeiDU. For example, I want to give Dorn a large penalty to Save vs Spell.

    I tried this code:

    LPF ADD_CRE_EFFECT INT_VAR opcode=37 target=1 timing=9 parameter1-=50 parameter2=0 END

    But when I look at the effect in the file, the first parameter is equal to 0. I don't know how to make it negative.
  • The user and all related content has been deleted.
    Grammarsalad
  • OlvynChuruOlvynChuru Member Posts: 3,075
    edited February 2017
    It doesn't work.

    LPF ADD_CRE_EFFECT INT_VAR opcode=37 target=1 timing=9 parameter1 = (0 - 50) parameter2=0 END

    It produces an error message:

    ERROR: cannot convert 0-50 or %0-50% to an integer


    Never mind, I caught my problem. It works. Thank you!
  • semiticgoddesssemiticgoddess Member Posts: 14,903
    I know how to assign new strings to items and spells, but how do you create a custom string that you can use in the Display String opcode?

    I want a spell to display a custom string in the dialog box or over a character's head.
  • ArdanisArdanis Member Posts: 1,736
    edited February 2017
    DisplayStringHead(Myself,@123) // where @123 is a standard .tra reference

    PS Sorry, didn't see ti was about opcode.
    Post edited by Ardanis on
  • argent77argent77 Member Posts: 3,431

    I know how to assign new strings to items and spells, but how do you create a custom string that you can use in the Display String opcode?

    I want a spell to display a custom string in the dialog box or over a character's head.

    There are several options.

    1. If your spell contains only a single Display String opcode you can use ALTER_SPELL_EFFECT to modify an existing opcode that you have already added to the spell via NI or DLTCEP:
    COPY ~%MOD_FOLDER%/spells/myspell.spl~ ~override~ LPF ALTER_SPELL_EFFECT INT_VAR match_opcode = 139 // Display String parameter1 = RESOLVE_STR_REF(@123) // resolves tra reference into strref END
    2. You can also create new opcodes completely in WeiDU:
    COPY ~%MOD_FOLDER%/spells/myspell.spl~ ~override~ LPF ADD_SPELL_EFFECT INT_VAR opcode = 139 // Display String target = 2 // Preset target parameter1 = RESOLVE_STR_REF(@123) // resolves tra reference into strref timing = 1 // Instant/Permanent until death resist_dispel = 1 END
    You can use opcode 330 (Float text) if you want to display text over the target's head instead.
    ArdanissemiticgoddessCrevsDaak
  • semiticgoddesssemiticgoddess Member Posts: 14,903
    @argent77: I forgot to mention--your solution worked! I got the message to display properly using yoru code and the Float Text opcode. Thank you!
    GrammarsaladCrevsDaak
  • semiticgoddesssemiticgoddess Member Posts: 14,903
    edited February 2017
    I made a discovery: adding a projectile to an item in WeiDu using the ADD_PROJECTILE function can overwrite any custom name or description you've given to the item using the SAY function, if you've used the COPY function earlier in your TP2 file. To solve this, put both the ADD_PROJECTILE and SAY functions right after the COPY function. Otherwise, using COPY twice will overwrite previous functions.

    This didn't work for me:

    COPY blah blah blah
    SAY blah blah blah

    COPY blah blah blah
    ADD_PROJECTILE blah blah blah

    But this did work for me:

    COPY blah blah blah
    ADD_PROJECTILE blah blah blah
    SAY blah blah blah

    This way, WeiDu will add the projectile and still keep the right name and description. This probably applies to spells as well as items.

    EDIT: Corrected a mistake and updated with advice from @argent77.
    Post edited by semiticgoddess on
  • argent77argent77 Member Posts: 3,431
    edited February 2017
    You shouldn't use COPY twice. The second call will simply overwrite the file from your first call because you're using the original file from your mod again. Use COPY_EXISTING instead for your second call.

    Example:
    COPY ~%MOD_FOLDER%/items/myitem.itm~ ~override~ SAY NAME1 ~blah~ COPY_EXISTING ~myitem.itm~ ~override~ // do some other stuff...
    GrammarsaladCrevsDaak
Sign In or Register to comment.