From 98e049b336c3ef896f6962b6495df106da59daea Mon Sep 17 00:00:00 2001 From: javalia Date: Sat, 3 Sep 2011 14:18:08 -0400 Subject: [PATCH] Added GetDistGainFromSoundLevel native to SDKTools (bug 5066, r=dvander). --- extensions/sdktools/vsound.cpp | 9 +++++++++ plugins/include/sdktools_sound.inc | 9 +++++++++ 2 files changed, 18 insertions(+) diff --git a/extensions/sdktools/vsound.cpp b/extensions/sdktools/vsound.cpp index 70c7274b..a9476a6e 100644 --- a/extensions/sdktools/vsound.cpp +++ b/extensions/sdktools/vsound.cpp @@ -782,6 +782,14 @@ static cell_t smn_RemoveNormalSoundHook(IPluginContext *pContext, const cell_t * return 1; } +static cell_t smn_GetDistGainFromSoundLevel(IPluginContext *pContext, const cell_t *params) +{ + int decibel = params[1]; + float distance = sp_ctof(params[2]); + + return sp_ftoc(engsound->GetDistGainFromSoundLevel(soundlevel_t)decibel, distance)); +} + sp_nativeinfo_t g_SoundNatives[] = { {"EmitAmbientSound", EmitAmbientSound}, @@ -795,5 +803,6 @@ sp_nativeinfo_t g_SoundNatives[] = {"AddNormalSoundHook", smn_AddNormalSoundHook}, {"RemoveAmbientSoundHook", smn_RemoveAmbientSoundHook}, {"RemoveNormalSoundHook", smn_RemoveNormalSoundHook}, + {"GetDistGainFromSoundLevel", smn_GetDistGainFromSoundLevel}, {NULL, NULL}, }; diff --git a/plugins/include/sdktools_sound.inc b/plugins/include/sdktools_sound.inc index 34c16967..87837408 100644 --- a/plugins/include/sdktools_sound.inc +++ b/plugins/include/sdktools_sound.inc @@ -257,6 +257,15 @@ native EmitSentence(const clients[], bool:updatePos = true, Float:soundtime = 0.0, any:...); + +/** + *Calculates gain of sound on given distance with given sound level in decibel + * + * @param soundlevel decibel of sound, like SNDLEVEL_NORMAL or integer value + * @param distance distance of sound to calculate, not meter or feet, but Source Engine`s normal Coordinate unit + * @return gain of sound. you can multiply this with original sound`s volume to calculate volume on given distance + */ +native Float:GetDistGainFromSoundLevel(soundlevel, Float:distance); /** * Called when an ambient sound is about to be emitted to one or more clients.