Jump to content


Photo

How to make an NPC if you are a NOOB.


No replies to this topic

#1 theacefes

theacefes

    XTREME METAL ROCKER PUNK CHICK WITH ULTRA SURFBOARD

  • Gibberling Poobah
  • 2704 posts
  • Gender:Female
  • Location:Irvine, CA, USA

Posted 15 April 2006 - 11:16 PM

Okay well here is an updated version of my NPC tutorial. This is all well and fine, but if you would like it in an easier to read format, please download the PDF below.

Attached File  Microsoft_Word___How_To_Make_An_NPC_If_You_Are_A_N00B.pdf   73.59KB   974 downloads

How To Make An NPC If You Are A N00B
By: theacefes bohdi2185@msn.com
Version 2
After realizing that I haven’t edited this in forever, I decided to write an updated version of my NPC tutorial . The purpose of this tutorial is not to teach people how to write and code an entire mod, but how to get a very basic NPC into the game.
So, without further delay, I present to you: Version 2!

TABLE OF CONTENTS:

1. INTRODUCTION
2. THE DIALOGUE
3. THE CRE
4. THE AREA FILE
5. THE TP2 and finishing up


1. INTRODUCTION

While there are other NPC tutorials out there, I feel that this one is very clear and easy to understand for the total noob (and yes, we were all noobs once). This tutorial will go through how to make an introduction dialogue, a creature file, an area file, and a TP2 file. I've gathered a list of terms that you many or may not have known before, but you will see them over and over if you decide to go into modding.

Common Terms:

PC- the character that you are playing as (player character)

NPC- any character in the game that is not you. ex: Jaheira and Imoen, and this character you are about to make. (Non-player character)

Dialogue: the actual conversations between PCs and NPCs, or NPCs and NPCs.

Script: the code that tells the game what to do (ex: where to move
characters, what conversation to start, when to start a quest, etc)

WeiDU: the program that allows mods to be compiled and installed
into BG2.

TP2: the file that lists all the parts of the mod that will be
installed so that WeiDU knows what to install.


Here are some of the programs you will want to have/download if you want to continue with this tutorial:

1. Some sort of text editor (Notepad, ConTEXT, etc)

2. NearInfinity (the beta) http://www.idi.ntnu.no/~joh/ni/

3. ShadowKeeper (edits stats easily) http://www.mud-maste...eeper/Home.html

4. WeiDU (compiles all your mod files into the game) http://weidu.org/

5. Infinity Explorer (you don't HAVE to have this but it's a neat program that allows you to see all the dialogues and scripts and anything else in the game) http://infexp.sourceforge.net/


2.THE DIALOGUE

This particular dialogue is the introductory dialogue, meaning, this is the dialogue where your NPC will want to join your party. I'll try and make this as easy as possible. For this tutorial, we are going to use my made up NPC, John.
Before I go into the dialogue, I want to talk about two things: file types and prefixes.

File Types: Basically, when you use your text editor, you have to save your mod files with certain file extensions.
- Dialogue files use a “.d” extension.
- Script files are compiled into the game as “.bcs” but when you make a script file, you are going to save it as a “.baf”.
- Portraits need to be bitmaps (.bmp)
- Sounds/music must be either in .wav or a format that can be decoded into .wavs (like .oggs)
- Your tp2 file, which contains all the instructions that WeiDU needs to follow to install your mod, uses a .tp2 extension.
Prefixes: Having your own prefix that you use in all of your coding is very important if you want for your mod to avoid any conflict with other mods. An example of a prefix would be my use of “K#” in front of all of my mod files and variables. You can view a list of the already registered prefixes or to register your own here.
Okay, so…let’s get started. NPCs need to have a few different files to function properly in the game. This includes files that will hold all the NPC’s dialogues if they are in the party, bantering, leaving the party, or just having their introductory talk with the PC. You can name these anything you want as long as it's 7 letter or less. You should use your prefix at the beginning of your filename. I'll use my first initial and # so that my intro. dialogue is named K#John.


2) Open up your text editor and save the file as "all files" type and in the box where you name the file, type "K#John.d" or whatever you decided to name your NPC.


3) At the top of the page, type "BEGIN K#John". Now, in coding, everything is based off of an "IF...THEN" process. So, let's go ahead and begin our introductory dialogue.


BEGIN K#John 

IF ~NumTimesTalkedTo(0)~ THEN BEGIN Talk1



This means that IF the number of times the PC and John have spoken is 0, then this dialogue, which is called "Talk1" will occur.


BEGIN K#John 

IF ~NumTimesTalkedTo(0)~ THEN BEGIN Talk1 
SAY ~Hey there, I'm John and I'm a new NPC!~


The tildes "~" are like quotation marks. "SAY" is obviously what John is saying to the PC. Now comes the choices the PC has to answer John with. All of the choices must start with IF ~~ THEN REPLY. If there is a special condition for one of the choices, then it would be put into those ~~ in "IF ~~ THEN REPLY"


IF ~~ THEN REPLY ~I'm <CHARNAME>, how are you, John?~ GOTO HiThere 
IF ~~ THEN REPLY ~I'm sorry, but I don't have time to speak with you 
right now.~ GOTO EndTalk 
END

<CHARNAME> is what's called a "dialogue token". If you put <CHARNAME> anywhere in the conversation, in the game the PC's name will appear. Neat, huh? GOTO HiThere/EndTalk is telling the game that there will be two blocks of dialogue called "HiThere" and "EndTalk". GOTO is connected the PC's choice with its respected block. END is ending the block.




IF ~~ THEN BEGIN HiThere 
SAY ~I'm fine. Can I join your group?~ 
IF ~~ THEN REPLY ~Sure, why not?~ DO ~SetGlobal("JohnJoined","LOCALS",1) JoinParty()~ EXIT 
IF ~~ THEN REPLY ~I'm afraid I can't accept your offer right now. 
Perhaps later.~ EXIT 
END


IF ~~ THEN BEGIN HiThere is beginning the block for Hithere. A Global is a variable. Globals can either be labeled as GLOBAL or LOCALS. GLOBALS are variables that can be used by any script in the game. LOCALS are variables that can only be used by the script running it. "JohnJoined" is a global in this. 0 means that the global is not active, while 1 means that it is (for most globals). DO ~SetGlobal("JohnJoined","LOCALS",1)JoinParty()~ is telling the game to make John join the party. EXIT ends the conversation while END ends the block.




IF ~~ THEN BEGIN EndTalk 
SAY ~(sigh) Very well. Just come back if you change your mind.  I'll be here.~ 
IF ~~ THEN EXIT 
END


This is pretty simple. Usually, if I want to put an action on the NPC's part, I use (), but it's not necessary.

Okay, so...that's the first part of the dialogue is done. Now we will create the block where the PC returns to John after rejecting him (in case the PC changed his/her mind).



IF ~NumTimesTalkedToGT(0)~ THEN BEGIN Talk2 
SAY ~You're back! Can I join now?~ 
IF ~~ THEN REPLY ~Sure, why not?~ DO ~SetGlobal("JohnJoined","LOCALS",1) 
JoinParty()~ EXIT 
IF ~~ THEN REPLY ~On second thought, I don't think that's a good 
idea right now.~ EXIT 
END

NumTimesTalkedToGT(0) looks complicated but it's quite simple. Basically, GT means "greater than". So...if the number of times talked to is greater than 0, then the SecondMeeting will begin. Okay...now...we have to make John's parting dialogue, which is the conversation you have with him when you kick him out. Go ahead and right under the SecondMeeting block, make a space and put BEGIN K#JohnP



BEGIN K#JohnP 

IF ~Global("JohnJoined","LOCALS",1)~ THEN BEGIN LeaveGroup 
SAY ~What? You don't need me?~ 
IF ~~ THEN REPLY ~My mistake, please stay.~ DO ~JoinParty()~ EXIT 
IF ~~ THEN REPLY ~You suck. Bye.~ DO ~EscapeArea()~ EXIT 
END


EscapeArea means that if you kick John out, he will not come back. If you want for John to be available again, use this instead.



IF ~Global("JohnJoined","LOCALS",1)~ THEN BEGIN LeaveGroup 
SAY ~What? You don't need me?~ 
IF ~~ THEN REPLY ~My mistake, please stay.~ DO ~JoinParty()~ EXIT 
IF ~~ THEN REPLY ~You suck. Bye.~ EXIT 
END


IF ~Global("JohnJoined","LOCALS",0)~ THEN BEGIN ComeBack 
SAY ~You want me to rejoin?~ 
IF ~~ THEN REPLY ~Welcome back.~ DO ~SetGlobal("JohnJoined","LOCALS",1) 
JoinParty()~ EXIT 
IF ~~ THEN REPLY ~Nope, you still suck.~ EXIT 
END

So that's it! Here is the whole thing!

BEGIN K#John 

IF ~NumTimesTalkedTo(0)~ THEN BEGIN Talk1 
SAY ~Hey there, I'm John and I'm a new NPC!~ 

IF ~~ THEN REPLY ~I'm <CHARNAME>, how are you, John?~ GOTO HiThere 
IF ~~ THEN REPLY ~I'm sorry, but I don't have time to speak with you 
right now.~ GOTO EndTalk 
END 

IF ~~ THEN BEGIN HiThere 
SAY ~I'm fine. Can I join your group?~ 
IF ~~ THEN REPLY ~Sure, why not?~ DO ~SetGlobal("JohnJoined","LOCALS",1) 
JoinParty()~ EXIT 
IF ~~ THEN REPLY ~I'm afraid I can't accept your offer right now. 
Perhaps later.~ EXIT 
END 

IF ~~ THEN BEGIN EndTalk 
SAY ~(sigh) Very well. Just come back if you change your mind. 
I'll be here.~ 
IF ~~ THEN EXIT 
END 

IF ~NumTimesTalkedToGT(0)~ THEN BEGIN Talk2 
SAY ~You're back! Can I join now?~ 
IF ~~ THEN REPLY ~Sure, why not?~ DO 

~SetGlobal("JohnJoined","LOCALS",1) 
JoinParty()~ EXIT 
IF ~~ THEN REPLY ~On second thought, I don't think that's a good 
idea right now.~ EXIT 
END



BEGIN K#JohnP 

IF ~Global("JohnJoined","LOCALS",1)~ THEN BEGIN LeaveGroup 
SAY ~What? You don't need me?~ 
IF ~~ THEN REPLY ~My mistake, please stay.~ DO ~JoinParty()~ EXIT 
IF ~~ THEN REPLY ~You suck. Bye.~ DO ~EscapeArea()~ EXIT 
END

OR

IF ~Global("JohnJoined","LOCALS",1)~ THEN BEGIN LeaveGroup 
SAY ~What? You don't need me?~ 
IF ~~ THEN REPLY ~My mistake, please stay.~ DO ~JoinParty()~ EXIT 
IF ~~ THEN REPLY ~You suck. Bye.~ EXIT 
END 



IF ~Global("JohnJoined","LOCALS",0)~ THEN BEGIN ComeBack 
SAY ~You want me to rejoin?~ 
IF ~~ THEN REPLY ~Welcome back.~ DO ~SetGlobal("JohnJoined","LOCALS",1) 
JoinParty()~ EXIT 
IF ~~ THEN REPLY ~Nope, you still suck.~ EXIT 
END

Okay, that’s the end of the Dialogue. Mind you, this is a VERY simplified version of a dialogue.

3. THE CRE


1) A CRE is a creature file. Every character/monster/chicken/etc has a CRE file. In order to make one, we must use NearInfinity. The easiest way to do this is to use a CHR (character file; you know, the ones you can import ex: FIGHTER, CLERIC, etc)


2) Go ahead and open ShadowKeeper and open up a character file. Edit the stats and weapons if you like. Then, when you exit, ShadowKeeper will ask you to name it a different file. So...I picked the Fighter chr. so I'll change the stats to whatever I like and rename it John.


3) Now open NearInfinity. Go to the tab on the side labeled CHR and click on John. Now go to FILE and click "CONVERT CHR to CRE". It should save as JOHN.CRE


4) Now go to GAME, then OPEN FILE. Then click BROWSE. Find JOHN.CRE and open it in a new window.


5) Okay, now we have our CRE file open. You will need to do a few things. First, scroll down to where it says FLAGS. Click on FLAGS and at the bottom there should be a bunch of options, one of which says EXPORTS ALLOWED and it is checked. Uncheck it.


6) Where it says GOLD, you can double click that and change it if you want.


7) ANIMATION ID: You can change the way your NPC's paperdoll looks, for example, my mod, Auren Aseph, is a human, but her paperdoll is an elf.


8 ) Colors: Where it says "major/minor/skin/hair/etc" color, make sure you keep them all below 68 or 69...otherwise the game will crash when you try to load your NPC.


9) Portraits: where it says large and small portrait, you can enter a different filename if you don't like the default portraits, just remember to use .bmp files (make your own portrait and stick it in the Portraits folder in your BG2 directory); the game won't accept jpegs.

10) Scroll down until you get to Override Script: type in K#John (or whatever your npc's filename is)


11) Where it says DEFAULT SCRIPT, scroll through the options and find NONE, then click "update value". If you want for your NPC to initiate the conversation by walking up to the PC, scroll and find INITDLG.BCS and click "update value"


12) For Enemy-Ally, find Neutral 128 and update value, so that your NPC will have a blue circle when you meet them.

13) GENDER: This is where you change the gender to male or female

14) RACE: This is where you choose what Race your NPC will be if you wish to change it.

15) ALIGNMENT: Changes your NPCs alignment (mind you, you can do all these little changes in SHADOWKEEPER before you make the CRE)

16) Script name: Also called the Death Variable or DV for short. This is kind of your NPCs ID. You will use this in banters and other conversations as well as scripts in the game. Double click it and type K#John.



17) Dialogue: Right click and choose "edit as string" and type K#John. This is the dialogue that we just made.

Wow...that was a lot, but it wasn't too hard, was it? That's it for the CRE. Just save it otherwise you'll have done all this work for nothing!

4. THE AREA FILE


So, now we want for our NPC to show up at a certain place. Since the Copper Coronet is where many NPCs can be found, let's go ahead and make him appear there.

1) Go ahead and open up a new text editor document and once again, save as "all files" type and save as "AR0406.baf" without the quotes of course...because AR means "area" and 0406 is the number of the Copper Coronet.

2) Go ahead and type this:


IF 
Global("JOHNExists","AR0406",0) 
THEN 
RESPONSE #100 
SetGlobal("JOHNExists","AR0406",1) 
CreateCreature("JOHN",[1483.1934],3) 
END


JOHNExists is a global (variable) in the game now. The 1483.1934 are the x, y coordinates (the game screen is like a graph) and 3 is the direction the NPC is facing (it goes from 1 to 15.

Okay, so save the file and close it.

5. THE TP2

All right, we are almost done!

1) In your BG2 directory, make a new folder and call it John. Open the folder and inside it, make another folder and call is "backup".

2) Find WeiDU.exe (it's the one that looks like a black window). Copy and paste it in your BG2 directory and rename it: Setup-John.exe


3) Now open up yet another new text file and save it as Setup-John.tp2 This will be what tells WeiDU what to install.

4) Copy and move (or just move) your dialogue file, your CRE file, and your area file into the John folder.

5) Now, in your TP2 file, type this:



BACKUP ~John/backup~ 
AUTHOR ~theacefes (bohdi2185@msn.com)~ 
BEGIN ~John for BG2:SoA~ 

// This adds our CRE file 

COPY ~John/JOHN.cre~ ~override/JOHN.cre~ 

// This allows for your NPC's name to be shown in the game during conversations and also on the character sheet 

SAY NAME1 ~John~ 
SAY NAME2 ~John~ 

// This is the biography. In NearInfinity, go to that side tab and find CHR. Open that and find JOHN.BIO You can create your own bio this way by simply deleting the default PC bio and typing your own. Save this. 

SAY BIO ~When you ask him about his past, JOHN says to shut up.~ 

// These are the different things that your NPC will say when they respond to your commands. 

SAY MORALE ~Sticking around is only going to get us killed.~ 
SAY HAPPY ~This group is great~ 
SAY UNHAPPY_ANNOYED ~You're starting to take the wrong path in morals.~ 
SAY UNHAPPY_SERIOUS ~I'll leave if you don’t stop!~ 
SAY UNHAPPY_BREAKING ~You suck, I'm outta here.~ 
SAY LEADER ~Yay I'm the leader!~ 
SAY TIRED ~I'm tired.~ 
SAY BORED ~I'm bored.~ 
SAY BATTLE_CRY1 ~TO BATTLE!~ 
SAY BATTLE_CRY2 ~Time to die!~ 
SAY BATTLE_CRY3 ~DIE NOW!~ 
SAY BATTLE_CRY4 ~DIE!~ 
SAY DAMAGE ~Ow!~ 
SAY DYING ~AH!~ 
SAY HURT ~Help me!~ 
SAY AREA_FOREST ~We're in a forest.~ 
SAY AREA_CITY ~We're in a city~ 
SAY AREA_DUNGEON ~We're in a dungeon.~ 
SAY AREA_DAY ~It's day.~ 
SAY AREA_NIGHT ~It's dark.~ 
SAY SELECT_COMMON1 ~Yeah?~ 
SAY SELECT_COMMON2 ~What do you need?~ 
SAY SELECT_COMMON3 ~Grunt.~ 
SAY SELECT_COMMON4 ~What?~ 
SAY SELECT_COMMON5 ~Yes?~ 
SAY SELECT_COMMON6 ~I'm listening.~ 
SAY SELECT_ACTION1 ~Uh huh.~ 
SAY SELECT_ACTION2 ~Sure.~ 
SAY SELECT_ACTION3 ~I'm on it.~ 
SAY SELECT_ACTION4 ~YAY!~ 
SAY SELECT_ACTION5 ~Not hard at all~ 
SAY SELECT_ACTION6 ~Yep~ 
SAY SELECT_ACTION7 ~Okay~ 
SAY SELECT_RARE1 ~I'm ready.~ 
SAY SELECT_RARE2 ~I got it.~ 
SAY CRITICAL_HIT ~Yeah!~ 
SAY CRITICAL_MISS ~Damn!~ 
SAY TARGET_IMMUNE ~No effect?~ 
SAY INVENTORY_FULL ~It's too heavy!~ 


// This is compiling John's dialogue 

COMPILE ~John/K#John.d~ 


// This is adding our area file to the game 

EXTEND_TOP ~AR0406.bcs~ ~John/AR0406.baf~ 

// Adds Portraits

COPY ~John/johns.bmp~ ~override/johns.bmp~
	 ~John/johnm.bmp~ ~override/johnm.bmp~


// Add this to the end (Appends .2DA files in the game so that it recognizes your NPC’s files 

APPEND ~pdialog.2da~ 
~K#John K#JohnP K#JohnJ K#JohnD K#Joh25P K#Joh25J K#Joh25D K#John25~ 
UNLESS ~K#John~ 


APPEND ~interdia.2da~ 
~K#John K#JohnB K#JohB25~ 
UNLESS ~K#John~



And that's it! You now have an NPC of your very own in the game! Just save the TP2 and run the install. Make sure you either start a new game or load a saved game where you have not yet visited the Copper Coronet (or the area in which you are spawning your CRE)!

If you have any questions, please PM or email theacefes at bohdi2185@msn.com.

Edited by theacefes, 07 October 2007 - 07:16 PM.

-Ace

My Music Reels (mod-related and others)

----

DO ~SetGlobal("omgBbqRomanceActive","GLOBAL", 2)~



Reply to this topic



  


0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users