SoundObject & Area Transistion

I’m having trouble getting a sound object to play. I would like it to play using the OnEnter event for the area when the PC transitions. It plays in the toolset but won’t play when I code it.

code: // not much to it…

void main()

object oPC = GetEnteringObject();
if (!GetIsPC(oPC)) return;


I’ve tried it with an appropriate delay as well with no luck. Can anyone think of why this wouldn’t work?

Thanks… :wink:

In NWN2 it’s tricky to play a sound right away for some reason. Maybe it’s the same thing with NWN1 and NWNEE. In any case, I have a script made by @travus which works really well. I think this should work with NWN1 too. You need the tag of an object that’s in the same as where you want the sound to be played. Here’s the script:

void main()
	object oPC = GetEnteringObject();
    if (!GetIsPC(oPC)) return;
	object oObjectInArea = GetObjectByTag("TagOfObject");

	object oIP = CreateObject(OBJECT_TYPE_PLACEABLE, "plc_ipoint ", GetLocation(oObjectInArea));
								//	do not remove this space	^ 	
	string sWave = "gui_flutesong02";	// <--- sound file name

	DelayCommand(0.2f, AssignCommand(oIP, PlaySound(sWave, TRUE)));	
	SetPlotFlag(oIP, FALSE);
	DestroyObject(oIP, 0.3f);	


EDIT: Actually, maybe you could even use the oPC as the oObjectInArea come to think of it.


Is this for NWN1 or NWN2?

There are a couple of things you could try …

  1. First, make sure the sound object is correctly setup to play by having a simple lever object trigger the sound object. i.e. Test the sound plays as you think it should using a different hook event other than the area On Enter. It’s important to establish you have the sound object setup correctly: Single_Shot_Global

  2. If this is NWN2, then using the area’s On Client Enter script hook is more reliable to use.

  3. Alternatively, fire the script like andgalf suggests, using a direct sound file play command: PlaySound, making sure you use you use the TRUE parameter.

  4. Have the sound event object played from entering a trigger (upon arrival) instead. i.e. The trigger event is fired after the PC arrives at the area where they enter a trigger.

  5. Also note that the function GetNearestObjectByTag, may require the parameter to replace OBJECT_SELF to help find the sound object in question. i.e. It may be that it simply needs to be …

SoundObjectPlay(GetNearestObjectByTag("SUGAR_BOOM", oPC));

@Nizidramaniit can you clarify whether this is NWN1 or NWN2?

I can move the thread to the correct category to prevent confusion.



This. GetNearestObjectByTag will fail if the second parameter is area. Since OP didn’t specify the parameter, then OBJECT_SELF was used and OBJECT_SELF is area type of object since the script has been running in area’s OnEnter event.

Generally speaking, when something doesn’t work the way you expect, add debugging to figure out why and how to fix it. Script debugging tutorial | The Neverwinter Vault

1 Like

NWN1. Proleric
I’ve got it working with the right delay now.
DelayCommand(4.0, SoundObjectPlay(GetNearestObjectByTag(“SUGAR_BOOM”, oPC)));

1 Like

So you did need the oPC.

No need for oPC.

Odd since you added the oPC argument :slight_smile:

yeah. that’s not right. :wink: It should read: DelayCommand(4.0, SoundObjectPlay(GetNearestObjectByTag(“SUGAR_BOOM”)));

With my scripter hat on, I don’t understand how that works, if, as @Shadooow said, OBJECT_SELF is still the area.

Even using oPC, GetNearestObjectByTag() doesn’t quite do what you might expect if we are in the area OnEnter event. At that time, strangely, the PC location is (0 0 0), not the point at which the PC enters the area moments later.


That is not consistent with my testing. Both spawned NPC and player moving areas have valid location at the time of area’s OnEnter module fires. And thus GetNearest* functions works if you pass such creature into parameter. (The reason why the debug message returns 7f00000 when Guard enters area is because I was looking for nearest placeable and there aren’t any in dungeon where the Guard just spawned)

1 Like

Hm… you’re right.

I must be mistaken.

1 Like