Jump to content
Gamer-3ac24a5e7f4beb96

How to Play a random sound from a list

Recommended Posts

I have my sounds set up in the Sounds folder inside the mission folder. I have my sounds configured in my description.ext file. How do I call one sound from the list at random when a trigger is activated?

Share this post


Link to post
Share on other sites

If you have for example 6 sounds, then write 6 scripts. Each script plays one of the sounds

 

Your scripts might be named:

sound0

sound1

sound2

sound3

sound4

sound5

 

Then you write a 7th script that selects a script at random.  (I have been meaning to ask over here how to do that. I saw a script years ago but did not keep a record).

 

 

.

 

 

 

 

 

 

 

Share this post


Link to post
Share on other sites

In trigger activation:

[] spawn "Your_sound_script.sqf";

Then make Your_sound_script.sqf in your mission folder & put in it:

_sound = selectRandom 
  [
    "sound_1", // As defined by you in Description.ext
    "sound_2",
    "sound_3"
  ];

playSound _sound;

 

  • Like 2

Share this post


Link to post
Share on other sites

Thanks Sergeant! When I put [] spawn "Your_sound_script.sqf"; with my sqf name into a trigger i get the error "On activation spawn type string expected code". I have the sqf file in the mission folder. Any ideas?

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×