1.1 --- a/plugins/include/sdktools_sound.inc Fri Mar 28 06:21:34 2008 +0000
1.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
1.3 @@ -1,369 +0,0 @@
1.4 -/**
1.5 - * vim: set ts=4 :
1.6 - * =============================================================================
1.7 - * SourceMod (C)2004-2007 AlliedModders LLC. All rights reserved.
1.8 - * =============================================================================
1.9 - *
1.10 - * This file is part of the SourceMod/SourcePawn SDK.
1.11 - *
1.12 - * This program is free software; you can redistribute it and/or modify it under
1.13 - * the terms of the GNU General Public License, version 3.0, as published by the
1.14 - * Free Software Foundation.
1.15 - *
1.16 - * This program is distributed in the hope that it will be useful, but WITHOUT
1.17 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
1.18 - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
1.19 - * details.
1.20 - *
1.21 - * You should have received a copy of the GNU General Public License along with
1.22 - * this program. If not, see <http://www.gnu.org/licenses/>.
1.23 - *
1.24 - * As a special exception, AlliedModders LLC gives you permission to link the
1.25 - * code of this program (as well as its derivative works) to "Half-Life 2," the
1.26 - * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
1.27 - * by the Valve Corporation. You must obey the GNU General Public License in
1.28 - * all respects for all other code used. Additionally, AlliedModders LLC grants
1.29 - * this exception to all derivative works. AlliedModders LLC defines further
1.30 - * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
1.31 - * or <http://www.sourcemod.net/license.php>.
1.32 - *
1.33 - * Version: $Id$
1.34 - */
1.35 -
1.36 -#if defined _sdktools_sound_included
1.37 - #endinput
1.38 -#endif
1.39 -#define _sdktools_sound_included
1.40 -
1.41 -/**
1.42 - * Sound should be from the target client.
1.43 - */
1.44 -#define SOUND_FROM_PLAYER -2
1.45 -
1.46 -/**
1.47 - * Sound should be from the listen server player.
1.48 - */
1.49 -#define SOUND_FROM_LOCAL_PLAYER -1
1.50 -
1.51 -/**
1.52 - * Sound is from the world.
1.53 - */
1.54 -#define SOUND_FROM_WORLD 0
1.55 -
1.56 -/**
1.57 - * Sound channels.
1.58 - */
1.59 -enum
1.60 -{
1.61 - SNDCHAN_REPLACE = -1, /**< Unknown */
1.62 - SNDCHAN_AUTO = 0, /**< Auto */
1.63 - SNDCHAN_WEAPON = 1, /**< Weapons */
1.64 - SNDCHAN_VOICE = 2, /**< Voices */
1.65 - SNDCHAN_ITEM = 3, /**< Items */
1.66 - SNDCHAN_BODY = 4, /**< Player? */
1.67 - SNDCHAN_STREAM = 5, /**< "Stream channel from the static or dynamic area" */
1.68 - SNDCHAN_STATIC = 6, /**< "Stream channel from the static area" */
1.69 - SNDCHAN_VOICE_BASE = 7, /**< "Channel for network voice data" */
1.70 - SNDCHAN_USER_BASE = 135 /**< Anything >= this is allocated to game code */
1.71 -};
1.72 -
1.73 -/**
1.74 - * Sound flags for the sound emitter system.
1.75 - */
1.76 -enum
1.77 -{
1.78 - SND_NOFLAGS= 0, /**< Nothing */
1.79 - SND_CHANGEVOL = 1, /**< Change sound volume */
1.80 - SND_CHANGEPITCH = 2, /**< Change sound pitch */
1.81 - SND_STOP = 3, /**< Stop the sound */
1.82 - SND_SPAWNING = 4, /**< Used in some cases for ambients */
1.83 - SND_DELAY = 5, /**< Sound has an initial delay */
1.84 - SND_STOPLOOPING = 6, /**< Stop looping all sounds on the entity */
1.85 - SND_SPEAKER = 7, /**< Being played by a mic through a speaker */
1.86 - SND_SHOULDPAUSE = 8, /**< Pause if game is paused */
1.87 -};
1.88 -
1.89 -/**
1.90 - * Various predefined sound levels in dB.
1.91 - */
1.92 -enum
1.93 -{
1.94 - SNDLEVEL_NONE = 0, /**< None */
1.95 - SNDLEVEL_RUSTLE = 20, /**< Rustling leaves */
1.96 - SNDLEVEL_WHISPER = 25, /**< Whispering */
1.97 - SNDLEVEL_LIBRARY = 30, /**< In a library */
1.98 - SNDLEVEL_FRIDGE = 45, /**< Refridgerator */
1.99 - SNDLEVEL_HOME = 50, /**< Average home (3.9 attn) */
1.100 - SNDLEVEL_CONVO = 60, /**< Normal conversation (2.0 attn) */
1.101 - SNDLEVEL_DRYER = 60, /**< Clothes dryer */
1.102 - SNDLEVEL_DISHWASHER = 65, /**< Dishwasher/washing machine (1.5 attn) */
1.103 - SNDLEVEL_CAR = 70, /**< Car or vacuum cleaner (1.0 attn) */
1.104 - SNDLEVEL_NORMAL = 75, /**< Normal sound level */
1.105 - SNDLEVEL_TRAFFIC = 75, /**< Busy traffic (0.8 attn) */
1.106 - SNDLEVEL_MINIBIKE = 80, /**< Mini-bike, alarm clock (0.7 attn) */
1.107 - SNDLEVEL_SCREAMING = 90, /**< Screaming child (0.5 attn) */
1.108 - SNDLEVEL_TRAIN = 100, /**< Subway train, pneumatic drill (0.4 attn) */
1.109 - SNDLEVEL_HELICOPTER = 105, /**< Helicopter */
1.110 - SNDLEVEL_SNOWMOBILE = 110, /**< Snow mobile */
1.111 - SNDLEVEL_AIRCRAFT = 120, /**< Auto horn, aircraft */
1.112 - SNDLEVEL_RAIDSIREN = 130, /**< Air raid siren */
1.113 - SNDLEVEL_GUNFIRE = 140, /**< Gunshot, jet engine (0.27 attn) */
1.114 - SNDLEVEL_ROCKET = 180, /**< Rocket launching (0.2 attn) */
1.115 -};
1.116 -
1.117 -#define SNDVOL_NORMAL 1.0 /**< Normal volume */
1.118 -#define SNDPITCH_NORMAL 100 /**< Normal pitch */
1.119 -#define SNDPITCH_LOW 95 /**< A low pitch */
1.120 -#define SNDPITCH_HIGH 120 /**< A high pitch */
1.121 -#define SNDATTN_NONE 0.0 /**< No attenuation */
1.122 -#define SNDATTN_NORMAL 0.8 /**< Normal attenuation */
1.123 -#define SNDATTN_STATIC 1.25 /**< Static attenuation? */
1.124 -#define SNDATTN_RICOCHET 1.5 /**< Ricochet effect */
1.125 -#define SNDATTN_IDLE 2.0 /**< Idle attenuation? */
1.126 -
1.127 -/**
1.128 - * Prefetches a sound.
1.129 - *
1.130 - * @param name Sound file name.
1.131 - * @noreturn
1.132 - */
1.133 -native PrefetchSound(const String:nane[]);
1.134 -
1.135 -/**
1.136 - * Gets a sound's duration (does not work for mp3s).
1.137 - *
1.138 - * @param name Sound file name.
1.139 - * @return Duration in seconds.
1.140 - */
1.141 -native Float:GetSoundDuration(const String:name[]);
1.142 -
1.143 -/**
1.144 - * Emits an ambient sound.
1.145 - *
1.146 - * @param entity Entity index to associate sound with.
1.147 - * @param pos Origin of sound.
1.148 - * @param name Sound file name.
1.149 - * @param level Sound level (from 0 to 255).
1.150 - * @param flags Sound flags.
1.151 - * @param vol Volume (from 0.0 to 1.0).
1.152 - * @param pitch Pitch (from 0 to 255).
1.153 - * @param delay Play delay.
1.154 - * @noreturn
1.155 - */
1.156 -native EmitAmbientSound(const String:name[],
1.157 - const Float:pos[3],
1.158 - entity = SOUND_FROM_WORLD,
1.159 - level = SNDLEVEL_NORMAL,
1.160 - flags = SND_NOFLAGS,
1.161 - Float:vol = SNDVOL_NORMAL,
1.162 - pitch = SNDPITCH_NORMAL,
1.163 - Float:delay = 0.0);
1.164 -
1.165 -/**
1.166 - * Fades a client's volume level toward silence or a given percentage.
1.167 - *
1.168 - * @param client Client index.
1.169 - * @param percent Fade percentage.
1.170 - * @param outtime Fade out time, in seconds.
1.171 - * @param holdtime Hold time, in seconds.
1.172 - * @param intime Fade in time, in seconds.
1.173 - * @noreturn
1.174 - * @error Invalid client index or client not in game.
1.175 - */
1.176 -native FadeClientVolume(client, Float:percent, Float:outtime, Float:holdtime, Float:intime);
1.177 -
1.178 -/**
1.179 - * Stops a sound.
1.180 - *
1.181 - * @param entity Entity index.
1.182 - * @param channel Channel number.
1.183 - * @param name Sound name.
1.184 - * @noreturn
1.185 - */
1.186 -native StopSound(entity, channel, const String:name[]);
1.187 -
1.188 -/**
1.189 - * Emits a sound to a list of clients.
1.190 - *
1.191 - * @param clients Array of client indexes.
1.192 - * @param numClients Number of clients in the array.
1.193 - * @param entity Entity to emit from.
1.194 - * @param channel Channel to emit with.
1.195 - * @param sample Sound name.
1.196 - * @param level Sound level.
1.197 - * @param flags Sound flags.
1.198 - * @param volume Sound volume.
1.199 - * @param pitch Sound pitch.
1.200 - * @param speakerentity Unknown.
1.201 - * @param origin Sound origin.
1.202 - * @param dir Sound direction.
1.203 - * @param updatePos Unknown (updates positions?)
1.204 - * @param soundtime Alternate time to play sound for.
1.205 - * @param ... Optional list of Float[3] arrays to specify additional origins.
1.206 - * @noreturn
1.207 - * @error Invalid client index.
1.208 - */
1.209 -native EmitSound(const clients[],
1.210 - numClients,
1.211 - const String:sample[],
1.212 - entity = SOUND_FROM_PLAYER,
1.213 - channel = SNDCHAN_AUTO,
1.214 - level = SNDLEVEL_NORMAL,
1.215 - flags = SND_NOFLAGS,
1.216 - Float:volume = SNDVOL_NORMAL,
1.217 - pitch = SNDPITCH_NORMAL,
1.218 - speakerentity = -1,
1.219 - const Float:origin[3] = NULL_VECTOR,
1.220 - const Float:dir[3] = NULL_VECTOR,
1.221 - bool:updatePos = true,
1.222 - Float:soundtime = 0.0,
1.223 - any:...);
1.224 -
1.225 -/**
1.226 - * Emits a sentence to a list of clients.
1.227 - *
1.228 - * @param clients Array of client indexes.
1.229 - * @param numClients Number of clients in the array.
1.230 - * @param entity Entity to emit from.
1.231 - * @param channel Channel to emit with.
1.232 - * @param sentence Sentence index (from PrecacheSenteFile).
1.233 - * @param level Sound level.
1.234 - * @param flags Sound flags.
1.235 - * @param volume Sound volume.
1.236 - * @param pitch Sound pitch.
1.237 - * @param speakerentity Unknown.
1.238 - * @param origin Sound origin.
1.239 - * @param dir Sound direction.
1.240 - * @param updatePos Unknown (updates positions?)
1.241 - * @param soundtime Alternate time to play sound for.
1.242 - * @param ... Optional list of Float[3] arrays to specify additional origins.
1.243 - * @noreturn
1.244 - * @error Invalid client index.
1.245 - */
1.246 -native EmitSentence(const clients[],
1.247 - numClients,
1.248 - sentence,
1.249 - entity,
1.250 - channel = SNDCHAN_AUTO,
1.251 - level = SNDLEVEL_NORMAL,
1.252 - flags = SND_NOFLAGS,
1.253 - Float:volume = SNDVOL_NORMAL,
1.254 - pitch = SNDPITCH_NORMAL,
1.255 - speakerentity = -1,
1.256 - const Float:origin[3] = NULL_VECTOR,
1.257 - const Float:dir[3] = NULL_VECTOR,
1.258 - bool:updatePos = true,
1.259 - Float:soundtime = 0.0,
1.260 - any:...);
1.261 -
1.262 -
1.263 -/**
1.264 - * Wrapper to emit sound to one client.
1.265 - *
1.266 - * @param client Client index.
1.267 - * @param entity Entity to emit from.
1.268 - * @param channel Channel to emit with.
1.269 - * @param sample Sound name.
1.270 - * @param level Sound level.
1.271 - * @param flags Sound flags.
1.272 - * @param volume Sound volume.
1.273 - * @param pitch Sound pitch.
1.274 - * @param speakerentity Unknown.
1.275 - * @param origin Sound origin.
1.276 - * @param dir Sound direction.
1.277 - * @param updatePos Unknown (updates positions?)
1.278 - * @param soundtime Alternate time to play sound for.
1.279 - * @noreturn
1.280 - * @error Invalid client index.
1.281 - */
1.282 -stock EmitSoundToClient(client,
1.283 - const String:sample[],
1.284 - entity = SOUND_FROM_PLAYER,
1.285 - channel = SNDCHAN_AUTO,
1.286 - level = SNDLEVEL_NORMAL,
1.287 - flags = SND_NOFLAGS,
1.288 - Float:volume = SNDVOL_NORMAL,
1.289 - pitch = SNDPITCH_NORMAL,
1.290 - speakerentity = -1,
1.291 - const Float:origin[3] = NULL_VECTOR,
1.292 - const Float:dir[3] = NULL_VECTOR,
1.293 - bool:updatePos = true,
1.294 - Float:soundtime = 0.0)
1.295 -{
1.296 - new clients[1];
1.297 - clients[0] = client;
1.298 - /* Save some work for SDKTools and remove SOUND_FROM_PLAYER references */
1.299 - entity = (entity == SOUND_FROM_PLAYER) ? client : entity;
1.300 - EmitSound(clients, 1, sample, entity, channel,
1.301 - level, flags, volume, pitch, speakerentity,
1.302 - origin, dir, updatePos, soundtime);
1.303 -}
1.304 -
1.305 -/**
1.306 - * Wrapper to emit sound to all clients.
1.307 - *
1.308 - * @param entity Entity to emit from.
1.309 - * @param channel Channel to emit with.
1.310 - * @param sample Sound name.
1.311 - * @param level Sound level.
1.312 - * @param flags Sound flags.
1.313 - * @param volume Sound volume.
1.314 - * @param pitch Sound pitch.
1.315 - * @param speakerentity Unknown.
1.316 - * @param origin Sound origin.
1.317 - * @param dir Sound direction.
1.318 - * @param updatePos Unknown (updates positions?)
1.319 - * @param soundtime Alternate time to play sound for.
1.320 - * @noreturn
1.321 - * @error Invalid client index.
1.322 - */
1.323 -stock EmitSoundToAll(const String:sample[],
1.324 - entity = SOUND_FROM_PLAYER,
1.325 - channel = SNDCHAN_AUTO,
1.326 - level = SNDLEVEL_NORMAL,
1.327 - flags = SND_NOFLAGS,
1.328 - Float:volume = SNDVOL_NORMAL,
1.329 - pitch = SNDPITCH_NORMAL,
1.330 - speakerentity = -1,
1.331 - const Float:origin[3] = NULL_VECTOR,
1.332 - const Float:dir[3] = NULL_VECTOR,
1.333 - bool:updatePos = true,
1.334 - Float:soundtime = 0.0)
1.335 -{
1.336 - new maxClients = GetMaxClients();
1.337 - new clients[maxClients];
1.338 - new total = 0;
1.339 -
1.340 - for (new i=1; i<=maxClients; i++)
1.341 - {
1.342 - if (IsClientInGame(i))
1.343 - {
1.344 - clients[total++] = i;
1.345 - }
1.346 - }
1.347 -
1.348 - if (!total)
1.349 - {
1.350 - return;
1.351 - }
1.352 -
1.353 - EmitSound(clients, total, sample, entity, channel,
1.354 - level, flags, volume, pitch, speakerentity,
1.355 - origin, dir, updatePos, soundtime);
1.356 -}
1.357 -
1.358 -/**
1.359 - * Converts an attenuation value to a sound level.
1.360 - * This function is from the HL2SDK.
1.361 - *
1.362 - * @param attn Attenuation value.
1.363 - * @return Integer sound level.
1.364 - */
1.365 -stock ATTN_TO_SNDLEVEL(Float:attn)
1.366 -{
1.367 - if (attn > 0.0)
1.368 - {
1.369 - return RoundFloat(50.0 + (20.0 / attn));
1.370 - }
1.371 - return 0;
1.372 -}