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

Editing sound

From Quake Wiki

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision Your text
Line 1: Line 1:
''void'' '''sound'''(''entity'' e, ''float'' channel, ''string'' soundPath, ''float'' volume, ''float'' attenuation)
+
====Syntax:====
 +
<code>void sound(entity e, float channel, string sample, float volume, float attenuation)</code>
  
== Usage ==
+
This function is used for playing a sound.
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.
+
====Parameters:====
 
+
:<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.
=== Parameters ===
+
:<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.
*''e''
+
:<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.
:The entity to play the sound from.
+
:<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.
*''channel''
+
====Returns:====
: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:
+
:void
:*<code>CHAN_AUTO</code>
+
====Other Details:====
:*<code>CHAN_WEAPON</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_VOICE</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_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]]

Please note that all contributions to Quake Wiki are considered to be released under the GNU Free Documentation License 1.3 or later (see Quake Wiki:Copyrights for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource. Do not submit copyrighted work without permission!

To edit this page, please answer the question that appears below (more info):

Cancel | Editing help (opens in new window)