How to prevent playsound when in certain conversation

I’m trying to prevent NPC “barking” from playing when the player is in a conversation with said NPC.
I tried using isinConversation but i get errors and i can’t find any documentation about the expression being used.

void main()
{
    ExecuteScript("nw_c2_default1", OBJECT_SELF);
    if(IsInConversation)PlaySound("");
    int rand=Random(3);  //Random number from 0 to 2
    //if(rand==0)PlaySound("vs_nils_bark001");
    else if(rand==1)PlaySound("vs_nils_bark002");
    else if(rand==2)PlaySound("vs_nils_bark003");
}

You have to comment out the whole if statement, including the else ifs. You can’t start a valid statement with else.

@crowbardoctor Maybe something like this perhaps?

void main()
{

	object oNPC = OBJECT_SELF;

	int rand = Random(3);

	if(!IsInConversation(oNPC))
	{
	
		if(rand==0)
		{
		   PlaySound("vs_nils_bark001");
		}
		else if(rand==1)
		{
		   PlaySound("vs_nils_bark002");
		}
		else if(rand==2)
		{
		   PlaySound("vs_nils_bark003”");
		}
		
	}
	

}

EDIT: Hmm, come to think about it, this might not prevent the bark sound from playing after all…I don’t know how these things work in NWN1, but my guess is you put this script on the OnConversation of the NPC?

EDIT2: As this script hurt @kevL_s ’ eyes, I have edited it to his liking and removed the last else if statement as that was redundant.

1 Like

This seems to work. Thank you very much :smiley:

1 Like

@andgalf my eyes!

void main()
{
	if (!IsInConversation(OBJECT_SELF))
	{
		int rand = Random(3);

		if(rand==0)
		{
			PlaySound("vs_nils_bark001");
		}
		else if(rand==1)
		{
			PlaySound("vs_nils_bark002");
		}
		else //if(rand==2)
		{
			PlaySound("vs_nils_bark003”");
		}
	}
}

Even shorter (but unfortunately less flexible, since the sounds will need to have similar names):

void main(int nMax=3)
{
	if (!IsInConversation(OBJECT_SELF))
	{
		int rand = Random(nMax)+1; // value between 1 and nMax
		string sFile = "vs_nils_bark0" + GetStringRight("00"+IntToString(rand),2); // sFile will be "vs_nils-bark0" followed by a number between "01" and "99" (so nMax is limited to 99)
		PlaySound(sFile);
	}
}
1 Like

@47 I wanted to keep it as similar as possible to Ag’s original, to point to 2 things

- the 2nd call to IsInConversation() and its return statement are redundant
- don’t define rand until and unless it’s needed

i mean …

void main()
{
	if (!IsInConversation(OBJECT_SELF))
		PlaySound("vs_nils_bark00" + IntToString(Random(3) + 1));
}

@kevL_s - I asked my brother what hurt your eyes so much with my script, as I was confused by that, and now I understand. He understood your reaction completely (he’s programmer too and has taught me a great deal about the fundamentals of programming/scripting (together with everyone here on the vault), even if it has taken a few years to get it through my thick head).

Yes, I didn’t have this in my original attempt, but I got insecure about how this script was called, so I put that in there just in case…but I know it’s not really needed.

I’m glad my simple script worked still, and that I could help a fellow neverwinternighter out.

2 Likes