Jump to content

A Scholar tries to Mod - Part 1 - Are the files referenced through other files?

Recommended Posts

Hi everyone. I'm new to the modding scene and am working on a dual-wielding Avenger druid NPC to join everyone's rank. Unfortunately, I know very little and trying to find the equivalent of a How to Mod BG2 for dummies is like trying to find several needles in various haystacks. This is, of course, pt.1, of what is most likely, many parts of me trying to make the mod a reality.

With that being said, part 1 is of the following code with Kulyox's (Thank god they made this, or else I would have gone insane) Branwen mod.

// This is my creature file, my .cre file. How to create it? Create a character in the game, export him, open him via Shadowkeeper and convert him to .cre. Or copy an existing .cre file. Near Infinity and DLTCEP help you edit your .cre.
COPY ~Branwen/Characters/O#Bran.cre~ ~override/O#Bran.cre~ // copy our .cre file to the game. Below I edit(patch) O#Bran.cre, adding a soundset, a bio, a dialogue file and other nice things.
SAY NAME1 @2 /* Branwen */
SAY NAME2 @2 /* Branwen */
SAY INITIAL_MEETING @3 /* By the ice breath of Auril! 'Tis good to see new faces and taste freedom again. */ // This text in square brackets means that BRANW01.wav is assigned here.
SAY MORALE @4 /* Tempus, forgive my cowardice. */
SAY HAPPY @5 /* I am proud to stand among such strong warriors. */
SAY UNHAPPY_ANNOYED @6 /* Our actions are not those of warrior born. */
SAY UNHAPPY_SERIOUS @7 /* What sort of craven cowards are we? */
SAY UNHAPPY_BREAKING @8 /* I can no longer honorably work with such as you. */
SAY LEADER @9 /* I have always dreamt of leading such a worthy band. */
SAY TIRED @10 /* I'm tired. */

I went through the mod files and yet I cannot find a file that simply lists all the select, battlecry, and basic click gameplay quotes. I understand the tp2 files instruct the WeIDu program to install the file a certain way. However, the lines above show comments. What I want to know is do I have to manually make the cre, write in the lines via NearInfinity, and then export it with the soundbytes included (after directing the file location for them) or do I have to make a file in the dialogue that is used to reference them? They use @1 to @ infinite so I had assume like coding in Java there would be a main class and then a local or another class holding all the variables and the data involved.

Also,  for part 2, how do I make a NPC that's only purpose is to introduce the Druid mod NPC I plan on making? I apologize if it's too vague but trying to make this is very confusing and it's like translating languages (Which is arguably is).

Link to comment

The // or /*
-comments are there to show what the @x where the x is a number references to in a given .tra file. Which is where the translations are... as weidu has language commands that allow different selections of them during the install and coding for that.

Where to make Non_Party-joinable Characters... well if you want to use a commoner, then you find a commoner, in this case a monk- in the game files and it's possible to copy those and plant them to an area. Via patching the area file, or it's script, so it's plants itself when the player first enters the area, via the deathvariable(deathvar)... and so forth. Usually the later one is less involved and better at patching stuff.
Also understand that you can patch small files like .cre's and other small files via the:

COPY_EXTERNAL ~monk.cre~ ~override/modcre1.cre~
SAY NAME1 ~name~
WRITE_ASCII 0x280 deathvar

And so you do it at that point, to give it a death_variable so you can summon it. the ~~ characters are there to mostly just keep things in order, similar to as the "",'s and others, some of them are not needed, but some are, as for example the second ones are as you need to instruct the directory as a whole...
Ask for more when needed. I or soneone else will help futher.

Edited by Jarno Mikkola
Link to comment

Stuff like the selection quotes, in a CRE file, are references to strings. In the file itself, it's just a number. That number points to an entry in DIALOG.TLK, which contains the plain text of the string and optionally links a sound file. Each of the game's languages has its own instance of DIALOG.TLK, and these files are so critical that you really shouldn't ever directly edit them; instead, go through safer tools such as WeiDU's SAY command.

So then, you can't just build the CRE file yourself with all the strings. Those strings aren't in the CRE file at all. You have to add them into the TLK file with WeiDU, and then patch them into the CRE file at the appropriate place.

Adding new strings is normally done with tra references; you create a tra file for each language your mod supports, which is simply a numbered list of strings. If that string has a sound attached to it, you put the sound file's name inside square brackets. Here's an example from the WeiDU documentation, using the dialog of Sir Sarles in BG2:

// SCSARLES translation file
@1   = ~Who is it? Might I ask why you have disturbed my meditations?
My creative muse must be gently awakened, and your stomping
about is simply not conducive to this.~ [SARLES02]
@2   = ~My apologies. I will leave you to your thinking.~
@3   = ~I apologize, but I have come to request your talent on a commissioned artwork.~

The ~ ~ characters delimit strings. " " can also be used for the same purpose, and in some instances you need to use both due to nesting issues or a string that contains quote marks. Thalantyr's parting words regarding "intelligence" versus "luck", for example. In this case, the first string has an associated sound; the [SARLES02] tells WeiDU to mark that string as having the sound SARLES02.WAV.

Once you have this tra file, you use it with @ references in your .tp*/.d/.baf files. @1 puts in that first string, @2 the second, and @3 the third. You don't have to use 1, 2, and 3, of course; any whole numbers will do as long as each string is unique.

So, then, back to that example. The first thing we're adding is the creature's name (Branwen), which is string @2 in the tra file that exists ... somewhere else. The line

SAY NAME1 @2 /* Branwen */

says we need to write a (four-byte) number at offset NAME1 ( = 8; it's a predefined constant in WeiDU) in the file that points to the string "Branwen". WeiDU first looks through the TLK to find if that string is already there. It is, in both BG1 and BG2, but we'll imagine that it's not. That means we need to add a new entry to the TLK, and WeiDU does this automatically. The new entry has a number (bigger than all the old strings), and we write that number to offset 8. This creature's name is now Branwen. All that in one deceptively simple line.

What's next?

SAY NAME2 @2 /* Branwen */

Ah. There are two name fields in the CRE file, and we're filling both of them with the same thing. They may be different in some cases - the first field is the "long name" and the second is the "short name/tooltip" - but most of the time they're exactly the same. And that means the string we're putting there is definitely already in the TLK. So WeiDU runs through that and finds the string that time, returning the number of the new entry we added last time and writing that number to the CRE file at offset 12.

All right, one more. In this case, the tra entry for Branwen's initial greeting is followed by [BRANW01] as in the example I gave above. So it's not just a plain text string, but also has an associated sound. WeiDU looks for a full match in the TLK; an entry with the right text but not the right sound wouldn't be a match here. Again, we either return an existing string reference or a new one, and write that number to the CRE file.


On to part 2. So, you want to create a new NPC. What will they do? You want them to introduce your joinable NPC, and presumably they'll do so by talking. Most likely, you want that NPC to walk up to the PCs and talk to them. They need a script for that, and for this simple task you can use an already extant generic script such as INITDLG; that'll go in the "override" script slot. Then they need a name/title, which is another round of editing that creature. They need basic stats and reactions if attacked (do they run? do they fight back, and how?), which ... honestly, you'll probably just clone some existing NPC. Because the main point of this character is what they say; most of your effort will go into building their dialogue file.

Link to comment

Ok. So to simplify the responses I've gotten (Thank you all so much by the way.), for me to add the basic clickable character responses, I need to put them in a tra file for every language that I plan on doing (which is only English unless someone wants to translate for me) and write them in WeIDU format. I will also need .baf files to also put in the dialogue for said NPC.

WeIDU adds the dialogue automatically.

If I have sounds, I put them in square brackets next to the dialogue being said. They should be in wav format.

I do not touch the DIALOGUE.TLK files because they are critical and should be left untouched.

To make a simple NPC, I  can just make a copy, edit/build their dialogue file, and script file (Assuming they also need a .tp2 file and a .tra file), and put it in the "override" script slot (I thought this was a file location and I am unsure what INITDLG is).

Link to comment

INITDLG.BCS is a resource that already exists in the base game; it's just a script that tells the character to walk up to a PC and talk to them at the first opportunity.

The various "script" fields in the character file are each eight-byte text fields; you enter the resource reference for whatever script you're using, or leave the field empty. In some cases, like the joinable NPC's main script, you'll want to write your own scripts (in the BAF format, then you compile them either with WeiDU or a tool such as NI). But if you can just use a script that already exists, why not?

Oh, and you build dialogue with the .D format; that should have examples in the reference you're using, and of course, the WeiDU documentation has a lot to say about it too. Dialogue-building is where WeiDU started, and it's a very flexible tool that allows you to do everything from making small changes in existing .DLG files to creating entirely new .DLG files. Here are two examples from my own work:








This .D file - that's the whole thing - edits seven existing dialogue files to have them set a variable at appropriate points. Those variables are then used in altered map scripts to add map markers for quest locations (usually people's houses).


(Spoilered for size)

// Rescued from the game files, originally part of Black Pits 2
// Rebalancing and corrections by jmerry, first demonstrated on the Beamdog forums
// Only one original string; all others are in the game already
// FLAGS 512 for instant execution of actions. Otherwise, setting vars has a delay


IF ~  Global("j8noober","GLOBAL",2)
~ THEN BEGIN 0 // from: 2.0
  SAY #100796 /* ~Heya! Wanna play a game?~ */
  IF ~~ THEN REPLY #100797 /* ~Yes!~ */ GOTO 3
  IF ~~ THEN REPLY #100798 /* ~Yes.~ */ GOTO 3
  IF ~~ THEN REPLY #100799 /* ~Yes?~ */ GOTO 3
  IF ~~ THEN REPLY #100800 /* ~No.~ */ GOTO 1
  IF ~~ THEN REPLY #100801 /* ~No. Gods, no.~ */ GOTO 1

// Lots of stuff snipped; the full file is 172 KB

IF ~~ THEN BEGIN 334 // from: 333.1 333.2
  SAY #101630 /* ~What about now?~ */
  IF ~~ THEN REPLY #101635 /* ~Okay, perhaps I will try another class.~ */ GOTO 327
  IF ~~ THEN REPLY #101636 /* ~You are the most reprehensible creature in the entire world.~ */ GOTO 335

IF ~~ THEN BEGIN 335 // from: 334.1
  SAY #101637 /* ~It appears my time is up, my friend. Goodbye, <CHARNAME>! It has been quite the adventure this past while. Perhaps we shall see each other again some day.~ */
  IF ~~ THEN DO ~GiveItemCreate("j8#shirt",LastTalkedToBy,0,0,0)
EscapeArea()~ EXIT

That entire unreasonably large file is devoted to one character's dialogue. One conversation, even. And, as indicated by all the # references, it's basically already in the game. I generated it by using NI's export function to convert that DLG to a D, then hand-edited the parts that I wanted to change. (The conversation in question is functionally a text-based adventure game)

You don't need separate .tp* files for every little thing you add. No matter how big your mod gets, there should be only one .tp2 file - this is where installation will start from. You might add some auxiliary .tp* files (traditionally .tpa or .tph, but the third character doesn't really matter as long as it's not 2) for stuff like libraries of functions you're including or more complex components, but you can just pack lots of unrelated stuff together into one file. I have a tweak mod with around 50 components; that has one .tp2 plus nine .tph/.tpa files in my "lib" folder to support it. Most of those auxiliary files are library files that add a function I need to use somewhere.

Link to comment
12 hours ago, CursedScholar said:

..for me to add the basic clickable character responses, I need to put them in a tra file for every language that I plan on doing (which is only English unless someone wants to translate for me) and write them in WeIDU format...

If you only have one language, then you don't need a .tra files at all. But you cannot use the @numbering system if you don't have a .tra file.
And there's some technical issues also that can pop up, but that not a large consern here yet if you are starting your mod making, as it has to do with foreign characters... or rather character encodings.

12 hours ago, CursedScholar said:

WeIDU adds the dialogue automatically.

Technically it doesn't. But if you compile a .d file into a .dlg, via weidu, then that process does it for you.
And coding this in a .tp2 action is as simple as COMPILE ~mod_folder_name/d_files~ //in where the .d file is in .. it tries to compile every file in the folder, so usage of subfolders is very much implied.

Edited by Jarno Mikkola
Link to comment

You don't have to COMPILE a full folder; both of the examples I gave specify the exact file. Actually, running a full-folder action like that is strongly discouraged, as  some operating systems can spontaneously add files to a folder that the mod needs to ignore. Or at least, if you do something across a full-folder, use a regex to make sure that you're only applying the action to files with the right extension.

Link to comment
1 hour ago, jmerry said:

s  some operating systems can spontaneously add files to a folder that the mod needs to ignore.

It's not Operation Systems, it's programs running in them that do... like the mac quick search function. (edited)
Or for example, picture quick access functions. You might want to get rid of all those. If you don't know why your computer has them...

Edited by Jarno Mikkola
Link to comment

I'm on a Mac. And you should never assume that other users will go into obscure settings to disable stuff like that. I haven't disabled that feature, after all - which means that any folder I so much as look at will have a hidden file named ".DS_Store"

Link to comment

Well, it's been a while since I've gone ahead and replied to this specific thread. Finally, got a prefix for my mod and I've been working on the file a little bit. I made three Creature Files. The idea is that my main NPC will acquired by talking to the main quest giver in my Druid mod. For this to work, is there a way I can do something like:

BEGIN (File to be named)

IF ~NumTimesTalkedTo(0)~ THEN BEGIN 0

Fred: Pumpkins here. Get your pumpkins here!        /* Quest Giver */
Halfling: 10 copper, 7 copper, 9 copper....        /* Random NPC given to get a few lines */
Wallace: Keep moving!     /*  The NPC that will sooner or later join the party */

The conversation above will then lead to Fred getting paid gold which will then cause Wallace to join the party. But I am unsure how to write a dialogue with the starting line being another NPC. I used Nearinfiity to make the characters via CHR conversion and editing. Wallace is a druid avenger joinable NPC. We don't have enough druids I say but that aside, do I use
IF (Fred is nearby?)
Start 1st Conversation of mod?

I am unsure how to go about this.

Link to comment

Yes, this looks like a textbook application for CHAIN. As for an NPC starting a dialogue, you do that by scripting the NPC to initiate dialogue with someone in the party, even if their actual conversation is entirely with non-party NPCs. Now, some of the subtler details:

- The files referenced in the CHAIN are all dialogue files, not creature files. So here, the non-party characters "Fred" and "Halfling" would each have a single DLG file, which you would usually use the same resource name as the CRE file for. The future party character "Wallace" would have several dialogue files; this would go in their "initial" dialogue file used before they join the party the first time.

- CHAIN adds its lines to existing DLG files. So you need to create all of those files (that aren't in the base game) before that CHAIN. Which ... well, it's often appropriate to start a D file with a bunch of BEGIN statements that create DLGs. For example, here's an excerpt from the beginning one of the D files in the Isra NPC mod:


Four characters used in that NPC's quests get their dialogue files created here, and all of them later get lines added as part of CHAINs. You don't have to do stuff with the files you BEGIN right away.

- What happens when a character isn't around for the dialogue to jump to? If no character with the appropriate dialogue file is available to speak in the scene, the conversation just ends instead - as a player, you might not even notice that anything went wrong right away. Anything that conversation needed to do later on like set variables - not happening. This is a common way to break quest/dialogue scripting; try to make sure that everyone who needs to speak in a scene is present and capable of speaking.

Link to comment

So would something like this work then? I made the .d files for all three characters but these commands are in Fred's dialogue because he's the one starting the conversation. I used this tutorial as reference and built the start of this dialogue as such.

Also for each NPC file will I need to rewrite this dialogue and place it in the file or can I just write "BEGIN CFFRED"?


/* Introduction:

In the slums of Atlkatla, there is a man parading around his pumpkins. Upon closer inspection, there appears to be pumpkin that moves. */


IF ~InParty("Fred")
~Pumpkins here. Get your pumpkins here!~
~10 copper, 7 copper, 9 copper....~
~Keep moving!~
~What was that?~
~Oh my~
DO ~LeaveArea("AR0400",[414.1048],4)~
~Sir Wallace, you can't keep scaring away the customers. The farm is going to notice and pawn you off by force.~
~Oh, and what am I supposed to? Watch my friends die by being eaten or mashed?

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.

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...