I don't know how to script this

So, I have a situation that I haven’t been able to solve with my script. You enter a trigger with the party, and a conversation is supposed to start. However, as it is now, nothing happens. Thing is, I don’t know what companions the player will have in the party at this time, so I want to scroll through the companions and just take one of them to be the one owning the conversation. I thought I had come up with a good idea of how to solve this, but it turns out it’s not working. Here’s my attempt:

int YouHaveShovels()
{

	object oPC1 = GetFirstPC();
	object oFM = GetFirstFactionMember(oPC1, FALSE);
	
	int bShovels = FALSE;
	while(GetIsObjectValid(oFM))
	{
		if (GetIsObjectValid(GetItemPossessedBy(oFM,"shovelit")))
		{
			bShovels = TRUE;
		}	
		oFM = GetNextFactionMember(oPC1, FALSE);
	}
	
	return bShovels;

}


void main()
{

object oPC = GetEnteringObject();
object oPC1 = GetFirstPC();

if(!GetIsPC(oPC)) return;

if(GetJournalEntry("q_treasure",oPC)<1) return;

if(!YouHaveShovels()) return;

SetCutsceneMode(oPC1);

object oCompanion = GetFirstFactionMember(oPC1,FALSE);

	while(GetIsObjectValid(oCompanion) && !GetLocalInt(OBJECT_SELF,"FoundCompanion"))
	{
	
		if(oPC1 == oCompanion)
		{
		
		oCompanion = GetNextFactionMember(oPC1);
		
		}

		else
		{
		
		SetLocalInt(OBJECT_SELF,"FoundCompanion",1);
		AssignCommand(oCompanion, ActionStartConversation(oPC, "c_i1_treasuredig", FALSE, FALSE, TRUE, FALSE));
		
		}
		
	}



}

So, how do you script this to make it work? Thanks for your time!

Yes! I got it working:

#include "ginc_companion"

int YouHaveShovels()
{

	object oPC1 = GetFirstPC();
	object oFM = GetFirstFactionMember(oPC1, FALSE);
	
	int bShovels = FALSE;
	while(GetIsObjectValid(oFM))
	{
		if (GetIsObjectValid(GetItemPossessedBy(oFM,"shovelit")))
		{
			bShovels = TRUE;
		}	
		oFM = GetNextFactionMember(oPC1, FALSE);
	}
	
	return bShovels;

}


void main()
{

object oPC = GetEnteringObject();
object oPC1 = GetFirstPC();

if(!GetIsPC(oPC)) return;

if(GetJournalEntry("q_treasure",oPC)<1) return;

if(!YouHaveShovels()) return;

SetCutsceneMode(oPC1);

string sCompanion = GetFirstRosterMember();


	while(!GetIsRosterNameInParty(oPC1,sCompanion))
	{
		
		sCompanion = GetNextRosterMember();
		
	}
	
object oFM = GetFirstFactionMember(oPC1, FALSE);	
		
	while(GetIsObjectValid(oFM))
	{
	
		AssignCommand(oFM, ClearAllActions());
		AssignCommand(oFM, ActionJumpToObject(oPC1));
		
		oFM = GetNextFactionMember(oPC1, FALSE);
	}	
	
	
object oCompanion = GetObjectByTag(sCompanion);
DelayCommand(0.3, AssignCommand(oCompanion, ActionStartConversation(oPC1, "c_i1_treasuredig", FALSE, FALSE, TRUE, FALSE)));




}
1 Like

note you can optimize this by returning TRUE on the first shovel found

int YouHaveShovels()
{
	object oPC1 = GetFirstPC();
	object oFM = GetFirstFactionMember(oPC1, FALSE);
	
	while(GetIsObjectValid(oFM))
	{
		if (GetIsObjectValid(GetItemPossessedBy(oFM,"shovelit")))
			return TRUE;

		oFM = GetNextFactionMember(oPC1, FALSE);
	}
	return FALSE;
}
2 Likes