#include < amxmodx >
#include < amxmisc >
#define MUSIC_ACCESS ADMIN_IMMUNITY
enum _:g_mMusicArray
{
g_mName[ 32 ],
g_mAuthor[ 18 ],
g_mPath[ 64 ]
}
new g_szMusicFile[ 64 ], g_iSong[ 33 ], g_iToAll[ 33 ], Float:g_fVolume[ 33 ];
new Array:g_aSongs;
public plugin_init( )
{
register_plugin( "Music Menu", "v1.0", "XControlX" );
register_saycmd( "/music", "CmdMusicMenu", ADMIN_IMMUNITY, "- Open the music menu." );
register_saycmd( "/stop", "CmdStopMusic", ADMIN_IMMUNITY, "- Stop the music." );
}
public plugin_precache( )
{
g_aSongs = ArrayCreate( g_mMusicArray );
loadMusics( );
new music[ g_mMusicArray ];
for ( new i = 0; i < ArraySize( g_aSongs ) - 1; i++ )
{
ArrayGetArray( g_aSongs, i, music );
precache_sound( music[ g_mPath ] );
}
}
public plugin_end( )
{
ArrayDestroy( g_aSongs );
}
public client_connect( client )
{
g_iSong[ client ] = 0;
g_iToAll[ client ] = 0;
g_fVolume[ client ] = 0.5;
}
public CmdMusicMenu( client )
{
if ( ! is_user_connected( client ) ) return 1;
if ( ArraySize( g_aSongs ) <= 1 ) return ColorChat( client, "The server didn't load any song." );
new music[ g_mMusicArray ], item[ 50 ];
ArrayGetArray( g_aSongs, g_iSong[ client ], music );
new menu = menu_create( "\r[Music] \yMusic Menu^n\wChoose your options:", "CmdMusicHandler" );
new callback = menu_makecallback( "CmdMusicCallback" );
formatex( item, charsmax( item ), "\rSong: [\y%s\r]", music[ g_mName ] );
menu_additem( menu, item );
formatex( item, charsmax( item ), "\rAuthor: [\y%s\r]", music[ g_mAuthor ] );
menu_additem( menu, item, _, _, callback );
formatex( item, charsmax( item ), "\rVolume: [\y%.1f\r]", g_fVolume[ client ] );
menu_additem( menu, item );
formatex( item, charsmax( item ), "\rPlay To All: [\y%sable\r]", g_iToAll[ client ] ? "En" : "Dis" );
menu_additem( menu, item, _, _, callback );
menu_addblank( menu, 0 );
menu_additem( menu, "\rStart The Music" );
menu_setprop( menu, MPROP_EXIT, MEXIT_ALL );
menu_setprop( menu, MPROP_EXITNAME, "\rExit Music Menu" );
menu_setprop( menu, MPROP_NUMBER_COLOR, "\d" );
menu_display( client, menu, 0 );
return 1;
}
public CmdMusicCallback( client, menu, item )
{
switch ( item )
{
case 1: return ITEM_DISABLED;
case 3: return ( get_user_flags( client ) & MUSIC_ACCESS ) ? ITEM_ENABLED : ITEM_DISABLED;
}
return ITEM_ENABLED;
}
public CmdMusicHandler( client, menu, item )
{
if ( item != MENU_EXIT )
{
switch ( item )
{
case 0:
{
( g_iSong[ client ] >= ( ArraySize( g_aSongs ) - 1 ) ) ? ( g_iSong[ client ] = 0 ) : ( g_iSong[ client ] += 1 );
return CmdMusicMenu( client );
}
case 2:
{
( g_fVolume[ client ] > 1.0 ) ? ( g_fVolume[ client ] = 0.1 ) : ( g_fVolume[ client ] += 0.1 );
return CmdMusicMenu( client );
}
case 3:
{
if ( ! ( get_user_flags( client ) & MUSIC_ACCESS ) ) return CmdMusicMenu( client );
g_iToAll[ client ] = ! g_iToAll[ client ];
return CmdMusicMenu( client );
}
case 4:
{
new music[ g_mMusicArray ];
ArrayGetArray( g_aSongs, g_iSong[ client ], music );
( g_iToAll[ client ] ) ? client_cmd( 0, "mp3 play ^"sound/%s^"", music[ g_mPath ] ) : client_cmd( client, "mp3 play ^"sound/%s^"", music[ g_mPath ] );
( g_iToAll[ client ] ) ? client_cmd( 0, "MP3Volume %.1f", g_fVolume[ client ] ) : client_cmd( client, "MP3Volume %.1f", g_fVolume[ client ] );
( g_iToAll[ client ] ) ? ColorChat( 0, "^x03 Admin %s^x01 has started the song^x03 ^"%s^"^x01, by^x03 ^"%s^"^x01.^x04 (Volume: %.1f)", GetUserName( client ), music[ g_mName ], music[ g_mAuthor ], g_fVolume[ client ] ) : ColorChat( client, "You have started the song^x03 ^"%s^"^x01, by^x03 ^"%s^"^x01.^x04 (Volume: %.1f)", music[ g_mName ], music[ g_mAuthor ], g_fVolume[ client ] );
}
}
}
menu_destroy( menu );
return 1;
}
public CmdStopMusic( client )
{
if ( ! is_user_connected( client ) ) return 1;
client_cmd( client, "mp3 stop" );
ColorChat( client, "You have^x03 stoped^x01 the music." );
return 1;
}
stock GetUserName( const index )
{
static name[ 32 ];
get_user_name( index, name, charsmax( name ) );
return name;
}
stock loadMusics( )
{
get_configsdir( g_szMusicFile, charsmax( g_szMusicFile ) );
add( g_szMusicFile, charsmax( g_szMusicFile ), "/MusicMenu.ini" );
if ( ! file_exists( g_szMusicFile ) )
{
write_file( g_szMusicFile, "; Music Menu By xControl" );
write_file( g_szMusicFile, "; ==================================================" );
write_file( g_szMusicFile, "; How to add a song to the menu:" );
write_file( g_szMusicFile, "; ^"music name^" ^"music author^" ^"music path^"" );
write_file( g_szMusicFile, "; ==================================================" );
}
new buffer[ 128 ], args[ g_mMusicArray ];
new file = fopen( g_szMusicFile, "rt" );
while ( ! feof( file ) )
{
fgets( file, buffer, charsmax( buffer ) );
remove_quotes( buffer );
if ( buffer[ 0 ] == ';' || equali( buffer, "//", 2 ) || strlen( buffer ) < 5 ) continue;
parse( buffer, args[ g_mName ], charsmax( args[ g_mName ] ), args[ g_mAuthor ], charsmax( args[ g_mAuthor ] ), args[ g_mPath ], charsmax( args[ g_mPath ] ) );
new song[ 64 ];
formatex( song, charsmax( song ), "sound/%s", args[ g_mPath ] );
if ( ! file_exists( song ) )
{
log_amx( "Can't load song %s by %s (%s)", args[ g_mName ], args[ g_mAuthor ], song );
continue;
}
ArrayPushArray( g_aSongs, args );
}
fclose( file );
( ArraySize( g_aSongs ) < 1 ) ? log_amx( "Can't load any song from file." ) : log_amx( "Successfuly loaded %i songs from file.", ArraySize( g_aSongs ) );
}
stock register_saycmd( command[ ], function[ ], flags, description[ ] )
{
new signs[ ] = { "/", "!", "." };
new types[ ] = { "say", "say_team" };
new temp[ 64 ];
for ( new i = 0; i < sizeof( signs ); i++ )
{
for ( new j = 0; j < sizeof( types ); j++ )
{
formatex( temp, charsmax( temp ), "%s %s%s", types[ j ], signs[ i ], command );
register_clcmd( temp, function, flags, description );
}
}
}
stock ColorChat( const iPlayer, const szMsg[ ], { Float, Sql, Resul, _ } : ... )
{
new iMsg[ 191 ], iPlayers[ 32 ], iCount = 1;
static iLen;
iLen = formatex( iMsg, charsmax( iMsg ), "^x04[Music]^x01 " );
vformat( iMsg[ iLen ], charsmax( iMsg ) - iLen, szMsg, 3 );
if ( iPlayer )
iPlayers[ 0 ] = iPlayer;
else
get_players( iPlayers, iCount, "ch" );
for ( new i = 0; i < iCount; i++ )
{
if ( ! is_user_connected( iPlayers[ i ] ) )
continue;
message_begin( MSG_ONE_UNRELIABLE, get_user_msgid( "SayText" ), _, iPlayers[ i ] );
write_byte( iPlayers[ i ] );
write_string( iMsg );
message_end( );
}
return 1;
}
/* AMXX-Studio Notes - DO NOT MODIFY BELOW HERE
*{\\ rtf1\\ fbidis\\ ansi\\ ansicpg1252\\ deff0{\\ fonttbl{\\ f0\\ fnil\\ fcharset0 Tahoma;}}\n\\ viewkind4\\ uc1\\ pard\\ ltrpar\\ lang1037\\ f0\\ fs16 \n\\ par }
*/