createSoundSource: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
mNo edit summary
(added seeAlso)
 
(101 intermediate revisions by 17 users not shown)
Line 1: Line 1:
[[Category:Scripting Commands|CREATESOUNDSOURCE]]
{{RV|type=command
[[Category:Scripting Commands OFP Elite |CREATESOUNDSOURCE]]
[[Category:Scripting Commands ArmA|CREATESOUNDSOURCE]]


|game1= ofpe
|version1= 1.00


<h2 style="color:#000066">''' createSoundSource ''[type, position, markers, placement]'''''</h2>
|game2= arma1
|version2= 1.00


|game3= arma2
|version3= 1.00


'''Operand types:'''
|game4= arma2oa
|version4= 1.50


'''[type, position, markers, placement]:''' [[Array]]
|game5= tkoh
|version5= 1.00


'''Type of returned value:'''
|game6= arma3
|version6= 0.50


[[Object]]
|arg= global


'''Compatibility:'''
|eff= global


Version 2.32 required.
|gr1= Sounds


'''Description:'''
|descr= Creates a sound source of the given type (type is the name of the subclass of [[ArmA:_CfgVehicles|CfgVehicles]] which is pointing to the sound defined in [[CfgSFX]]).
The actual sound object created is of type {{hl|"#dynamicsound"}} and could be detected with [[allMissionObjects]].
If the markers array contains several marker names, the position of a random one is used, otherwise, the given position is used.
The sound source is placed inside a circle with this position as its center and placement as its radius. Some of the vanilla classes pre-configured in {{arma3}}:
{{Columns|4|
* {{hl|"Sound_Alarm"}}
* {{hl|"Sound_Alarm2"}}
* {{hl|"Sound_BattlefieldExplosions"}}
* {{hl|"Sound_BattlefieldFirefight"}}
* {{hl|"Sound_Fire"}}
* {{hl|"Sound_SmokeWreck1"}}
* {{hl|"Sound_SparklesWreck1"}}
* {{hl|"Sound_SparklesWreck2"}}
* {{hl|"Sound_Stream"}}
}}


Creates a sound source of the given '''type''' (type is the name of the subclass of CfgVehicles).
Since {{GVI|arma3|1.70}} it is possible to define sounds for use with [[createSoundSource]] in [[Description.ext]].
As mentioned earlier, the sounds needed for this command should be defined inside [[CfgVehicles]] class, which itself references [[CfgSFX]] class.
If given class searched in main config and is not found, the search will continue in [[Description.ext|description.ext]] - see {{Link|#Example 3}}.<br>


If the '''markers''' array contains several marker names, the position of a random one is used, otherwise, the given '''position''' is used.
{{Feature|informative|A sound created by [[createSoundSource]] will always be looping.}}


The sound source is placed inside a circle with this position as its center and '''placement''' as its radius.
{{Feature|arma3|In earlier {{arma3}} versions, the sound created was greatly attenuated if the player was in first person view inside a vehicle at the moment of execution.}}


|mp= When a [[CfgSFX]] sound definition contains more than 1 sound, there is no guarantee that the sound played will be the same on every PC in Multiplayer.


'''Example:'''
|s1= [[createSoundSource]] [type, position, markers, placement]


soundSource = '''createSoundSource''' ["LittleDog", [[position]] [[player]], [], 0]
|p1= type: [[String]] - [[CfgVehicles]] class
 
|p2= position: [[Object]] or [[Array]] format [[Position#PositionAGL|PositionAGL]] or [[Position#Introduction|Position2D]] - desired placement position
 
|p3= markers: [[Array]] - if the markers array contains any markers, the position is randomly picked from array of given markers plus desired placement position.
If any of the markers were given a Z coordinate with [[setMarkerPos]], the sound will also be created at the given Z coordinate
 
|p4= placement: [[Number]] - the sound is placed inside a circle with given position as center and placement as its radius
 
|r1= [[Object]]
 
|x1= <sqf>_soundSource = createSoundSource ["LittleDog", position player, [], 0];</sqf>
 
|x2= <sqf>
0 spawn
{
_alarm = createSoundSource ["Sound_Alarm", position player, [], 0]; // starts alarm
sleep 10;
deleteVehicle _alarm; // stops alarm
};
</sqf>
 
|x3= {{GVI|arma3|1.70}} Here is an example of suitable mission config definition:
<syntaxhighlight lang="cpp">
// description.ext
class CfgSFX
{
class MyOwl
{
sound0[] = { "@A3\Sounds_F\environment\animals\birds\owl1", db-10, 1.0, 1000, 0.2, 0, 15, 30 }; // path to addon sound
sound1[] = { "@A3\Sounds_F\environment\animals\birds\owl2", db-10, 1.0, 1000, 0.2, 0, 15, 30 }; // path to addon sound
sound2[] = { "@A3\Sounds_F\environment\animals\birds\owl3", db-10, 1.0, 1000, 0.2, 0, 15, 30 }; // path to addon sound
sounds[] = { "sound0", "sound1", "sound2" };
empty[] = { "", 0, 0, 0, 0, 0, 0, 0 };
};
};
 
class CfgVehicles
{
class MyOwlSound // class name to be used with createSoundSource
{
sound = "MyOwl"; // reference to CfgSFX class
};
};
</syntaxhighlight>
 
<sqf>private _owl = createSoundSource ["MyOwlSound", position player, [], 0];</sqf>
 
|seealso= [[createSoundSourceLocal]] [[playSound]] [[playSound3D]] [[sideRadio]] [[say]] [[say2D]] [[say3D]] [[playMusic]] [[playSoundUI]]
}}

Latest revision as of 07:53, 12 October 2024

Hover & click on the images for description

Description

Description:
Creates a sound source of the given type (type is the name of the subclass of CfgVehicles which is pointing to the sound defined in CfgSFX). The actual sound object created is of type "#dynamicsound" and could be detected with allMissionObjects. If the markers array contains several marker names, the position of a random one is used, otherwise, the given position is used. The sound source is placed inside a circle with this position as its center and placement as its radius. Some of the vanilla classes pre-configured in Arma 3:
  • "Sound_Alarm"
  • "Sound_Alarm2"
  • "Sound_BattlefieldExplosions"
  • "Sound_BattlefieldFirefight"
  • "Sound_Fire"
  • "Sound_SmokeWreck1"
  • "Sound_SparklesWreck1"
  • "Sound_SparklesWreck2"
  • "Sound_Stream"

Since Arma 3 logo black.png1.70 it is possible to define sounds for use with createSoundSource in Description.ext. As mentioned earlier, the sounds needed for this command should be defined inside CfgVehicles class, which itself references CfgSFX class. If given class searched in main config and is not found, the search will continue in description.ext - see Example 3.

A sound created by createSoundSource will always be looping.
Arma 3
In earlier Arma 3 versions, the sound created was greatly attenuated if the player was in first person view inside a vehicle at the moment of execution.
Multiplayer:
When a CfgSFX sound definition contains more than 1 sound, there is no guarantee that the sound played will be the same on every PC in Multiplayer.
Groups:
Sounds

Syntax

Syntax:
createSoundSource [type, position, markers, placement]
Parameters:
type: String - CfgVehicles class
position: Object or Array format PositionAGL or Position2D - desired placement position
markers: Array - if the markers array contains any markers, the position is randomly picked from array of given markers plus desired placement position. If any of the markers were given a Z coordinate with setMarkerPos, the sound will also be created at the given Z coordinate
placement: Number - the sound is placed inside a circle with given position as center and placement as its radius
Return Value:
Object

Examples

Example 1:
_soundSource = createSoundSource ["LittleDog", position player, [], 0];
Example 2:
0 spawn { _alarm = createSoundSource ["Sound_Alarm", position player, [], 0]; // starts alarm sleep 10; deleteVehicle _alarm; // stops alarm };
Example 3:
Arma 3 logo black.png1.70 Here is an example of suitable mission config definition:
// description.ext
class CfgSFX
{
	class MyOwl
	{
		sound0[] = { "@A3\Sounds_F\environment\animals\birds\owl1", db-10, 1.0, 1000, 0.2, 0, 15, 30 };	// path to addon sound
		sound1[] = { "@A3\Sounds_F\environment\animals\birds\owl2", db-10, 1.0, 1000, 0.2, 0, 15, 30 };	// path to addon sound
		sound2[] = { "@A3\Sounds_F\environment\animals\birds\owl3", db-10, 1.0, 1000, 0.2, 0, 15, 30 };	// path to addon sound
		sounds[] = { "sound0", "sound1", "sound2" };
		empty[] = { "", 0, 0, 0, 0, 0, 0, 0 };
	};
};

class CfgVehicles
{
	class MyOwlSound // class name to be used with createSoundSource
	{
		sound = "MyOwl"; // reference to CfgSFX class
	};
};
private _owl = createSoundSource ["MyOwlSound", position player, [], 0];

Additional Information

See also:
createSoundSourceLocal playSound playSound3D sideRadio say say2D say3D playMusic playSoundUI

Notes

Report bugs on the Feedback Tracker and/or discuss them on the Arma Discord or on the Forums.
Only post proven facts here! Add Note