View Single Post
Old 01-12-2012, 04:38 PM   #47
Senior Member
JCarter426's Avatar
Join Date: Feb 2008
Location: Look to your left.
Posts: 1,668
Originally Posted by DarthJango/Weasley View Post
THANKS SOOO MUCh! Im sure many people will find this helpful, i get it. Your a true master JC
Originally Posted by Qui-Gon Glenn View Post
Great post JCarter426!!

At first reading, I was wishing there were a link to a tutorial somewhere... then realized I was reading one! Nicely done
No problemo and thanks. As I said it's not that complicated... and I've been messing around with this stuff for a while.

Originally Posted by DarthJango/Weasley View Post
Will this still work if I have 2 seperate scripts, 1 to recruit and 1 to change the class, for instance Atton, who you add but can only have as a defferent class at a later date?
Not sure what you mean exactly... if you want to split it up into separate scripts, yes, just duplicate it and remove what isn't necessary from each part. For example:
void main() {

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

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

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

void main() {

//Define everything
	object oPC = GetFirstPC();

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

But you can't change an NPC's class... as I mentioned earlier. If you mean the multiclass to Sentinel... what you posted (and I recreated) multiclasses the player, not Atton or anyone else, so you'd have to change the object for that. I think I'm just misunderstanding you though.

Also, I forgot to mention, with any recruitment you should remove the NPC you're replacing if they're already in the party - RemoveAvailableNPC(iNPC) - and remove the possibility of recruiting them if they're not.
Originally Posted by Qui-Gon Glenn View Post
Where does the value NPC_INTEGER come from? It probably is an integer constant from nwscript, so I am wondering what object it is being obtained from, and how... I would think it would need to be something along the lines of
int iNPC = GetSomeInfoFromObject(oNPC); This function compiles for me all the time ;)
I believe that what you posted is correct, so really I am asking for further enlightenment
Yes, lifted from nwscript.nss. Basically the number is just the slot they occupy; the names that are defined are just added for the developers' sake - I usually just use the numbers, since I've memorized them. There are 10 slots in K1, 13 in K2 (plus 3 puppet slots). As far as I know they're just slots, space for storing information, nothing else. (Side note: it is possible to add an NPC to a slot that isn't defined, but it's severely broken because the game doesn't store any information for it. I managed to have a non-existent NPC in my party, taking up space and preventing me from adding another, despite not existing.)

There's no function for the NPC integer, though - either to get an NPC's integer, or to get the object that's assigned to an integer. I guess no one ever needed it. You can, however, spawn the object that is stored in a specified slot. For my own purposes I wrote some subroutines (for K2) to rip the integer from an object, or to generate an object based on an integer (well, expected object- it's not perfect because other NPCs can and do occupy party member slots... Trask as Bastila, B-4D4 and the Remote as Bao-Dur, recruitment mods, etc):
//Gets the NPC integer of an object
int ObjectToNPC(object oObject) {

string sTag = GetTag(oObject);
	if( sTag == "atton" ) return 0;
	else if( sTag == "baodur" ) return 1;
	else if( sTag == "mand" ) return 2;
	else if( sTag == "G0T0" ) return 3;
	else if( sTag == "handmaiden" ) return 4;
	else if( sTag == "HK47" ) return 5;
	else if( sTag == "kreia" ) return 6;
	else if( sTag == "mira" ) return 7;
	else if( sTag == "T3M4" ) return 8;
	else if( sTag == "visasmarr" ) return 9;
	else if( sTag == "hanharr" ) return 10;
	else if( sTag == "disciple" ) return 11;
	else return -1;


//Gets the expected tag of an object using its NPC integer
string NPCToTag(int iNPC) {

string sTag;
	if( iNPC == 0 ) return "atton";
	else if( iNPC == 1 ) return "baodur";
	else if( iNPC == 2 ) return "mand";
	else if( iNPC == 3 ) return "G0T0";
	else if( iNPC == 4 ) return "handmaiden";
	else if( iNPC == 5 ) return "HK47";
	else if( iNPC == 6 ) return "kreia";
	else if( iNPC == 7 ) return "mira";
	else if( iNPC == 8 ) return "T3M4";
	else if( iNPC == 9 ) return "visasmarr";
	else if( iNPC == 10 ) return "hanharr";
	else if( iNPC == 11 ) return "disciple";
	else return "";


//Gets an object from an NPC integer
object NPCToObject(int iNPC){

return GetObjectByTag(NPCToTag(iNPC), 0);

I used these for a script that switches the active PC to a party member. I needed to get the integer of the current PC and store it, check if who I'm turning into is available, make sure the two aren't the same, remove who I'm switching to from the party if present so the game doesn't CRASH, add the other party members back into the party (with the integer), and various other things - and give different error messages depending on the situation. Took me days to sort out all the possibilities.

Last edited by JCarter426; 01-12-2012 at 04:43 PM.
JCarter426 is offline   you may: quote & reply,