Check how many party members through script

Is there an easy way to check how many companions are currently in the party of the PC through a script?

I would like a way to check if for some reason the player has decided to go alone to a place where I need there to be at least one companion in the party otherwise there will be bugs.

I think I might be able to put together something convoluted to check this, but if there was a pretty easy way I’d like to know.

EDIT: Could it be this simple:

void main()
{

object oPC1 = GetFirstPC();

object oFM = GetFirstFactionMember(oPC1,FALSE);

if(!GetIsObjectValid(oFM))
	SendMessageToPC(oPC1,"By not having any companions in your party have created a bug. Please reload.");	
	return;
}

EDIT2: Apparently not.

I solved it in another way. It would still be interesting to know though.

Everything hard coded on this matter is just for “show”. Which mean you have to do your own functions on that subject. Luckily NWN2 scripting has everything needed for it.

//function that return the number of party number

int partySize(){
	
       int size =1;		
       object oFM =  GetFirstFactionMember(GetFirstPC(TRUE), FALSE);
        while( GetIsObjectValid(oFM) )
	
        {
  			if(GetIsRosterMember(oFM)){
				size = size+1;	 
			}
	
            oFM = GetNextFactionMember(GetFirstPC(TRUE), FALSE);
        }

//	SendMessageToPC(GetFirstPC(FALSE),"party size = " + IntToString(size));
	return size;

	
}

This is what I made and use mostly on those subject. It return the size of the main player party without counting the summons or “henchmen” since I have almost none in my project, only full party member.

Depending of what you want to check you need to alter the filter on the condition, you can check for summon, henchmen as well if you wish, here I count only roster members. If it returns “1” then it means I have only the main character.

The “creature” associated with the player or in his/her party are all put in the “player faction”, when removed from the party they return to their original faction.

1 Like

@andgalf

My homebrew function …

///////////////////////////////////////////////////////////////////////////////////////////////////
// This function returns the number of PCs in the party regardless of their current state.
// Counts players main PCs, Created PCs and Companions. (Basically all roster PCs and owned PCs.)
// DOES NOT COUNT SUMMONED . If ExcludeDead == 1, then dead party members are not included in count.
// Used to make sure players do not go above party size. (Althea campaign maximum party size is 6.)
// ADDED FULL PARTY COUNT OPTION THAT INCLUDES ASSOCIATES
///////////////////////////////////////////////////////////////////////////////////////////////////
int PartyNumber(object oPlayer, int ExcludeDead = 0, int IncludeAll = 0); 
int PartyNumber(object oPlayer, int ExcludeDead = 0, int IncludeAll = 0)
{
	int iNumber = 0;
	object oFM = GetFirstFactionMember(oPlayer, FALSE);
	
	while(oFM != OBJECT_INVALID)
	{
		if(IncludeAll == 1){iNumber = iNumber + 1;}
		else if(GetAssociateType(oFM) == 0 && (ExcludeDead == 0 || !GetIsDead(oFM))){iNumber = iNumber + 1;}
		
		oFM = GetNextFactionMember(oPlayer, FALSE);	
	}
	
	return iNumber;

}
2 Likes

Thanks for the replies! I could probably use either of those, so I consider both of these the Solution to this thread.

1 Like

Here is the script I used for checking if alone.

// gc_bb_alone
// by Brendan Bellina
// Feb 2008

// Returns TRUE if the PC is traveling alone, else returns FALSE

int StartingConditional()
{
int partyCount = 0;
object oPC = GetFirstPC();
object oPartyMember = GetFirstFactionMember(oPC, FALSE);

while(GetIsObjectValid(oPartyMember) == TRUE && partyCount < 2)
{
	partyCount++;
	oPartyMember = GetNextFactionMember(oPC, FALSE);
}

return (partyCount == 1);

}

1 Like