Jump to content
Sign in to follow this  
drift501

Select from a random choice

Recommended Posts

Hello. I am wanting to create a radio script to be played by a helicopter in my mission. I have defined all my music that I want the helicopter to play in the description.ext using cfgSounds and I can make the helicopter play them by using rh say3d "sound" but I was wondering if I could create a script that will select a song at random, play it and once it's done play another song.

Share this post


Link to post
Share on other sites

If you place the BIS Functions Module, you can then use:

[["song1", "song2", "song3", "song4"], 2] spawn BIS_fnc_music;

Where the first parameter is the songs, and the second is the delay between songs :)

Share this post


Link to post
Share on other sites

Thanks, this is not what I wanted but I can put this to good effect in my mission anyway. Is it possible to have a code like this. (when I say this I mean can someone edit it to work)

selectRandom [goto #s1, goto #s2, goto #s3]

#s1
rh say3d "s1;
selectRandom [goto #s2, goto #s3]

#s2
rh say3d "s2"
selectRandom [goto #s1, goto #s3]

#s3
rh say3d "s1"
selectRandom [goto #s1, goto #s2]

Is there a code like this I can use with s1, s2 and s3 being my songs, defined as sound so I can use say3d, and rh being the helicopter I want to play the music.

Share this post


Link to post
Share on other sites

Try this:

private ["_randSong"];
waituntil {!isnil "bis_fnc_init"};
while {true} do {
if ((alive heloName) && (vehicle player != player)) then {
_randSong = ["song1", "song2", "song3"] call BIS_fnc_selectRandom;
heloName say3D _randSong;

switch (_randSong) do {
case "song1" : {sleep 180;};
case "song2" : {sleep 210;};
case "song3" : {sleep 250;};
};
};
};

It selects a random song and then sets the correct sleep before playing the next one. Untested but hope it works. You need a functions module on the map.

Alternative is the jukebox module which is whats already been suggested - Jukebox

Tip: if you are calling a BIS_fnc and have the functions module always put this at the top of the script so it doesn't run before module initialises:

waituntil {!isnil "bis_fnc_init"};

Share this post


Link to post
Share on other sites

Ninja'd by Pelham :)

Should do the same thing...just written differently. Not tested.

_playmusic = {
_song = [];	//might not need this?
_songs = [["s1",310],["s2",316],["s3",256]];
_song = _songs select floor (random (count _songs));
_name = _song select 0;
_time = _song select 1;
rh say3D _name;
sleep _time;
nul = [] spawn _playmusic;
};

EDIT: Problem is... it is possible for the same song to play over and over..... and sleep 310 might not be 310 seconds. Just depends on the game engine load.

Edited by twirly

Share this post


Link to post
Share on other sites

Ok. Thanks guys, I will try both of these when I can get onto the computer.

Share this post


Link to post
Share on other sites

I found a function on the Biki that calls from a random selection so would this code work.

goto = ["s1", "s2", "s3"] call BIS_fnc_selectRandom;

#s1
rh play3d "s1"
goto = ["s2", "s3"] call BIS_fnc_selectRandom;

#s2
rh say3d "s2"
goto = ["s1", "s3"] call BIS_fnc_selectRandom;

#s3
rh say3d "s3"
goto = ["s1", "s2"] call BIS_fnc_selectRandom;

Would this script work or not?

Share this post


Link to post
Share on other sites

SQS is old and not used anymore... but if you insist... why don't you try it?

Add -showscipterrors to your Arma 2 shortcut and also you can look in your .rpt file for the errors. This is where you start. You'll find out if it works or not.

It would pay bigtime to do a lot of searching and reading in the forums!

---------- Post added at 02:19 PM ---------- Previous post was at 12:45 PM ----------

Here mate....see if you can wrap your head around this.

It should (not tested!) play music until you set MyPlaySongsGlobalVariable to false.

It also shouldn't play the same song twice in a row.

_songs = [["s1",310],["s2",316],["s3",256]];

_oldname = "";

MyPlaySongsGlobalVariable = true;

while {MyPlaySongsGlobalVariable} do {

_song = _songs floor (random (count _songs);

_name = _song select 0;
_time = _song select 1;

if (_oldname != _name) then {

	rh say3D _name;
	_oldname = _name;
	sleep _time;

};

sleep 0.01;
};

Edited by twirly
Added stuff

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
Sign in to follow this  

×