Executing a script within another script

I can’t seem to get this working, ExecuteScript("playlevelupsound", oPC);
nor does variation of OBJECT_ etc etc. The scripts separately both function as intended.

I want to be able to trigger a small script that plays a short sound once a specific operation is done in another script. For example, the script I’m working with handles player skill leveling, and once they level up, and interface appears notifying the player that they have reached a certain level.

I would also like a specific audio file to play when this occurs, and I currently have that configured to play via ExecuteScript("playlevelupsound", oPC);, except the script won’t fire. I am open to alternative methods, but the “play sound” function wouldn’t work either, so I opted to spawn an object near the Player and have that play the sound then destroy itself. It works when the script is ran from an interface, specifically in this case I have been testing it by making the close button on the level-up notification interface execute the script that plays the sound.

Here is a snippet from the script where I have attempted to make this work

void UpdateCraftLevel(object oPC, int nSKILL, string sPROF, int nTOTXP, int nBASE, int nOVER)


{
	int nNEW = nBASE; //this little bit here just places the level-up notification inside the chat-box.
	
	string sTEXT0 = "Congratulations, you just advanced a " + sPROF + " level.";
	string sTEXT1 =	"Your " + sPROF + " level is now " + IntToString(nNEW) +".";

	if (nOVER == TRUE)
	{
		while (GetSkillXPNeeded(nNEW) > nTOTXP)
		{
			SetBaseSkillRank(oPC, nSKILL, nNEW - 1, FALSE);
			nNEW = nNEW - 1;
		}
	}
	if ((nNEW <= MAX_SKILL_LEVEL)&&(nNEW == nBASE)) //Max Level
	{
		while (GetSkillXPNeeded(nNEW + 1) <= nTOTXP)
		{
			SetBaseSkillRank(oPC, nSKILL, nNEW + 1, FALSE);
			nNEW = nNEW + 1;
		}
	}
	if (nNEW != nBASE)//this is where the level-up notification GUI is triggered
	
	{
		ExecuteScript("playlevelupsound", oPC);	//This is SUPPOSED to trigger the script "playlevelupsound" that plays the 'level-up jingle', but it won't work!
		DisplayGuiScreen(oPC, "LEVELUPBACKGROUND", FALSE, "levelupbackgroundgui.xml");	
		SetGUIObjectText(oPC, "LEVELUPBACKGROUND", "LEVELUP_TEXT0", -1, sTEXT0);
		SetGUIObjectText(oPC, "LEVELUPBACKGROUND", "LEVELUP_TEXT1", -1, sTEXT1);
		SetGUITexture(oPC, "LEVELUPBACKGROUND", "SKILL_ICON", "levelupbackground.tga");	
	}
	switch (nSKILL)//each skill has a case, this is done so that each skill can have its own graphics appear on the level-up notification GUI
		{	
		case SKILL_THIEVING: SetGUITexture(oPC, "LEVELUPBACKGROUND", "SKILL_ICON", "thievinglvlup.tga"); break; //Thieving Skill
		case SKILL_WOODCUTTING: SetGUITexture(oPC, "LEVELUPBACKGROUND", "SKILL_ICON", "woodcuttinglvlup.tga"); break;//Woodcuting Skill
		}
	
}

This script is by @travus and I’ve used it several times. It works great. Maybe try that as your script to execute?

// Creates an iPoint at the location of the currently controlled character.
// A sound file is then played off of that iPoint before destroying it. 

void main()
{
	object oPC = GetFirstPC(FALSE);
	object oIP = CreateObject(OBJECT_TYPE_PLACEABLE, "plc_ipoint ", GetLocation(oPC));
								//	do not remove this space	^ 	
	string sWave = "0_archery_warning_0000";	// <--- sound file name

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

Unfortunately, adding this to my script doesn’t play the sound. I know this works, it’s just not the fix for my issue. Thanks for your time.

Ok, I read your first post again and it seems you had already tried this. I’m not sure I understand though when your script works and when it doesn’t…

If I understand you correctly everything works when running the script from an interface, but not when running this script (like the one I posted) when run from another script? That I find very odd since I have had it working for me when running the function I posted inside another script…Makes me wonder how this first script is triggered…From what I can deduce you want it to trigger when the player is levelling up?

Does the whole thing with

work? It’s just the sound that’s not playing for you?

Ah, well, maybe someone else can help you.