Added replicate and notify parameters to ResetConVar() - these were already available for SetConVarX()
3 * ===============================================================
4 * SourceMod (C)2004-2007 AlliedModders LLC. All rights reserved.
5 * ===============================================================
7 * This file is part of the SourceMod/SourcePawn SDK. This file may only be used
8 * or modified under the Terms and Conditions of its License Agreement, which is found
9 * in LICENSE.txt. The Terms and Conditions for making SourceMod extensions/plugins
10 * may change at any time. To view the latest information, see:
11 * http://www.sourcemod.net/license.php
16 #if defined _sdktools_sound_included
19 #define _sdktools_sound_included
22 * Sound should be from the target client.
24 #define SOUND_FROM_PLAYER -2
27 * Sound should be from the listen server player.
29 #define SOUND_FROM_LOCAL_PLAYER -1
32 * Sound is from the world.
34 #define SOUND_FROM_WORLD 0
41 SNDCHAN_REPLACE = -1, /**< Unknown */
42 SNDCHAN_AUTO = 0, /**< Auto */
43 SNDCHAN_WEAPON = 1, /**< Weapons */
44 SNDCHAN_VOICE = 2, /**< Voices */
45 SNDCHAN_ITEM = 3, /**< Items */
46 SNDCHAN_BODY = 4, /**< Player? */
47 SNDCHAN_STREAM = 5, /**< "Stream channel from the static or dynamic area" */
48 SNDCHAN_STATIC = 6, /**< "Stream channel from the static area" */
49 SNDCHAN_VOICE_BASE = 7, /**< "Channel for network voice data" */
50 SNDCHAN_USER_BASE = 135 /**< Anything >= this is allocated to game code */
54 * Sound flags for the sound emitter system.
58 SND_NOFLAGS= 0, /**< Nothing */
59 SND_CHANGEVOL = 1, /**< Change sound volume */
60 SND_CHANGEPITCH = 2, /**< Change sound pitch */
61 SND_STOP = 3, /**< Stop the sound */
62 SND_SPAWNING = 4, /**< Used in some cases for ambients */
63 SND_DELAY = 5, /**< Sound has an initial delay */
64 SND_STOPLOOPING = 6, /**< Stop looping all sounds on the entity */
65 SND_SPEAKER = 7, /**< Being played by a mic through a speaker */
66 SND_SHOULDPAUSE = 8, /**< Pause if game is paused */
70 * Various predefined sound levels in dB.
74 SNDLEVEL_NONE = 0, /**< None */
75 SNDLEVEL_RUSTLE = 20, /**< Rustling leaves */
76 SNDLEVEL_WHISPER = 25, /**< Whispering */
77 SNDLEVEL_LIBRARY = 30, /**< In a library */
78 SNDLEVEL_FRIDGE = 45, /**< Refridgerator */
79 SNDLEVEL_HOME = 50, /**< Average home (3.9 attn) */
80 SNDLEVEL_CONVO = 60, /**< Normal conversation (2.0 attn) */
81 SNDLEVEL_DRYER = 60, /**< Clothes dryer */
82 SNDLEVEL_DISHWASHER = 65, /**< Dishwasher/washing machine (1.5 attn) */
83 SNDLEVEL_CAR = 70, /**< Car or vacuum cleaner (1.0 attn) */
84 SNDLEVEL_NORMAL = 75, /**< Normal sound level */
85 SNDLEVEL_TRAFFIC = 75, /**< Busy traffic (0.8 attn) */
86 SNDLEVEL_MINIBIKE = 80, /**< Mini-bike, alarm clock (0.7 attn) */
87 SNDLEVEL_SCREAMING = 90, /**< Screaming child (0.5 attn) */
88 SNDLEVEL_TRAIN = 100, /**< Subway train, pneumatic drill (0.4 attn) */
89 SNDLEVEL_HELICOPTER = 105, /**< Helicopter */
90 SNDLEVEL_SNOWMOBILE = 110, /**< Snow mobile */
91 SNDLEVEL_AIRCRAFT = 120, /**< Auto horn, aircraft */
92 SNDLEVEL_RAIDSIREN = 130, /**< Air raid siren */
93 SNDLEVEL_GUNFIRE = 140, /**< Gunshot, jet engine (0.27 attn) */
94 SNDLEVEL_ROCKET = 180, /**< Rocket launching (0.2 attn) */
97 #define SNDVOL_NORMAL 1.0 /**< Normal volume */
98 #define SNDPITCH_NORMAL 100 /**< Normal pitch */
99 #define SNDPITCH_LOW 95 /**< A low pitch */
100 #define SNDPITCH_HIGH 120 /**< A high pitch */
101 #define SNDATTN_NONE 0.0 /**< No attenuation */
102 #define SNDATTN_NORMAL 0.8 /**< Normal attenuation */
103 #define SNDATTN_STATIC 1.25 /**< Static attenuation? */
104 #define SNDATTN_RICOCHET 1.5 /**< Ricochet effect */
105 #define SNDATTN_IDLE 2.0 /**< Idle attenuation? */
108 * Prefetches a sound.
110 * @param name Sound file name.
113 native PrefetchSound(const String:nane[]);
116 * Gets a sound's duration (does not work for mp3s).
118 * @param name Sound file name.
119 * @return Duration in seconds.
121 native Float:GetSoundDuration(const String:name[]);
124 * Emits an ambient sound.
126 * @param entity Entity index to associate sound with.
127 * @param pos Origin of sound.
128 * @param name Sound file name.
129 * @param level Sound level (from 0 to 255).
130 * @param flags Sound flags.
131 * @param vol Volume (from 0.0 to 1.0).
132 * @param pitch Pitch (from 0 to 255).
133 * @param delay Play delay.
136 native EmitAmbientSound(const String:name[],
138 entity = SOUND_FROM_WORLD,
139 level = SNDLEVEL_NORMAL,
141 Float:vol = SNDVOL_NORMAL,
142 pitch = SNDPITCH_NORMAL,
146 * Fades a client's volume level toward silence or a given percentage.
148 * @param client Client index.
149 * @param percent Fade percentage.
150 * @param outtime Fade out time, in seconds.
151 * @param holdtime Hold time, in seconds.
152 * @param intime Fade in time, in seconds.
154 * @error Invalid client index or client not in game.
156 native FadeClientVolume(client, Float:percent, Float:outtime, Float:holdtime, Float:intime);
161 * @param entity Entity index.
162 * @param channel Channel number.
163 * @param name Sound name.
166 native StopSound(entity, channel, const String:name[]);
169 * Emits a sound to a list of clients.
171 * @param clients Array of client indexes.
172 * @param numClients Number of clients in the array.
173 * @param entity Entity to emit from.
174 * @param channel Channel to emit with.
175 * @param sample Sound name.
176 * @param level Sound level.
177 * @param flags Sound flags.
178 * @param volume Sound volume.
179 * @param pitch Sound pitch.
180 * @param speakerentity Unknown.
181 * @param origin Sound origin.
182 * @param dir Sound direction.
183 * @param updatePos Unknown (updates positions?)
184 * @param soundtime Alternate time to play sound for.
185 * @param ... Optional list of Float[3] arrays to specify additional origins.
187 * @error Invalid client index.
189 native EmitSound(const clients[],
191 const String:sample[],
192 entity = SOUND_FROM_PLAYER,
193 channel = SNDCHAN_AUTO,
194 level = SNDLEVEL_NORMAL,
196 Float:volume = SNDVOL_NORMAL,
197 pitch = SNDPITCH_NORMAL,
199 const Float:origin[3] = NULL_VECTOR,
200 const Float:dir[3] = NULL_VECTOR,
201 bool:updatePos = true,
202 Float:soundtime = 0.0,
206 * Emits a sentence to a list of clients.
208 * @param clients Array of client indexes.
209 * @param numClients Number of clients in the array.
210 * @param entity Entity to emit from.
211 * @param channel Channel to emit with.
212 * @param sentence Sentence index (from PrecacheSenteFile).
213 * @param level Sound level.
214 * @param flags Sound flags.
215 * @param volume Sound volume.
216 * @param pitch Sound pitch.
217 * @param speakerentity Unknown.
218 * @param origin Sound origin.
219 * @param dir Sound direction.
220 * @param updatePos Unknown (updates positions?)
221 * @param soundtime Alternate time to play sound for.
222 * @param ... Optional list of Float[3] arrays to specify additional origins.
224 * @error Invalid client index.
226 native EmitSentence(const clients[],
230 channel = SNDCHAN_AUTO,
231 level = SNDLEVEL_NORMAL,
233 Float:volume = SNDVOL_NORMAL,
234 pitch = SNDPITCH_NORMAL,
236 const Float:origin[3] = NULL_VECTOR,
237 const Float:dir[3] = NULL_VECTOR,
238 bool:updatePos = true,
239 Float:soundtime = 0.0,
244 * Wrapper to emit sound to one client.
246 * @param client Client index.
247 * @param entity Entity to emit from.
248 * @param channel Channel to emit with.
249 * @param sample Sound name.
250 * @param level Sound level.
251 * @param flags Sound flags.
252 * @param volume Sound volume.
253 * @param pitch Sound pitch.
254 * @param speakerentity Unknown.
255 * @param origin Sound origin.
256 * @param dir Sound direction.
257 * @param updatePos Unknown (updates positions?)
258 * @param soundtime Alternate time to play sound for.
260 * @error Invalid client index.
262 stock EmitSoundToClient(client,
263 const String:sample[],
264 entity = SOUND_FROM_PLAYER,
265 channel = SNDCHAN_AUTO,
266 level = SNDLEVEL_NORMAL,
268 Float:volume = SNDVOL_NORMAL,
269 pitch = SNDPITCH_NORMAL,
271 const Float:origin[3] = NULL_VECTOR,
272 const Float:dir[3] = NULL_VECTOR,
273 bool:updatePos = true,
274 Float:soundtime = 0.0)
278 /* Save some work for SDKTools and remove SOUND_FROM_PLAYER references */
279 entity = (entity == SOUND_FROM_PLAYER) ? client : entity;
280 EmitSound(clients, 1, sample, entity, channel,
281 level, flags, volume, pitch, speakerentity,
282 origin, dir, updatePos, soundtime);
286 * Wrapper to emit sound to all clients.
288 * @param entity Entity to emit from.
289 * @param channel Channel to emit with.
290 * @param sample Sound name.
291 * @param level Sound level.
292 * @param flags Sound flags.
293 * @param volume Sound volume.
294 * @param pitch Sound pitch.
295 * @param speakerentity Unknown.
296 * @param origin Sound origin.
297 * @param dir Sound direction.
298 * @param updatePos Unknown (updates positions?)
299 * @param soundtime Alternate time to play sound for.
301 * @error Invalid client index.
303 stock EmitSoundToAll(const String:sample[],
304 entity = SOUND_FROM_PLAYER,
305 channel = SNDCHAN_AUTO,
306 level = SNDLEVEL_NORMAL,
308 Float:volume = SNDVOL_NORMAL,
309 pitch = SNDPITCH_NORMAL,
311 const Float:origin[3] = NULL_VECTOR,
312 const Float:dir[3] = NULL_VECTOR,
313 bool:updatePos = true,
314 Float:soundtime = 0.0)
316 new maxClients = GetMaxClients();
317 new clients[maxClients];
320 for (new i=1; i<=maxClients; i++)
322 if (IsClientInGame(i))
324 clients[total++] = i;
333 EmitSound(clients, total, sample, entity, channel,
334 level, flags, volume, pitch, speakerentity,
335 origin, dir, updatePos, soundtime);
339 * Converts an attenuation value to a sound level.
340 * This function is from the HL2SDK.
342 * @param attn Attenuation value.
343 * @return Integer sound level.
345 stock ATTN_TO_SNDLEVEL(Float:attn)
349 return RoundFloat(50.0 + (20.0 / attn));