#include <amxmodx>
#include <reapi>
enum _:PCVAR
{
ISOUND,
TOGGLE
}
new g_pCvar[PCVAR], bool:g_bToggle[MAX_PLAYERS + 1], g_iOldNum;
new szSound[] = "sound/gm_plugins/roundsound/num";
public plugin_init()
{
register_plugin("[GM] Round Sound", "0.0.1", "[GM] NWC");
register_dictionary("gm_roundsound.txt");
register_clcmd("say /music", "Music");
register_clcmd("say_team /music", "Music");
bind_pcvar_num(create_cvar("roundsound_toggle", "1", FCVAR_NONE, "Ability to turn off music", true, 0.0, true, 1.0), g_pCvar[TOGGLE]);
AutoExecConfig(true, "roundsound", "gm_plugins");
RegisterHookChain(RG_RoundEnd, "RG_RoundEnd_Pre", false);
}
public plugin_precache()
{
bind_pcvar_num(create_cvar("roundsound_qty", "15", FCVAR_NONE, "Number of songs to play", true, 1.0), g_pCvar[ISOUND]);
for(new i = 1; i <= g_pCvar[ISOUND]; i++)
{
precache_generic(fmt("%s%i.mp3", szSound, i));
}
}
public RG_RoundEnd_Pre(WinStatus:status, ScenarioEventEndRound:event, Float:tmDelay)
{
if(status != WINSTATUS_NONE && status != WINSTATUS_DRAW)
{
new i = random_num(1, g_pCvar[ISOUND]);
while(i == g_iOldNum)
{
i = random_num(1, g_pCvar[ISOUND]);
}
g_iOldNum = i;
for(new id = 1; id <= MaxClients; id++)
{
if(g_bToggle[id])
{
client_cmd(id, "mp3 play %s%i.mp3", szSound, i);
}
}
}
return HC_CONTINUE;
}
public Music(id)
{
if(g_pCvar[TOGGLE])
{
(g_bToggle[id]) ? (g_bToggle[id] = false, client_print_color(id, -2, "%L %L", -1, "ROUNDSOUND_PREFIX", -1, "ROUNDSOUND_DISABLED")) : (g_bToggle[id] = true, client_print_color(id, -3, "%L %L", -1, "ROUNDSOUND_PREFIX", -1, "ROUNDSOUND_ENABLED"));
}
return PLUGIN_HANDLED;
}
public client_connect(id)
{
g_bToggle[id] = true;
}
public client_disconnected(id)
{
if(!g_bToggle[id])
{
g_bToggle[id] = true;
}
}