View Single Post
Old 01-12-2012, 01:35 PM   #44
Senior Member
JCarter426's Avatar
Join Date: Feb 2008
Location: Look to your left.
Posts: 1,668
Well, recruiting an NPC is pretty simple. Assuming you have your basic talk to NPC and then recruit them, it should go something like this:
void main() {

	object oNPC = GetObjectByTag("NPC_tag", 0);

AddAvailableNPCByObject(iNPC, oNPC);
SetNPCSelectability(iNPC, 1);

I believe you're supposed to keep the NPC tag as the tag of whoever you're replacing. So you'll have to check the original NPC for that. The NPC integers are as follows (you can paste this right into your script if you need it for reference, it won't do anything):
int NPC_BASTILA         = 0;
int NPC_CANDEROUS       = 1;
int NPC_CARTH           = 2;
int NPC_HK_47           = 3;
int NPC_JOLEE           = 4;
int NPC_JUHANI          = 5;
int NPC_MISSION         = 6;
int NPC_T3_M4           = 7;
int NPC_ZAALBAR         = 8;

int NPC_ATTON           = 0;
int NPC_BAO_DUR         = 1;
int NPC_CANDEROUS       = 2;
int NPC_G0T0            = 3;
int NPC_HANDMAIDEN      = 4;
int NPC_HK_47           = 5;
int NPC_KREIA           = 6;
int NPC_MIRA            = 7;
int NPC_T3_M4           = 8;
int NPC_VISAS           = 9;
int NPC_HANHARR          = 10;
int NPC_DISCIPLE        = 11;
You can use either the integer or the name (exactly as it appears) - depending of course on who you're replacing. You also might want to add the following, which will bring up the party selection screen and force the player to pick your new NPC:
ShowPartySelectionGUI("", iNPC, -1);
The "" is the name of a script to fire upon exiting, so put something in there (in the quotes) if you want to fire another script (such as a dialogue). Change the -1 to another NPC integer if you want another forced NPC. But if you're going to do this, you have to make sure the module is set to unescapable, or else fire the following as well:
...which will prevent you from changing party members, no matter what the area. Then once this is over, fire:
...which will let you change party members again. This function only affects a single module for as long as you're in it and is undone if you enter a new module, so if you're dealing with more than one you'll have to trigger it each time you enter a module - I believe this only ever happens in K2, and they do it by setting a global and then having all the modules' OnEnter scripts check that global.

So here's an example with everything, replacing Mission (because I think she's useless but feel free to change it):
void main() {

//Define everything
	object oPC = GetFirstPC();
	object oNPC = GetObjectByTag("mission", 0);

//Recruit the NPC
AddAvailableNPCByObject(iNPC, oNPC);
SetNPCSelectability(iNPC, 1);

//Multiclass to Jedi Sentinel and give items
AddMutliClass(iClass, oPC);
CreateItemOnObject("g_a_jedirobe01", oPC);
CreateItemOnObject("g_w_shortsbr01", oPC);

//Bring up the party selection GUI, force the new NPC, and prevent any further changes
ShowPartySelectionGUI("", iNPC, -1);

Simple, right? But basically, AddAvailableNPC is really the only thing required to add an NPC (no really?) to the party. It's a lot like AddMultiClass; you think because it's such an important feature it must be immensely complicated, when in fact it's one line - although the hard coded stuff that the function calls probably is immensely complicated. Anyway, it's very simple, the rest is just window dressing. But of course you should consult the tutorial here on recruiting... it goes over a lot of things I haven't covered.

JCarter426 is offline   you may: quote & reply,