Jump to content
cc_kronus

Help with script syntax / Radio transmision for all radios

Recommended Posts

Hi, 

 

With my very limited knowledge of programming  (I am a copy-paster)  I am trying to simulate a  random radio broadcast to some radios placed in the scenario, but all radios must emit the same track.

 

This is the code I am using in radios.sqf.   The sountracks have already been defined in description.ext , and individually played, on a single radio  as in  -   this say3d [ "voicetrack1" , 15,1]  -  they run OK.  Now, I want all the radios. to play at the same time  the same random track selected by the random function.

 

_antena is an antena placed in the scenario. If destroyed, the transmissions end.

_radios is the array of the devices I want to play the sound files, (the vanilla small black transistors) 

 

if !(isServer) exitWith {}; 

_antena = _this select 0; 
_radios = ["radio_1","radio_2","radio_3","radio_4","radio_5"]; 
_random = 3; 

while {alive _antena} do   
 {
   _randomResult = floor(random _random);
   sleep 15;
   switch (_randomResult) do
   {
	case 0: {_radios say3D ["voicetrack1",15,1]; sleep 182;};
	case 1: {_radios say3D ["voicetrack2",15,1]; sleep 197;};
	case 2: {_radios say3D ["voicetrack3",15,1];sleep 171;};
	
 };
 };

The problem is that an error pops up and keeps telling me that it has found 5 elements (presumibly the radios) when only 2 where expected.  

 

I am totally lost and I have no idea on how to solve this issue.

 

I would appreciate some help. 

 

 

Share this post


Link to post
Share on other sites

The error is about say3D which needs one object only but you are passing an array of objects.
Just use a forEach loop to go through the array.

Your random technique is not good. Put all sounds in an array and use selectRandom to select one of the sounds randomly

sent from mobile using Tapatalk
 

 

EDIT:

 

untested solution using forEach and selectRandom:

if !(isServer) exitWith {}; 

params ["_antena"];
_radios = [radio_1, radio_2, radio_3, radio_4, radio_5];
_soundsSpecs = [["voicetrack1", 182], ["voicetrack2", 197], ["voicetrack3", 171]];

while {alive _antena} do   
{
 _randomSoundSpecs = selectRandom _soundsSpecs;
 _randomSoundSpecs params ["_randomSound", "_delay"];
 sleep 15;
 
 {
  _x say3D [_randomSound,15,1]; 
 } forEach _radios;
 sleep _delay;
};

 

Edited by sarogahtyp
  • Like 1

Share this post


Link to post
Share on other sites
5 hours ago, cc_kronus said:

Hi, 

 

With my very limited knowledge of programming  (I am a copy-paster)  I am trying to simulate a  random radio broadcast to some radios placed in the scenario, but all radios must emit the same track.

 

This is the code I am using in radios.sqf.   The sountracks have already been defined in description.ext , and individually played, on a single radio  as in  -   this say3d [ "voicetrack1" , 15,1]  -  they run OK.  Now, I want all the radios. to play at the same time  the same random track selected by the random function.

 

_antena is an antena placed in the scenario. If destroyed, the transmissions end.

_radios is the array of the devices I want to play the sound files, (the vanilla small black transistors) 

 


if !(isServer) exitWith {}; 

_antena = _this select 0; 
_radios = ["radio_1","radio_2","radio_3","radio_4","radio_5"]; 
_random = 3; 

while {alive _antena} do   
 {
   _randomResult = floor(random _random);
   sleep 15;
   switch (_randomResult) do
   {
	case 0: {_radios say3D ["voicetrack1",15,1]; sleep 182;};
	case 1: {_radios say3D ["voicetrack2",15,1]; sleep 197;};
	case 2: {_radios say3D ["voicetrack3",15,1];sleep 171;};
	
 };
 };

The problem is that an error pops up and keeps telling me that it has found 5 elements (presumibly the radios) when only 2 where expected.  

 

I am totally lost and I have no idea on how to solve this issue.

 

I would appreciate some help. 

 

 

 

Why it won't work:

Your _radios array contains strings, not objects.

You are using the _radios array in front of say3D which only accepts objects, not arrays (at least not arrays of multiple sound origins, rather from/to objects).

The usage of the distance parameter in say3D is questionable at most. If you play with this value a bit you will notice that the sound is barely audible at the given distance parameter, so make it at least twice as high as you think it needs to be. Setting this to 200 usually works fine for making it audible within 50m, also depending on the actual volume of the sound file.

Say3D is local to the machine it was executed on, in your case only the server will play the sound. You need remoteExec for that.

 

Quick tweak:

 

if !(isServer) exitWith {};

params ["_antena"];
_radios = [radio_1,radio_2,radio_3,radio_4,radio_5];//changed this into object variables, make sure your radios are named exactly like that
_tracks = ["voicetrack1","voicetrack2","voicetrack3"];//always put stuff in arrays for easier randomization
_sleeps = [182,197,171];

while {alive _antena} do
 {

 	_rndIndex = selectRandom [0,1,2];//quick randomization, no need for switch here
 	_track = _tracks select _rndIndex;
 	_sleep = _sleeps select _rndIndex;

 	sleep 15;//sleep 15s between each transmission if that's your intent

 	{

 		[_x,[_track,200,1]] remoteExec ["say3D",0];//using remoteexec to run this on all clients and server

 	} forEach _radios;//run the remoteexec for every radio
 	sleep _sleep;//sleep the track specific time

 };

Go through each command on the wiki, if unclear ask again.

Stop living the life of a copy paster and join the dark side.

 

Cheers

 

  • Like 1

Share this post


Link to post
Share on other sites

@sarogahtyp & @Grumpy Old Man

 

Thanks, both of your solutions makes all the radios sound and all play the same track, but I found a curious and unexpected issue.  At the moment the player exits the listening radio of the say3D, the transmission pauses.  This means that if you pass near a radio, listen to it, you get on your way  until you can't hear it anymore and you get back within range to hear it again, transmission resumes right at the point you stopped hearing it.  and when you get near the next radio, you hear the track start again from zero. 

 

it is not the case in the mission , but to give you an idea of the issue, Imagine you are hearing a terrorist making a speech trough a radio with a threat and a countdown, and you pass near radio1, and the speech starts, saying that after so many seconds he is doing whatever evil things terrorists do.  you listen until he says that there is only half a minute left.  you go away for maybe five minutes, you go back to the radio, and the next thing you hear is that you have 29 seconds left.  Now if you get to the next radio2, you will listen the speech right from start.  it destroys the inmersion and the purpose of the transmision. 

 

Is there any way to make all radios make the speech in a synchronized way?  even if there is no player within the hearing radio of the transistors?

 

If this synchronization can not be done due to the nature of say3d function. I would rather prefer that each radio1, radio3, etc.  play a random track. 

 

@Grumpy Old Man

I'm slowly getting into the dark side, but i cannot devote much time to it, so each aid is a great lesson on how the system works. 

Share this post


Link to post
Share on other sites

This shouldn't be happening, since there's currently no way to pause a sound triggered by the say3d command to have it continue later on.

Say3D usually plays the sound from beginning to end, no matter if anyone is in range or not.

Something's odd. Did you try this in a new mission without mods?

 

Cheers

Share this post


Link to post
Share on other sites

vanilla + CBA

 

As said before, if it is a characteristic of say3D,  for the purposes of my mission, It would be better if each transistor played a random track

Share this post


Link to post
Share on other sites
vanilla + CBA
 
As said before, if it is a characteristic of say3D,  for the purposes of my mission, It would be better if each transistor played a random track
I think u did not understand what grumpy said. The behaviour which u described should never happen with say3D. It should just play the sound an never stop it until it's finished


sent from mobile using Tapatalk

  • Like 1

Share this post


Link to post
Share on other sites

Best would be to upload a video and/or a repro mission that showcases this.

Say3D has never done anything like that as long as I used it.

 

Cheers

  • Like 1

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

×