Hosting and domain costs until October 2024 have been generously sponsored by dumptruck_ds. Thank you!

Difference between revisions of "ambientsound"

From Quake Wiki

 
(One intermediate revision by one other user not shown)
Line 1: Line 1:
====Syntax:====
+
''void'' '''ambientsound'''(''vector'' pos, ''string'' soundPath, ''float'' volume, ''float'' attenuation)
<code>void ambientsound(vector pos, string sample, float volume, float attenuation)</code>
+
 
 +
== Usage ==
 +
Starts playing a sound with no connection to any entity. A sound must be precached during map load in order to be considered valid. Once an ambient sound starts playing it cannot be stopped.
 +
 
 +
Unlike standard sounds, ambient sounds must loop in order to be considered valid (sound markers need to be present in the file).
  
Starts a sound as an ambient sound.  Unlike normal sounds started from the '''sound''' function, an ambient sound will never stop playing, even if the player moves out of audible range.  It will also be properly registered by the engine if it is started outside of hearing range of the player.
 
 
====Parameters:====
 
====Parameters:====
:<code>pos</code> - The coordinates for the origin of the sound.
+
*''pos''
:<code>sample</code> - The path to the sound file. Unlike models, sounds have /sound/ already present, so do not include that directory in the pathname.  This sound MUST be looped by placing markers in the .wav file.
+
:The origin of the sound.
:<code>volume</code> - A value between 0.0 and 1.0 that controls the volume of the sound. 0.0 is silent, 1.0 is full volume.
+
*''soundPath''
:<code>attenuation</code> - A value greater than or equal to 0 and less than 4 that controls how fast the sound's volume attenuated from distance.  0 can be heard everywhere in the level, 1 can be heard up to 1000 units and 3.999 has a radius of about 250 units.
+
:The path of the sound file. Supports WAV (.wav) files.
====Returns:====
+
*''volume''
:void
+
:Can be a value from 0 to 1.
====Other Details:====
+
*''attenuation''
There is a separate limit to how many ambient sounds can be placed in a map (even if they are the same sound).  In stock Quake, this is 128. (VERIFY?)
+
:Determines the linear falloff of the sound over distance. A value of 0 (<code>ATTN_NONE</code>) will have no fall off. The larger the value, the greater the falloff. Default values:
 +
:*<code>ATTN_NONE</code>
 +
:*<code>ATTN_NORM</code>
 +
:*<code>ATTN_IDLE</code>
 +
:*<code>ATTN_STATIC</code>
  
 +
== Example ==
 +
// This entity plays an ambient sound when it initializes
 +
void ambient_ocean()
 +
{
 +
    precache_sound("ambience/ocean.wav");
 +
    ambientsound(self.origin, "ambience/ocean.wav", 1, ATTN_STATIC);
 +
 +
    remove(self);
 +
}
  
 
[[Category:QuakeC Function]]
 
[[Category:QuakeC Function]]

Latest revision as of 18:02, 1 August 2023

void ambientsound(vector pos, string soundPath, float volume, float attenuation)

Usage[edit]

Starts playing a sound with no connection to any entity. A sound must be precached during map load in order to be considered valid. Once an ambient sound starts playing it cannot be stopped.

Unlike standard sounds, ambient sounds must loop in order to be considered valid (sound markers need to be present in the file).

Parameters:[edit]

  • pos
The origin of the sound.
  • soundPath
The path of the sound file. Supports WAV (.wav) files.
  • volume
Can be a value from 0 to 1.
  • attenuation
Determines the linear falloff of the sound over distance. A value of 0 (ATTN_NONE) will have no fall off. The larger the value, the greater the falloff. Default values:
  • ATTN_NONE
  • ATTN_NORM
  • ATTN_IDLE
  • ATTN_STATIC

Example[edit]

// This entity plays an ambient sound when it initializes
void ambient_ocean()
{
    precache_sound("ambience/ocean.wav");
    ambientsound(self.origin, "ambience/ocean.wav", 1, ATTN_STATIC);

    remove(self);
}