How can I determine the filename of the mp3 sound currently being played?
How can I determine the channel of the mp3 sound currently being played?
How can I stop the mp3 sound currently being played?
Issue: I'm using the excellent Saysounds (Redux) plugin
https://forums.alliedmods.net/showth...2240969http:// developed by friagram. I would like to stop a lengthy sound file on command.
I put together the very inefficient code below, but it does not stop sounds played using Saysounds. However, it will stop sounds played using the console command sm_playsnd "filename.mp3"
Friagrams play code:
Code:
DoSaySound(String:soundfile[], Float:volume)
{
for(new target = 1; target<=MaxClients; target++)
{
if(IsClientInGame(target) && !g_clientprefs[target][SAYSOUND_PREF_DISABLED])
{
if(gb_playingame)
{
if(volume > 1.0)
{
volume *= 0.5;
EmitSoundToClient(target, soundfile, .volume = volume);
EmitSoundToClient(target, soundfile, .volume = volume);
}
else
{
EmitSoundToClient(target, soundfile, .volume = volume);
}
}
else
{
if(volume >= 2.0)
{
ClientCommand(target, "playgamesound \"%s\";playgamesound \"%s\"", soundfile,soundfile);
}
else
{
ClientCommand(target, "playgamesound \"%s\"",soundfile);
}
}
}
}
}
My horribly ineffecient plugin to stop sounds. I have around 50 sounds:
Code:
#include <sdktools>
#pragma semicolon 1
public Plugin myinfo =
{
name = "Stop Sound",
author = "PC Gamer",
description = "Stops the currently playing sound",
version = "PLUGIN_VERSION 1.0",
url = "www.sourcemod.com"
}
public OnPluginStart()
{
RegAdminCmd("sm_stopsound", Command_killsound, ADMFLAG_SLAY, "Stop Sound");
}
public Action Command_killsound(client, args)
{
for (int i = 1; i <= MaxClients; i++)
if (IsClientInGame(i) && !IsFakeClient(i))
{
StopSoundPerm(i, "/ui/gamestartup24.mp3");
StopSoundPerm(i, "/ui/gamestartup1.mp3");
StopSoundPerm(i, "/custom/mysong1.mp3");
StopSoundPerm(i, "/custom/mysong2.mp3");
StopSoundPerm(i, "/custom/someothersong.mp3");
StopSoundPerm(i, "/custom/yetanothersound.mp3");
ClientCommand(i, "playgamesound Music.StopAllExceptMusic");
ClientCommand(i, "playgamesound Music.StopAllMusic");
}
return Plugin_Handled;
}
//Stop Sound from all Channels:
stock StopSoundPerm(Client, String:sound[])
{
//Stop Sound:
StopSound(Client, SNDCHAN_AUTO, sound);
StopSound(Client, SNDCHAN_WEAPON, sound);
StopSound(Client, SNDCHAN_VOICE, sound);
StopSound(Client, SNDCHAN_ITEM, sound);
StopSound(Client, SNDCHAN_BODY, sound);
StopSound(Client, SNDCHAN_STREAM, sound);
StopSound(Client, SNDCHAN_VOICE_BASE, sound);
StopSound(Client, SNDCHAN_USER_BASE, sound);
}