Hello people, how are you this fine evening (local time for me.)
I’m trying to stop the background music of an area if and when the PC opens a chest?
Having issues getting anything to work.
Code so far:
void main()
{
object oPC = GetLastUsedBy();
if (!GetIsPC(oPC)) return;
if ( GetLocalInt(oPC, "DO_ONCE__" + GetTag(OBJECT_SELF)) )
return;
SetLocalInt(oPC, "DO_ONCE__" + GetTag(OBJECT_SELF), TRUE);
if ( MusicBackgroundGetDayTrack(GetArea(OBJECT_SELF)) )
{
MusicBackgroundStop(GetArea(OBJECT_SELF));
}
object oSound = GetObjectByTag("EGYPT_HINT");
SoundObjectSetPosition(oSound, GetPosition(oPC));
SoundObjectSetVolume(oSound, 127);
DelayCommand(0.5, SoundObjectPlay(oSound));
}
I’m probably missing something, but I don’t see a glaring error.
This is the chest OnUsed script, right?
If nothing at all is happening, worth checking it’s firing for the right event (using SendMessageToPC() or whatever).
Checking MusicBackgroundGetDayTrack() is redundant (if no music is playing, MusicBackgroundStop() will do nothing, so it can be called unconditionally) though this shouldn’t be a problem.
If all else fails, try using AssignCommand(GetModule(), …) to instruct the module to perform all the sound commands. Commands issued directly by placeables have lowish priority and can fail if the module is very busy.
1 Like
Yeah, it was for the OnUsed() event.
I ended up putting it into a sound object so I can then call SoundObjectStop(). Works fine now.
void main()
{
object oPC = GetLastUsedBy();
if (!GetIsPC(oPC)) return;
if ( GetLocalInt(oPC, "DO_ONCE__" + GetTag(OBJECT_SELF)) )
return;
SetLocalInt(oPC, "DO_ONCE__" + GetTag(OBJECT_SELF), TRUE);
AssignCommand(GetModule(), MusicBackgroundStop(GetArea(OBJECT_SELF)));
SoundObjectStop(GetObjectByTag("EGYPT_CHOIR"));
object oSound = GetObjectByTag("EGYPT_HINT");
SoundObjectSetPosition(oSound, GetPosition(oPC));
SoundObjectSetVolume(oSound, 127);
DelayCommand(0.5, SoundObjectPlay(oSound));
}