PHP Code:
#include < amxmodx >
#include < amxmisc >
#include < colorchat >
#define b_PLUGIN "Advanced Music Player"
#define b_VERSION "1.4"
#define b_AUTHOR "Baws"
#define MAX_SONGS 5000
new bSongId;
new bLastSong, bSongCount;
new bMusicPlayer[ 1536 ];
new b_Song_Names[ MAX_SONGS ][ 64 ];
new b_Song_Links[ MAX_SONGS ][ 512 ];
new bLastMusic[ 33 ];
public plugin_init( )
{
register_plugin( b_PLUGIN, b_VERSION, b_AUTHOR );
register_cvar( b_PLUGIN, b_VERSION, FCVAR_SERVER | FCVAR_EXTDLL | FCVAR_UNLOGGED | FCVAR_SPONLY );
register_clcmd( "say", "Cmd_Say" );
register_clcmd( "say_team", "Cmd_Say" );
register_concmd( "amx_addsong", "b_AddSong", ADMIN_CFG, "- Usage: <song name> <song url/link> | Attention: Instead of < > use quotes." );
register_concmd( "amx_reloadsong", "b_ReloadSongList", ADMIN_CFG, "- Reload's the songlist.ini file." );
bInitialize( );
}
public client_putinserver( id )
{
bLastMusic[ id ] = 0;
}
public b_AddSong( id, level, cid )
{
if( !cmd_access( id, level, cid, 3 ) )
return PLUGIN_HANDLED_MAIN;
new bSongName[ 33 ], bSongLink[ 256 ]
read_argv( 1, bSongName, charsmax( bSongName ) )
read_argv( 2, bSongLink, charsmax( bSongLink ) )
copy( b_Song_Names[ bSongId ], charsmax( b_Song_Names[ ] ), bSongName )
copy( b_Song_Links[ bSongId++ ], charsmax( b_Song_Links[ ] ), bSongLink )
new bConfigDir[ 128 ], bFile[ 128 ]
get_localinfo( "amxx_configsdir", bConfigDir, charsmax( bConfigDir ) )
formatex( bFile, charsmax( bFile ), "%s/%s", bConfigDir, "songlist.ini" )
if( file_exists( bFile ) )
{
new bText[ 512 ]
formatex( bText, charsmax( bText ), "^n^"%s^" ^"%s^"", bSongName, bSongLink )
write_file( bFile, bText )
console_print( id, "* Added %s to songlist.ini *", bSongName )
}
return PLUGIN_HANDLED_MAIN;
}
public b_ReloadSongList( id, level, cid )
{
if( !cmd_access( id, level, cid, 1 ) )
return PLUGIN_HANDLED_MAIN;
bInitialize( )
console_print( id, "* songlist.ini file has been successfully reloaded *" )
return PLUGIN_HANDLED_MAIN;
}
public Cmd_Say( id )
{
static bSaid[ 192 ], bBaws;
read_args( bSaid, 191 );
remove_quotes( bSaid );
if( equali( bSaid,"/",1 ) ) bBaws = 1;
else bBaws = 0;
new bFirstMsg[ 21 ], bAllied[ 2 ];
strbreak( bSaid[ bBaws ], bFirstMsg, 20, bAllied, 1 )
if( equali( bFirstMsg, "music" ) )
{
SongList( id );
return PLUGIN_HANDLED_MAIN
}
else if( equali( bFirstMsg, "stop" ) )
{
static bMotd[ 1024 ], bLen;
bLen = formatex( bMotd, charsmax( bMotd ), "<html><head><style type=^"text/css^">pre{color:#FFB000;}body{background:#000000;margin-left:8px;margin-top:0px;}</style></head><pre><body>" )
bLen += formatex( bMotd[ bLen ], charsmax( bMotd ) - bLen, "<center>Music Stopped. This has been brought you by %s.^n", b_PLUGIN )
bLen += formatex( bMotd[ bLen ], charsmax( bMotd ) - bLen, "<center>Hope you had fun listening to the nice music!^n" )
bLen += formatex( bMotd[ bLen ], charsmax( bMotd ) - bLen, "</body></pre></html>^n" )
show_motd( id, bMotd, b_PLUGIN )
return PLUGIN_HANDLED_MAIN;
}
else if( equali( bFirstMsg, "replay" ) )
{
if( bLastMusic[ id ] != 0 )
{
bPlay_Song( id, bLastMusic[ id ] );
}
else
{
ColorChat( id, GREEN,"^x01You have not played any song yet." );
}
return PLUGIN_HANDLED_MAIN;
}
else if( equali( bFirstMsg, "copy" ) )
{
Cmd_CopySong( id );
return PLUGIN_HANDLED_MAIN;
}
else if( equali( bFirstMsg, "search" ) )
{
new bLeft[ 151 ], bRight[ 151 ]
strbreak( bSaid[ bBaws ], bLeft, 150, bRight, 150 )
strbreak( bRight, bLeft, 150, bRight, 150 )
Cmd_Search( id, bLeft );
return PLUGIN_HANDLED_MAIN;
}
return PLUGIN_CONTINUE;
}
public SongList( id )
{
new bMenu = menu_create( "\yChoose a song to play:\r", "SongList_Handler" )
for( new i = 1; i < bSongCount; i++ )
{
new bNum[ 3 ];
num_to_str( i, bNum, 2 );
menu_additem( bMenu, b_Song_Names[ i ], bNum );
}
menu_display( id, bMenu );
return PLUGIN_HANDLED;
}
public SongList_Handler( id, bMenu, item )
{
if( item == MENU_EXIT )
{
menu_destroy( bMenu );
return PLUGIN_HANDLED;
}
new bData[ 6 ], bName[ 64 ];
new access, callback;
menu_item_getinfo( bMenu, item, access, bData, charsmax( bData ), bName, charsmax( bName ), callback );
new bChoice = str_to_num( bData );
bPlay_Song( id, bChoice );
return PLUGIN_HANDLED;
}
public Cmd_Search( id, bSearch[ ] )
{
ColorChat( id, GREEN, "^x01You searched for '^x04%s^x01'^x04.", bSearch )
new bSearchMenu = menu_create( "\ySearching Results:\r", "SongList_Handler" )
new bNum[ 3 ];
for( new i = 1; i <= bSongCount; i++ )
{
if( containi( b_Song_Names[ i ], bSearch ) != -1 )
{
num_to_str( i, bNum, 2 );
menu_additem( bSearchMenu, b_Song_Names[ i ], bNum );
}
}
menu_display( id, bSearchMenu );
return PLUGIN_HANDLED;
}
public Cmd_CopySong( id )
{
bPlay_Song( id, bLastSong );
}
bPlay_Song( id, key )
{
if( !file_exists( bMusicPlayer ) )
return;
new bPlayer[ sizeof( bMusicPlayer ) ], bMotd[ sizeof( bMusicPlayer ) ], bLine, bLength
while( read_file( bMusicPlayer, bLine++, bPlayer, charsmax( bPlayer ), bLength ) )
add( bMotd, charsmax( bMotd ), bPlayer )
replace_all( bMotd, charsmax( bMotd ), "[MEDIA_NAME]", b_Song_Names[ key ] )
replace_all( bMotd, charsmax( bMotd ), "[MEDIA_URL]", b_Song_Links[ key ] )
show_motd( id, bMotd, b_PLUGIN )
new bName[ 32 ];
get_user_name( id, bName, 31 )
ColorChat( 0, GREEN, "^x03%s ^x01is now listening to ^x04%s^x01. Type ^x04/copy ^x01to copy his song.", bName, b_Song_Names[ key ] )
bLastSong = key
bLastMusic[ id ] = key
}
public bInitialize( )
{
new bConfigDir[ 128 ], bFile[ 128 ], bFileText[ 2048 ], bLen = 0;
get_localinfo( "amxx_configsdir", bConfigDir, charsmax( bConfigDir ) )
formatex( bFile, charsmax( bFile ), "%s/%s", bConfigDir, "songlist.ini" )
if( !file_exists( bFile ) )
{
bLen = format( bFileText, charsmax( bFileText ), "; %s Songs^n", b_PLUGIN )
bLen += format( bFileText[ bLen ], charsmax( bFileText ) - bLen, "; Format: ^"Song Name^" ^"Song Url/Link^"^n" )
bLen += format( bFileText[ bLen ], charsmax( bFileText ) - bLen, "; eg. ^"Eminem - Mockingbird^" ^"http://www.youtube.com/watch?v=S9bCLPwzSC0^n^"" )
write_file( bFile, bFileText )
}
formatex( bMusicPlayer, charsmax( bMusicPlayer ), "%s/%s", bConfigDir, "AdvMusicPlayer.html" ); bLen = 0
bSongCount = 1;
new bText[ 1024 ], bLine, bLength
while( read_file( bFile, bLine++, bText, charsmax( bText ), bLength ) )
{
trim( bText )
if( !bLength || bText[ 0 ] == ';' )
continue;
if( bSongCount > MAX_SONGS )
break;
static bLeft[ 32 ], bRight[ 512 ]
strbreak( bText, bLeft, charsmax( bLeft ), bRight, charsmax( bRight ) )
replace_all( bLeft, charsmax( bLeft ), "^"", "" )
replace_all( bRight, charsmax( bRight), "^"", "" )
replace_all( bRight, charsmax( bRight ), " ", "%20" )
copy( b_Song_Names[ bSongCount ], charsmax( b_Song_Names[ ] ), bLeft )
copy( b_Song_Links[ bSongCount ], charsmax( b_Song_Links[ ] ), bRight )
bSongCount++
}
}