Jump to content
Endet15

Need help playing sound to all clients in a server

Recommended Posts

So a few weeks back I wanted to make a tornado siren for a scenario I was going to zeus for my friends. I followed this tutorial on how to do it. 30 minutes later I had a working siren.

 

Only issue was, when the time came for me to actually use the siren in the scenario, I was the only person that could hear it. Now I want to add audio to an object for another scenario, but I want to know how I can get ALL clients on the server to hear it. Any help would be appreciated!!

Here's my description.ext:

 

class CfgSounds
{
 sounds[] = {};
 class music1
 {
  name = "music1";
  sound[] = {"\sounds\siren.wav", 300, 1};
  titles[] = {0,""};
 };
};

Here's the code I had in the object:

 

siren addAction [ "SIREN ON", {
siren say3D ["music1", 1000, 1];
} ];

 

Share this post


Link to post
Share on other sites

G'day Endet15,

 

The reason i believe you're the only one hearing the sound, is because the effects of the addAction are Local. Meaning only the individual who completes the action, will get the results/effects (i.e the sound)

Wiki page: https://community.bistudio.com/wiki/addAction

Notice the Effects are marked as L for Local. I recently discovered this as well, so no worries about this issue. 

 

One way to fix the problem is either you can use remoteExec on the addaction which will force the addAction effects to run on all connected clients whenever one person uses the action, or you can have the addAction execute a trigger, and then that trigger execute the say3D as trigger effects are always globalised so everyone should hear the sound.

 

REMOTEEXEC:

 

This is the way i have set-up my addAction for my COOP mission using remoteExec:

(I put this inside the init field of a Switch object)


[this,["Switch Off Generators",{
gen1_switch animateSource ["switchposition",1];   
gen1_switch animateSource ["light",0];   
gen1_switch setDamage 1;
switched_off = true;
},[],1.5,true,true,"","_this distance _target < 2"]] remoteExec ["addAction",0];

 

Perhaps this should work; i think i have written the syntax correctly but they may be one or two errors:

[siren, ["SIREN ON", {siren say3D ["music1", 1000, 1];} ]] remoteExec ["addAction",0];

 

TRIGGER METHOD: (I think this works, tbh i haven't tested it though, just thought it up)

 

The way i would do it via a trigger is to have the addAction run as you have it now, but alter the variable to a boolean like "enable_siren". 

I.E: "siren addAction [ "SIREN ON", { enable_siren = true; } ];"

This will then switch the variable to 'true' which can be placed inside a triggers Condition field as (enable_siren), which will then once the action has been completed activate the trigger that will have "siren say3D ["music1", 1000, 1];" inside the On Activation field. This should work Server Side and for all players, as triggers are global. 

 

Hope one of these helps

Share this post


Link to post
Share on other sites
7 hours ago, Endet15 said:

 


class CfgSounds
{
 sounds[] = {};
 class music1
 {
  name = "music1";
  sound[] = {"\sounds\siren.wav", 300, 1};
  titles[] = {0,""};
 };
};

Here's the code I had in the object:

 


siren addAction [ "SIREN ON", {
siren say3D ["music1", 1000, 1];
} ];

 

 

 

You're not too far. Your addAction must be in init.sqf or in the init field of the object, or, everywhere any player will run at start. In init field of the object you can use the variable this instead of siren . Just a point, not mandatory. No need to remoteExec it this way!

 

So, when the addAction is executable on any PC , now, the inner code (always local to the caller) must be remoteExec globally along with all "local effect" commands, to be run everywhere.    say3D is effects_local.gif command.

[siren, ["music1", 1000, 1] ] remoteExec ["say3D"];

should work. (process tested in my scripts similar to this).

 

Share this post


Link to post
Share on other sites
19 hours ago, pierremgi said:

 

 

You're not too far. Your addAction must be in init.sqf or in the init field of the object, or, everywhere any player will run at start. In init field of the object you can use the variable this instead of siren . Just a point, not mandatory. No need to remoteExec it this way!

 

So, when the addAction is executable on any PC , now, the inner code (always local to the caller) must be remoteExec globally along with all "local effect" commands, to be run everywhere.    say3D is effects_local.gif command.

[siren, ["music1", 1000, 1] ] remoteExec ["say3D"]; 

should work. (process tested in my scripts similar to this).

 

This worked, thanks a ton guys!

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

×