Jump to content
mariuswww

Random sound

Recommended Posts

I would like to make the BMA script (AFA script) play a random sound file (from a list of "Const char" ) when the BMA is triggered. How would I go about doing that?

 

For now its like this

 

 

if (Audio == 0)

Audio::PlaySample(PfadAudio);
 
if (Audio3D == 0)
{
int x;
x = Audio::PlaySample3D(PfadAudio3D, go->GetPosition());
}

My question is basicly what do I put to make it select a random sound of the Const char list?

Link to comment
Share on other sites

if (Audio == 0)

{

    int random = Math::rand()%5;

    if (random == 0)

        Audio::PlaySample(Sound1);

    else if (random == 1)

        Audio::PlaySample(Sound2);

    else if (random == 2)

        Audio::PlaySample(Sound3);

    else if (random == 3)

        Audio::PlaySample(Sound4);

    else

        Audio::PlaySample(Sound5);

}

if (Audio3D == 0)

{

    int x;

    int random = Math::rand()%5;

    if (random == 0)

        x = Audio::PlaySample3D(Sound3D1, box->GetPosition(), true);

    else if (random == 1)

        x = Audio::PlaySample3D(Sound3D2, box->GetPosition(), true);

    else if (random == 2)

        x = Audio::PlaySample3D(Sound3D3, box->GetPosition(), true);

    else if (random == 3)

        x = Audio::PlaySample3D(Sound3D4, box->GetPosition(), true);

    else

        x = Audio::PlaySample3D(Sound3D5, box->GetPosition(), true);

    box->SetUserData(x);

}

Link to comment
Share on other sites

if (Audio == 0){    int random = Math::rand()%5;    if (random == 0)        Audio::PlaySample(Sound1);    else if (random == 1)        Audio::PlaySample(Sound2);    else if (random == 2)        Audio::PlaySample(Sound3);    else if (random == 3)        Audio::PlaySample(Sound4);    else        Audio::PlaySample(Sound5);}if (Audio3D == 0){    int x;    int random = Math::rand()%5;    if (random == 0)        x = Audio::PlaySample3D(Sound3D1, box->GetPosition(), true);    else if (random == 1)        x = Audio::PlaySample3D(Sound3D2, box->GetPosition(), true);    else if (random == 2)        x = Audio::PlaySample3D(Sound3D3, box->GetPosition(), true);    else if (random == 3)        x = Audio::PlaySample3D(Sound3D4, box->GetPosition(), true);    else        x = Audio::PlaySample3D(Sound3D5, box->GetPosition(), true);    box->SetUserData(x);}

Wow fast reply! Thank you very much, I cant test right now but ill try asap when I get home :)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...