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

Difference between revisions of "sound"

From Quake Wiki

m (Parameters)
 
(2 intermediate revisions by 2 users not shown)
Line 1: Line 1:
====Syntax:====
+
''void'' '''sound'''(''entity'' e, ''float'' channel, ''string'' soundPath, ''float'' volume, ''float'' attenuation)
<code>void sound(entity e, float channel, string sample, float volume, float attenuation)</code>
 
  
This function is used for playing a sound.
+
== Usage ==
====Parameters:====
+
Plays a sound at an entity's location using one of its sound channels. A sound must be precached during map load in order to be considered valid. Once a sound is playing the only way to stop it is by passing an empty sound to play on the same channel. Sounds will always interrupt each other if played on the same channel, but <code>CHAN_AUTO</code> will attempt to avoid this.
:<code>channel</code> - The channel to play the sound on.  A sound played on the same channel as another will override the previous one. Use integer values only.
+
 
:<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.
+
=== Parameters ===
:<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.
+
*''e''
:<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 entity to play the sound from.
====Returns:====
+
*''channel''
:void
+
:Can be a value from 0 to 7 (whole numbers only). 0 (<code>CHAN_AUTO</code>) will try and not override any currently playing sounds. Default values:
====Other Details:====
+
:*<code>CHAN_AUTO</code>
Sounds started outside the hearing range of the player will not be registered by the engine, so if the player later moves in to hearing range, the sound will not be heard.
+
:*<code>CHAN_WEAPON</code>
Sounds that are looped will continue playing, but if the player moves out of hearing range, the engine will eventually stop playing it and when the player moves back into hearing range, it will no longer be there.
+
:*<code>CHAN_VOICE</code>
 +
:*<code>CHAN_ITEM</code>
 +
:*<code>CHAN_BODY</code>
 +
*''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 (<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 ==
 +
void monster_my_monster()
 +
{
 +
    // Make sure to precache the sound first in the initialization function
 +
    precache_sound("mymonster/missile.wav");
 +
}
 +
 +
void MyMonsterMissileAttack()
 +
{
 +
    // Play the sound on the monster's weapon channel
 +
    sound(self, CHAN_WEAPON, "mymonster/missile.wav", 1, ATTN_NORM);
 +
}
  
 
[[Category:QuakeC Function]]
 
[[Category:QuakeC Function]]

Latest revision as of 11:51, 31 July 2023

void sound(entity e, float channel, string soundPath, float volume, float attenuation)

Usage[edit]

Plays a sound at an entity's location using one of its sound channels. A sound must be precached during map load in order to be considered valid. Once a sound is playing the only way to stop it is by passing an empty sound to play on the same channel. Sounds will always interrupt each other if played on the same channel, but CHAN_AUTO will attempt to avoid this.

Parameters[edit]

  • e
The entity to play the sound from.
  • channel
Can be a value from 0 to 7 (whole numbers only). 0 (CHAN_AUTO) will try and not override any currently playing sounds. Default values:
  • CHAN_AUTO
  • CHAN_WEAPON
  • CHAN_VOICE
  • CHAN_ITEM
  • CHAN_BODY
  • 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]

void monster_my_monster()
{
    // Make sure to precache the sound first in the initialization function
    precache_sound("mymonster/missile.wav");
}

void MyMonsterMissileAttack()
{
    // Play the sound on the monster's weapon channel
    sound(self, CHAN_WEAPON, "mymonster/missile.wav", 1, ATTN_NORM);
}