Play server-wide sound?

hi,

I have an event that gets triggered and i’d like to send a server wide sound to all players at the same time.

What would be the best way to do this?

Make each PC play the sound.

void main()
{
    object oPC = GetFirstPC();

    while(GetIsObjectValid(oPC))
    {
        AssignCommand(oPC, ClearAllActions());
        AssignCommand(oPC, PlaySound("al_an_chickens1"));
        oPC = GetNextPC();
    }
}

This makes sure that the sound travels with them. The drawback is that everybody will be forced to stop (PlaySound works via action queue).

Alternatively spawn an invisible placeable next to each player, make that placeable play the sound, then destroy it:

void SendSoundToAllPCs(string sSound, float fDelay=0.25)
{
    object oPC = GetFirstPC();
    object oPlc;

    while(GetIsObjectValid(oPC))
    {
        oPlc = CreateObject(OBJECT_TYPE_PLACEABLE,
            "your_plc_resref", GetLocation(oPC));
        DelayCommand(fDelay, AssignCommand(oPlc, PlaySound(sSound)));
        DestroyObject(oPlc, 6.0);
        oPC = GetNextPC();
    }
}

void main()
{
    SendSoundToAllPCs("al_an_chickens1");
}
  • your plc must not be static
  • you need a short delay to allow the placeable to settle in the area
1 Like

went with the 2nd approach, works great!

thanks again!