/* Plugin generated by AMXX-Studio */
#include <amxmodx>
#include <amxmisc>
#include <colorchat>
#include <hamsandwich>
#define PLUGIN "[RS] Round Sound"
#define VERSION "1.0S"
#define AUTHOR "VCL/sonyx"
#pragma semicolon 1
new Array:g_aTrackNames;
new Array:g_aTrackPaths;
new pMenuStyle = 0;
public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR);
register_logevent("leRoundEnd",2,"1=Round_End");
register_dictionary("round_sound.txt");
pMenuStyle = register_cvar("rs_menu_style","1");
register_clcmd("say /soundmenu","Show_SoundMenu");
register_clcmd("say_team /soundmenu","Show_SoundMenu");
register_menucmd(register_menuid("Show_SoundMenu"), (1<<0|1<<1|1<<2|1<<9), "Handle_SoundMenu");
RegisterHam(Ham_Spawn,"player","hamPlayerSpawnPost",1);
}
new iSpawnsCount[33];
public hamPlayerSpawnPost(id)
{
if(!(++iSpawnsCount[id]>1))
{
set_task(10.0,"Show_SoundMenu",id);
}
}
public plugin_precache()
{
g_aTrackNames = ArrayCreate(256,10);
g_aTrackPaths = ArrayCreate(256,10);
LoadSettings();
}
#define get_bit(%1,%2) ( %1 & 1 << ( %2 & 31 ) )
#define set_bit(%1,%2) %1 |= ( 1 << ( %2 & 31 ) )
#define clear_bit(%1,%2) %1 &= ~( 1 << ( %2 & 31 ) )
new iSoundPlayers = 0;
public Show_SoundMenu(id)
{
if(!is_user_connected(id)) return PLUGIN_CONTINUE;
new iStyle = get_pcvar_num(pMenuStyle);
new szMenu[512];
new iLen = formatex(szMenu, charsmax(szMenu), "\y%L^n", LANG_PLAYER, "RS_MENU_TITLE");
iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, iStyle==1 ? "\y[1] \w%L^n" : "\w1. %L^n", LANG_PLAYER, "RS_MENU_YES");
iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, iStyle==1 ? "\y[2] \w%L^n" : "\w2. %L^n", LANG_PLAYER, "RS_MENU_NO");
iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, iStyle==1 ? "\y[3] \w%L^n" : "\w3. %L^n", LANG_PLAYER, "RS_MENU_ON_MUSIC");
formatex(szMenu[iLen], charsmax(szMenu) - iLen, iStyle==1 ? "^n\y[0] \w%L" : "^n\w0. %L", id, "RS_MENU_EXIT");
return show_menu(id, (1<<0|1<<1|1<<2|1<<9), szMenu, -1, "Show_SoundMenu");
}
public Handle_SoundMenu(id,iKey)
{
switch(iKey)
{
case 0:
{
set_bit(iSoundPlayers,id);
ColorChat(id,RED,"%L",LANG_PLAYER,"RS_MENU_CHAT_MSG_YES");
}
case 1:
{
clear_bit(iSoundPlayers,id);
client_cmd(id,"mp3 stop");
ColorChat(id,RED,"%L",LANG_PLAYER,"RS_MENU_CHAT_MSG_NO");
}
case 2:
{
client_cmd(id,"MP3Volume 3");
ColorChat(id,RED,"%L",LANG_PLAYER,"RS_MENU_CHAT_MSG_ON_MUSIC");
Show_SoundMenu(id);
}
}
return PLUGIN_HANDLED;
}
new iTrackListSize = 0;
public LoadSettings()
{
new szIniFile[256];
get_configsdir(szIniFile,charsmax(szIniFile));
format(szIniFile,charsmax(szIniFile),"%s%s",szIniFile,"/round_sound.ini");
new szTempBuffer[512];
new szTrackName[256],szTrackPath[256];
new hFile = fopen(szIniFile,"rt");
if(!hFile)
log_to_error("Cannot open file %s",szIniFile);
while(!feof(hFile))
{
fgets(hFile,szTempBuffer,charsmax(szTempBuffer));
new iParseCount = parse(szTempBuffer,szTrackName,charsmax(szTrackName),szTrackPath,charsmax(szTrackPath));
if(iParseCount==2)
{
trim(szTrackName);
trim(szTrackPath);
if(strlen(szTrackPath)>0 && strlen(szTrackName)>0)
{
ArrayPushString(g_aTrackNames,szTrackName);
ArrayPushString(g_aTrackPaths,szTrackPath);
log_amx("Add %s // %s", szTrackName, szTrackPath);
precache_sound(szTrackPath);
}
}
else
{
log_to_error("Error reading INI File");
log_to_error(" Track Name:%s",szTrackName);
log_to_error(" Track Path:%s",szTrackPath);
}
}
fclose(hFile);
iTrackListSize = ArraySize(g_aTrackNames);
for(new i = 0; i < iTrackListSize; i++)
{
new iRand = random_num(0,iTrackListSize-1);
ArraySwap(g_aTrackNames,i,iRand);
ArraySwap(g_aTrackPaths,i,iRand);
log_amx("Change %d to %d", i, iRand);
}
}
new iTrackNum = 0;
public leRoundEnd()
{
iTrackNum = ((iTrackNum+1)>=iTrackListSize) ? 0 : iTrackNum+1;
new szTrackName[256],szTrackPath[256];
log_amx("-|Try on %d", iTrackNum);
ArrayGetString(g_aTrackNames,iTrackNum,szTrackName,charsmax(szTrackName));
ArrayGetString(g_aTrackPaths,iTrackNum,szTrackPath,charsmax(szTrackPath));
log_amx("-|File %s // %s", szTrackName, szTrackPath);
new aPlayers[32],iCount;
get_players(aPlayers,iCount,"c");
for(new i = 0;i<iCount;i++)
{
new id = aPlayers[i];
if(!get_bit(iSoundPlayers,id)) continue;
ColorChat(id,RED,"%L",LANG_PLAYER,"RS_CHAT_MSG_PLAYING",szTrackName);
client_cmd(id,"mp3 play sound/%s",szTrackPath);
}
}
public client_connect(id)
{
clear_bit(iSoundPlayers,id);
iSpawnsCount[id]=0;
}
stock log_to_error(const message[], any:...)
{
new log[256], date[32], Map[32];
vformat(log, 255, message, 2);
get_time("error_%Y%m%d.log", date, 31);
get_mapname(Map, 31);
log_to_file(date, "[%s] %s", "Round Sound", log);
}