The result of some researches:
Joining a server and downloading new *.mp3 will not make them working immidiately. You need to restart CS:GO. Probably something like "snd_rebuildaudiocache" (what has been removed some weeks ago) would help.
Is there a way to make it possible to play custom sounds directly after the are downloaded?
Here is the current code I am using:
Code:
#include <sourcemod>
#include <emitsoundany>
#define MAX_FILE_LEN 80
Handle g_CvarSound = INVALID_HANDLE;
char g_soundsound[MAX_FILE_LEN];
public void OnPluginStart()
{
SoundFilespluginStart();
AutoExecConfig(true, "testsound");
RegConsoleCmd("sm_testsound", Command_Sound);
}
public void SoundFilespluginStart()
{
g_CvarSound = CreateConVar("sound", "Sound.mp3", "Sound");
}
public void OnMapStart()
{
precache_sounds();
}
public void precache_sounds()
{
GetConVarString(g_CvarSound, g_soundsound, MAX_FILE_LEN);
char buffer[MAX_FILE_LEN];
PrecacheSoundAny(g_soundsound, true);
Format(buffer, sizeof(buffer), "sound/%s", g_soundsound);
AddFileToDownloadsTable(buffer);
}
public Action Command_Sound(int client, int args)
{
CreateTimer(0.1,PlaySound);
return Plugin_Handled;
}
public Action PlaySound(Handle timer)
{
float volume=0.3;
for(int client=1; client<MAXPLAYERS; client++)
{
if(IsClientInGame(client) && !IsFakeClient(client))
EmitSoundToClientAny(client,g_soundsound,SOUND_FROM_PLAYER, SNDCHAN_AUTO, SNDLEVEL_NORMAL, SND_NOFLAGS, volume, SNDPITCH_NORMAL, -1, NULL_VECTOR, NULL_VECTOR, true,0.0);
}
}