I wanted a kind of randomization of a sound in a script. I thought I knew how to do it, but apperently it doesn’t work like I thought. Here’s my custom function in my script (based on an original script by @travus):
void GaspSound()
{
object oDoor = GetObjectByTag("arenastone");
object oIP = CreateObject(OBJECT_TYPE_PLACEABLE, "plc_ipoint ", GetLocation(oDoor));
// do not remove this space ^
string sWave = "gasp1"; // <--- sound file name
string sWave2 = "gasp2";
string sWave3 = "gasp3";
string sWave4 = "gasp4";
string sSound;
int rndm = Random(40);
if (rndm <= 10) sWave = sSound;
else if (rndm <= 20) sWave2 = sSound;
else if (rndm <= 30) sWave3 = sSound;
else if (rndm <= 40) sWave4 = sSound;
DelayCommand(0.2f, AssignCommand(oIP, PlaySound(sSound, TRUE)));
SetPlotFlag(oIP, FALSE);
DestroyObject(oIP, 1.5f);
}