Updated license headers on virtually all files with extremely minor changes in the name of some sort of strange consistency.
All plugin and include file headers also have been changed to say about GPL3 instead of GPL2.
(This day shall henceforth be known as the Eighty Column Massacre of '07)
3 * =============================================================================
4 * SourceMod SDKTools Extension
5 * Copyright (C) 2004-2007 AlliedModders LLC. All rights reserved.
6 * =============================================================================
8 * This program is free software; you can redistribute it and/or modify it under
9 * the terms of the GNU General Public License, version 3.0, as published by the
10 * Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
17 * You should have received a copy of the GNU General Public License along with
18 * this program. If not, see <http://www.gnu.org/licenses/>.
20 * As a special exception, AlliedModders LLC gives you permission to link the
21 * code of this program (as well as its derivative works) to "Half-Life 2," the
22 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
23 * by the Valve Corporation. You must obey the GNU General Public License in
24 * all respects for all other code used. Additionally, AlliedModders LLC grants
25 * this exception to all derivative works. AlliedModders LLC defines further
26 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
27 * or <http://www.sourcemod.net/license.php>.
32 #include "extension.h"
33 #include "CellRecipientFilter.h"
35 static cell_t PrefetchSound(IPluginContext *pContext, const cell_t *params)
38 pContext->LocalToString(params[1], &name);
40 engsound->PrefetchSound(name);
45 static cell_t GetSoundDuration(IPluginContext *pContext, const cell_t *params)
48 pContext->LocalToString(params[1], &name);
50 return sp_ftoc(engsound->GetSoundDuration(name));
53 static cell_t EmitAmbientSound(IPluginContext *pContext, const cell_t *params)
59 int pitch, flags, level;
64 pContext->LocalToPhysAddr(params[2], &addr);
65 pos.x = sp_ctof(addr[0]);
66 pos.y = sp_ctof(addr[1]);
67 pos.z = sp_ctof(addr[2]);
69 pContext->LocalToString(params[1], &name);
71 vol = sp_ctof(params[6]);
75 delay = sp_ctof(params[8]);
77 engine->EmitAmbientSound(entity, pos, name, vol, (soundlevel_t)level, flags, pitch, delay);
82 static cell_t FadeClientVolume(IPluginContext *pContext, const cell_t *params)
84 int client = params[1];
85 if (client < 1 || client > playerhelpers->GetMaxClients())
87 return pContext->ThrowNativeError("Client index %d is not valid", client);
90 IGamePlayer *player = playerhelpers->GetGamePlayer(client);
91 if (!player->IsInGame())
93 return pContext->ThrowNativeError("Client index %d is not in game", client);
96 engine->FadeClientVolume(player->GetEdict(),
105 static cell_t StopSound(IPluginContext *pContext, const cell_t *params)
107 int entity = params[1];
108 int channel = params[2];
111 pContext->LocalToString(params[3], &name);
113 engsound->StopSound(entity, channel, name);
118 static cell_t EmitSound(IPluginContext *pContext, const cell_t *params)
120 cell_t *addr, *pl_addr;
122 CellRecipientFilter crf;
123 pContext->LocalToPhysAddr(params[1], &pl_addr);
124 crf.Initialize(pl_addr, params[2]);
127 pContext->LocalToString(params[3], &sample);
129 int entity = params[4];
130 int channel = params[5];
131 int level = params[6];
132 int flags = params[7];
133 float vol = sp_ctof(params[8]);
134 int pitch = params[9];
135 int speakerentity = params[10];
137 Vector *pOrigin = NULL, origin;
138 Vector *pDir = NULL, dir;
140 pContext->LocalToPhysAddr(params[11], &addr);
141 if (addr != pContext->GetNullRef(SP_NULL_VECTOR))
144 origin.x = sp_ctof(addr[0]);
145 origin.y = sp_ctof(addr[1]);
146 origin.z = sp_ctof(addr[2]);
149 pContext->LocalToPhysAddr(params[12], &addr);
150 if (addr != pContext->GetNullRef(SP_NULL_VECTOR))
153 dir.x = sp_ctof(addr[0]);
154 dir.y = sp_ctof(addr[1]);
155 dir.z = sp_ctof(addr[2]);
158 bool updatePos = params[13] ? true : false;
159 float soundtime = sp_ctof(params[14]);
161 CUtlVector<Vector> *pOrigVec = NULL;
162 CUtlVector<Vector> origvec;
166 for (cell_t i = 15; i <= params[0]; i++)
169 pContext->LocalToPhysAddr(params[i], &addr);
170 vec.x = sp_ctof(addr[0]);
171 vec.y = sp_ctof(addr[1]);
172 vec.z = sp_ctof(addr[2]);
173 origvec.AddToTail(vec);
177 /* If we're going to a "local player" and this is a dedicated server,
178 * intelligently redirect each sound.
181 if (entity == -2 && engine->IsDedicatedServer())
183 for (cell_t i=0; i<params[2]; i++)
186 player[0] = pl_addr[i];
188 crf.Initialize(player, 1);
189 engsound->EmitSound(crf,
205 engsound->EmitSound(crf,
224 static cell_t EmitSentence(IPluginContext *pContext, const cell_t *params)
228 CellRecipientFilter crf;
229 pContext->LocalToPhysAddr(params[1], &addr);
230 crf.Initialize(addr, params[2]);
232 int sentence = params[3];
233 int entity = params[4];
234 int channel = params[5];
235 int level = params[6];
236 int flags = params[7];
237 float vol = sp_ctof(params[8]);
238 int pitch = params[9];
239 int speakerentity = params[10];
241 Vector *pOrigin = NULL, origin;
242 Vector *pDir = NULL, dir;
244 pContext->LocalToPhysAddr(params[11], &addr);
245 if (addr != pContext->GetNullRef(SP_NULL_VECTOR))
248 origin.x = sp_ctof(addr[0]);
249 origin.y = sp_ctof(addr[1]);
250 origin.z = sp_ctof(addr[2]);
253 pContext->LocalToPhysAddr(params[12], &addr);
254 if (addr != pContext->GetNullRef(SP_NULL_VECTOR))
257 dir.x = sp_ctof(addr[0]);
258 dir.y = sp_ctof(addr[1]);
259 dir.z = sp_ctof(addr[2]);
262 bool updatePos = params[13] ? true : false;
263 float soundtime = sp_ctof(params[14]);
265 CUtlVector<Vector> *pOrigVec = NULL;
266 CUtlVector<Vector> origvec;
270 for (cell_t i = 15; i <= params[0]; i++)
273 pContext->LocalToPhysAddr(params[i], &addr);
274 vec.x = sp_ctof(addr[0]);
275 vec.y = sp_ctof(addr[1]);
276 vec.z = sp_ctof(addr[2]);
277 origvec.AddToTail(vec);
281 engsound->EmitSentenceByIndex(crf,
299 sp_nativeinfo_t g_SoundNatives[] =
301 {"EmitAmbientSound", EmitAmbientSound},
302 {"EmitSentence", EmitSentence},
303 {"EmitSound", EmitSound},
304 {"FadeClientVolume", FadeClientVolume},
305 {"GetSoundDuration", GetSoundDuration},
306 {"PrefetchSound", PrefetchSound},
307 {"StopSound", StopSound},