Jump to content


Photo

How to make an NPC mod for BG2?


  • Please log in to reply
2 replies to this topic

#1 Kulyok

Kulyok
  • Modder
  • 2450 posts

Posted 05 September 2013 - 11:39 PM

Practice shows that the best guide is someone's working code. And an even better guide is someone's explained and commented working code. Hence, Branwen NPC, available at

 

http://www.pocketplane.net/oneday

 

Some code examples here:

 

An example from Branwen's script, O#BranS.baf:

 

// This is where Branwen's friendship talks start. O#BranShutUp is a variable you can set in player-initiated dialogue by telling Branwen you'd like some quiet, or asking her to talk to you again.
// So, when Branwen joins your party, a timer is set for one hour, and the first talk is preparing to run.
// ATTENTION: in all scripts InParty(Myself) should go first or right after Global() conditions if present. It means NPC is present and not dead. If your NPC is dead and this condition is not present, your game might crash.
IF
InParty(Myself)
Global("O#BranShutUp","GLOBAL",0) // O#BranShutUp is used in player-initiated dialogue. Look it up.
Global("O#BranTalk","GLOBAL",0)
THEN
RESPONSE #100
RealSetGlobalTimer("O#BranTimer","GLOBAL",3600)
SetGlobal("O#BranTalk","GLOBAL",1) // Each block must run only once, which is also why we set O#BranTalk to 1 - it means the same set of conditions will never be repeated again
END

 

An example from Branwen's banter file, O#BBran.d:

 

// Read this dialogue file third, after O#Bran.d and O#BranP.d.

BEGIN O#BBRAN

// This is Branwen's banter file. Remember how companions talk to each other? To do it, you need to write CHAINS like the ones below.
// Note that each of these chains has a condition like O#BranAerie1=0. It's technically always true, but on practice all banters in B file(O#BBran.d) trigger ONLY when the banter engine(or jcompton's banter script) tells them to.

// Sometimes modders uses game conventions and use BO#BRAN instead of O#BBRAN. I used this myself in Xan, Tiax and Coran. However, to avoid ALL possible collisions, it's best to use your prefix like we do here: O#BBRAN or even O#BRANB.
// Remember to register your own prefix, though, or there WILL be collisions. If this topic http://forums.blackw...p?showtopic=113 is not available, just ask at forums.pocketplane.net or forums.gibberlings3.net.

// Conditions: InParty(otherNPC) which means they're in party and not dead, See(other NPC), and CamDawg's !StateCheck("Name",CD_STATE_NOTVALID). NPCs can't talk if they're silenced or confused.
// Again, and I can't stress that enough, you have to set your variable to 1 in the banter, or it will trigger again.
CHAIN
IF ~InParty("Aerie")
See("Aerie")
!StateCheck("Aerie",CD_STATE_NOTVALID)
!StateCheck("O#Bran",CD_STATE_NOTVALID)
Global("O#BranAerie1","GLOBAL",0)~ THEN O#BBRAN O#BranAerie1
~Speak up, girl! Why are you always mumbling and stuttering?~
DO ~SetGlobal("O#BranAerie1","GLOBAL",1)~
== BAERIE ~I'm not!~
== O#BBRAN ~Are too!~
== BAERIE ~Not!~
== O#BBRAN ~Are!~
== BAERIE ~Not, not, not! And you're too big and too loud and your feet are smelly when you take your huge boots off! So there!~
== O#BBRAN ~Ha! When you want to, you're a regular little lioness, girl.~
EXIT

An example from Branwen's installation file, Setup-Branwen.tp2

 

// This is Branwen NPC, created to help other NPC modders. If you just want to play, close this file and run Setup-Branwen.exe :)

// Okay, let's begin. Note these two slashes. These mean "commentary". Weidu will not compile this.
// There's lots of commentary here. Just remember, it's not all code. It's just notes to help you code quicker and better.
/* Weidu will not compile this, either. This is commentary, too. The difference is, two slashes can only comment one line, whereas this way you can comment out entire paragraphs. */

// What is Weidu? Let's say it's an exe file I renamed as Setup-Branwen.exe. Now, *this* file, Setup-Branwen.tp2, is a list of commands I'm giving Weidu. They will execute when I run Setup-Branwen.exe.

// BACKUP is necessary. When you install the mod, if you add to Anomen's dialogue, his backup dialogue will be in Branwen/Backup.

BACKUP ~Branwen/Backup~

AUTHOR ~Kulyok at http://forums.pocketplane.net~ // If the player gets an installation error, he'll know where to post his bug reports

VERSION ~v1~ // This is not necessary, but recommended. V4, v1alpha, v1.23 will work too.

BEGIN ~Branwen BG2 NPC mod for players and modders~ // This is the name of your mod.

// These two lines were created by CamDawg. It's a new state that checks if NPC is able to talk. USE this in your mod. See the dialogue for details.
APPEND ~STATE.IDS~ ~0x80101FEF CD_STATE_NOTVALID~
UNLESS ~CD_STATE_NOTVALID~

COPY ~Branwen/Audio~ ~override~ // All Branwen's audio files are in the game now, and we'll hear them when she talks.

// I am going to use my prefix now. For the purposes of this mod, it is going to be O#. DON'T USE IT, REGISTER YOUR OWN!
// Go here: http://forums.blackw...p?showtopic=113 - the list of prefixes is in the first post of the thread. Use it in ALL your files and ALL variables.

// Remember that all your filenames should not be longer than 8 symbols. Hence I often use O#Bran, and not O#Branwen(9 symbols).
// You can use long character's names in variables, if you want. But I use variable names like O#BranSomething instead of O#BranwenSomething, so it's easier for you to mass-replace(read below).

// HOW TO DO A QUICK MASS-REPLACE WHEN YOU'VE GOT YOUR OWN PREFIX?

// Imagine you have an NPC called Anna, and your prefix is BB(and, yes, this prefix is taken, too, it's just hypothetical).

// To use my code for your NPC, replace all o#bran with bbanna(if you want it to be case-sensitive, then o#bran with bbanna, O#Bran with BBAnna and O#BRAN with BBANNA).
// Exceptions are ToB files(with 25's in it), where you have to replace o#bran with bbanna, and THEN o#bra with bbann(files can be only eight symbols long, so I have to use O#BBRA25.d, not O#BBRAN25.d).
// Naturally, make backups before you mass-replace.

 

 

In other words, all comments, no code, but the code is somewhere there, trust me. I checked.

 

 

Have fun stealing it! Remember your own modding prefix, Branwen is playable and fully romanceable, too! A friendship path is included, if you wish to code your own.

 



#2 Eric P.

Eric P.

    Journeyman Modder

  • Member
  • 1178 posts

Donator

Posted 06 September 2013 - 06:18 AM

I like how it mentions that backup (the folder) is necessary. I see many mods that don't even have this folder, so I always create it after I d/l a mod, if it's not present. Call me harsh, but I consider it to be irresponsible to not include the backup folder. Further, it's a good idea to always create a folder inside backup, and name it 0 (the number zero, not the capital letter O). This will decrease, if not eliminate, the possibility of the backup folder being erased for some reason.


Working and playing on a Mac Pro 6,1 running Mac OS X 10.13.6 High Sierra, and a Mac Pro 3,1 running Mac OS X 10.11.6 El Capitan.

~Buion na 'ell! I serve with joy! Your eyes and ears I shall be. Let us hunt together!~
- Erysseril Gwaethorien: a joinable, romanceable NPC mod for BGII - SoA/ToB, in sporadic development.

A female elf warrior of nature and a Bhaalspawn cross paths during their quests, joining forces to share adventure and companionship. Will they find more?


#3 Kulyok

Kulyok
  • Modder
  • 2450 posts

Posted 06 September 2013 - 07:02 AM

Weidu requires the BACKUP *command*, since it's the core of Weidu - it has to backup my game files before it overwrites them. The funny thing is, the actual backup *folder* is not necessary with the newer versions of Weidu - Weidu will create it for you, if you don't have it. I create it in my mods, though - for completeness.

 

(Anyway, if you're a beginner modder who's reading this - stick to placing BACKUP command to your .tp2 and you'll be fine).