OFPEC Forum

Editors Depot - Mission Editing and Scripting => Arma2 - Editing/Scripting Multiplayer => Topic started by: LurchiDerLurch on 19 Apr 2010, 21:48:35

Title: Play a sound public
Post by: LurchiDerLurch on 19 Apr 2010, 21:48:35
Hello everyone!

I need to know how I can play a sound that everybody can hear (or not if he's too far away!)

playSound "sound"; -this is local or not?
unit say "sound"; -local? or global?
sound = createSoundSource ["sound",position Player,[],10]; - isn't working for me

Lurchi
Title: Re: Play a sound public
Post by: Loyalguard on 19 Apr 2010, 23:46:52
playSound is not local.  It will play the sound at every player location so you can be on the other side of the map and you will hear it as if you are right next to the sound.

Say will make the unit "say" the sound only as loud as defined in CfgSounds in the descriptiopn.ext or #include so you have to be relatively close to hear it.  So it is local per se, but the unit saying the sound does not have to be local to the player hearing it.

createSoundSource will only play sounds from class sound inside CfgVehicles.  So unless you choose one of those predefined sounds, or create your own via an addon, it will not play a sound (and may cause errors I assume)
Title: Re: Play a sound public
Post by: kju on 20 Apr 2010, 09:53:39
init.sqf
Code: [Select]
AAS_PublicSound = "";
clientOnly.sqf
Code: [Select]
"AAS_PublicSound" addPublicVariableEventHandler
{
_soundSource = (_this select 1) select 0;
_sound = (_this select 1) select 1;
_soundSource say _sound;
};

yourScriptCallingTheSound.sqf
Code: [Select]
_soundsource = "HeliHEmpty" createVehicle (position player);
_sound = "MySoundFile";
AAS_PublicSound = [_soundsource,_sound];
publicVariable "AAS_PublicSound";
_soundsource say _sound;
Title: Re: Play a sound public
Post by: LurchiDerLurch on 20 Apr 2010, 10:17:21
init.sqf
Code: [Select]
public string AAS_PublicSound = "";
clientOnly.sqf
Code: [Select]
"AAS_PublicSound" addPublicVariableEventHandler
{
_soundSource = (_this select 1) select 0;
_sound = (_this select 1) select 1;
_soundSource say _sound;
};

yourScriptCallingTheSound.sqf
Code: [Select]
_soundsource = "HeliHEmpty" createVehicle (position player);
_sound = "MySoundFile";
AAS_PublicSound = [_soundsource,_sound];
publicVariable "AAS_PublicSound";
_soundsource say _sound;

This will play the sound global - every player can hear this, right?

So the effect should be the same:

playSound is not local.  It will play the sound at every player location so you can be on the other side of the map and you will hear it as if you are right next to the sound.

Correct me if I'm wrong  :dunno:
Title: Re: Play a sound public
Post by: kju on 20 Apr 2010, 14:19:46
Say is played at the objects' location. So if you are far away, you won't hear it.

http://community.bistudio.com/wiki/say

Quote
If the camera is not within given range, title is not shown and the sound will not be heard.

You could optimize the script for MP to make a check if any isPlayer unit is close enough before calling the PV.
Title: Re: Play a sound public
Post by: ModestNovice on 21 Apr 2010, 00:43:11
@kju
what is this public string?

I've never heard of this and couldn't find anything on it on the wiki.
Title: Re: Play a sound public
Post by: kju on 21 Apr 2010, 07:35:25
Ups sorry. It is a convention introduced by CoolBox.

#define public
#define string

So its an empty replacement. They are to help reading code.