#include < amxmodx >
#include < amxmisc >
#define TASK_ID_CMSG 2000
new const g_szPlugin[ ] = "Advanced Music Player";
new const g_szVersion[ ] = "1.5";
new const g_szAuthor[ ] = "Baws";
enum Color
{
NORMAL = 1,
GREEN,
TEAM_COLOR,
GREY,
RED,
BLUE,
};
new SongId;
new LastSong, SongCount;
new g_MusicPlayer[ 1206 ];
new g_Song_Names[ MaxSongs ][ 64 ];
new g_Song_Links[ MaxSongs ][ 512 ];
new g_LastMusic[ 33 ];
new Array:MaxSongs;
new PcvarConnectMsg;
public plugin_init( )
{
register_plugin( g_szPlugin, g_szVersion, g_szAuthor );
register_cvar( g_szPlugin, g_szVersion, FCVAR_SERVER | FCVAR_EXTDLL | FCVAR_UNLOGGED | FCVAR_SPONLY );
register_clcmd( "say", "Cmd_Say" );
register_clcmd( "say_team", "Cmd_Say" );
register_concmd( "amx_addsong", "AddSong", ADMIN_CFG, "- Usage: <song name> <song url/link> | Attention: Instead of < > use quotes." );
register_concmd( "amx_reloadfile", "ReloadSongList", ADMIN_CFG, "- Reload's the songlist.ini file." );
PcvarConnectMsg = register_cvar( "sv_connectmessage", "1" );
MaxSongs = ArrayCreate( x );
register_dictionary_colored( "AdvMusicPlayer.txt" );
Initialize( );
}
public client_putinserver( id )
{
g_LastMusic[ id ] = 0;
if( get_pcvar_num( PcvarConnectMsg ) == 1 )
set_task( 25.0, "ConnectMsg", id + TASK_ID_CMSG )
}
public ConnectMsg( id )
{
id -= TASK_ID_CMSG
if( get_pcvar_num( PcvarConnectMsg ) == 1 )
{
new szName[ 32 ];
get_user_name( id, szName, charsmax( szName ) )
client_print_color( id, NORMAL, "%L", szName, id, "CONNECT_MSG" )
}
}
public AddSong( id, level, cid )
{
if( !cmd_access( id, level, cid, 3 ) )
return PLUGIN_HANDLED;
new szSongName[ 36 ], szSongLink[ 256 ]
read_argv( 1, szSongName, charsmax( szSongName ) )
read_argv( 2, szSongName, charsmax( szSongLink ) )
copy( g_Song_Names[ SongId ], charsmax( g_Song_Names[ ] ), szSongName )
copy( g_Song_Links[ SongId++ ], charsmax( g_Song_Links[ ] ), szSongLink )
new iConfigDir[ 128 ], iFile[ 128 ]
get_localinfo( "amxx_configsdir", iConfigDir, charsmax( iConfigDir ) )
formatex( iFile, charsmax( iFile ), "%s/%s", iConfigDir, "songlist.ini" )
if( file_exists( iFile ) )
{
new iText[ 512 ]
formatex( iText, charsmax( iText ), "^n^"%s^" ^"%s^"", szSongName, szSongLink )
write_file( iFile, iText )
console_print( id, "%L", szSongName, id, "SONG_ADDED" )
}
return PLUGIN_HANDLED;
}
public ReloadSongList( id, level, cid )
{
if( !cmd_access( id, level, cid, 1 ) )
return PLUGIN_HANDLED;
Initialize( )
console_print( id, "%L", id, "FILE_RELOADED" )
return PLUGIN_HANDLED;
}
public Cmd_Say( id )
{
static Said[ 192 ], Baws;
read_args( Said, 191 );
remove_quotes( Said );
if( equali( Said, "/", 1 ) ) Baws = 1;
else Baws = 0;
new szFirstMsg[ 21 ] //szAllied[ 2 ]; //strbreak( Said[ Baws ], szFirstMsg, 20, szAllied, 1 )
if( equali( szFirstMsg, "music" ) )
{
SongList( id );
return PLUGIN_HANDLED;
}
else if( equali( szFirstMsg, "stop" ) )
{
static Motd[ 1024 ], Len;
Len = formatex( Motd, charsmax( Motd ), "<html><head><style type=^"text/css^">pre{color:#FFB000;}body{background:#000000;margin-left:8px;margin-top:0px;}</style></head><pre><body>" )
Len += formatex( Motd[ Len], charsmax( Motd ) - Len, "<center><b>Music Stopped</b>." )
Len += formatex( Motd[ Len ], charsmax( Motd ) - Len, "<center>This has been brought you by %s.^n", g_szAuthor )
Len += formatex( Motd[ Len ], charsmax( Motd ) - Len, "<center>%s is the most powerful music player plugin ever!", g_szPlugin )
Len += formatex( Motd[ Len ], charsmax( Motd ) - Len, "<center>Hope you had fun listening to the nice music!^n" )
Len += formatex( Motd[ Len ], charsmax( Motd ) - Len, "</body></pre></html>^n" )
show_motd( id, Motd, g_szPlugin )
return PLUGIN_HANDLED;
}
else if( equali( szFirstMsg, "replay" ) )
{
if( g_LastMusic[ id ] != 0 )
{
Play_Song( id, g_LastMusic[ id ] );
}
else
{
client_print_color( id, NORMAL, "%L", id, "NO_SONG_PLAYED" );
}
return PLUGIN_HANDLED;
}
else if( equali( szFirstMsg, "copy" ) )
{
Cmd_CopySong( id );
return PLUGIN_HANDLED;
}
else if( equali( szFirstMsg, "search" ) )
{
new Left[ 151 ], Right[ 151 ];
parse( Said[ Baws ], Left, 150, Right, 150 ) //strbreak( Right, Left, 150, Right, 150 )
Cmd_Search( id, Left );
return PLUGIN_HANDLED;
}
return PLUGIN_CONTINUE;
}
public SongList( id )
{
new Menu = menu_create( "\yChoose a song to play:\r", "SongList_Handler" )
new Num[ 3 ];
for( new i = 0; i < SongCount; i++ )
{
num_to_str( i, Num, 2 );
menu_additem( Menu, g_Song_Names[ i ], Num );
}
menu_display( id, Menu );
return PLUGIN_HANDLED;
}
public SongList_Handler( id, Menu, item )
{
if( item == MENU_EXIT )
{
menu_destroy( Menu );
return PLUGIN_HANDLED;
}
Play_Song( id, item );
return PLUGIN_HANDLED;
}
public Cmd_Search( id, Search[ ] )
{
client_print_color( id, NORMAL, "%L", Search, id, "SEARCHED_FOR" )
new SearchMenu = menu_create( "\ySearching Results:\r", "SongList_Handler" )
new Num[ 3 ];
for( new i = 0; i <= SongCount; i++ )
{
if( containi( g_Song_Names[ i ], Search ) != -1 )
{
num_to_str( i, Num, 2 );
menu_additem( SearchMenu, g_Song_Names[ i ], Num );
}
}
menu_display( id, SearchMenu );
return PLUGIN_HANDLED;
}
public Cmd_CopySong( id )
Play_Song( id, LastSong );
Play_Song( id, key )
{
if( !file_exists( g_MusicPlayer ) )
return;
new szPlayer[ charsmax( g_MusicPlayer ) ], szMotd[ charsmax( g_MusicPlayer ) ], szLine, szLength
while( read_file( g_MusicPlayer, szLine++, szPlayer, charsmax( szPlayer ), szLength ) )
add( szMotd, charsmax( szMotd ), szPlayer )
parse( szMotd, charsmax( szMotd ), "[MEDIA_NAME]", g_Song_Names[ key ] )
parse( szMotd, charsmax( szMotd ), "[MEDIA_URL]", g_Song_Links[ key ] )
show_motd( id, szMotd, g_szPlugin )
new szName[ 32 ];
get_user_name( id, szName, 31 )
client_print_color( 0, NORMAL, "%L", szName, g_Song_Names[ key ], id, "LISTENING_TO" )
LastSong = key
g_LastMusic[ id ] = key
}
public Initialize( )
{
new iConfigDir[ 128 ], iFile[ 128 ]//, iFileText[ 2048 ], iLen = 0;
get_localinfo( "amxx_configsdir", iConfigDir, charsmax( iConfigDir ) )
format(iFile, 127, "configs/songlist.ini")
if( !file_exists( iFile ) )
{
new FileP = fopen( iFile, "+a" )
fprintf( FileP, "; %s Songs^n", g_szPlugin )
fprintf( FileP, "; Format: ^"Song Name^" ^"Song Url/Link^"^n" )
fprintf( FileP, "; eg. ^"Eminem - Mockingbird^" ^"http://www.youtube.com/watch?v=S9bCLPwzSC0^n^"" )
fclose( FileP )
server_print( "%L", iFile, "FILE_ADDED" )
}
/*formatex( iFile, charsmax( iFile ), "%s/%s", iConfigDir, "songlist.ini" )
if( !file_exists( iFile ) )
{
iLen = format( iFileText, charsmax( iFileText ), "; %s Songs^n", g_szPlugin )
iLen += format( iFileText[ iLen ], charsmax( iFileText ) - iLen, "; Format: ^"Song Name^" ^"Song Url/Link^"^n" )
iLen += format( iFileText[ iLen ], charsmax( iFileText ) - iLen, "; eg. ^"Eminem - Mockingbird^" ^"http://www.youtube.com/watch?v=S9bCLPwzSC0^n^"" )
write_file( iFile, iFileText )
}*/
formatex( g_MusicPlayer, charsmax( g_MusicPlayer ), "%s/%s", iConfigDir, "AdvMusicPlayer.html" ); //iLen = 0
SongCount = 1;
new szText[ 1024 ], Line, Length;
while( read_file( iFile, Line++, szText, charsmax( szText ), Length ) )
{
trim( szText )
if( !Length || szText[ 0 ] == ';' )
continue;
if( SongCount > MaxSongs )
break;
static Left[ 35 ], Right[ 512 ]
parse( szText, Left, charsmax( Left ), Right, charsmax( Right ) )
parse( Left, charsmax( Left ), "^"", "" )
parse( Right, charsmax( Right), "^"", "" )
parse( Right, charsmax( Right ), " ", "%20" )
copy( g_Song_Names[ SongCount ], charsmax( g_Song_Names[ ] ), Left )
copy( g_Song_Links[ SongCount ], charsmax( g_Song_Links[ ] ), Right )
SongCount++
}
}
register_dictionary_colored( const iFile[ ] )
{
if( !register_dictionary( iFile ) )
return 0;
new iLangDir[ 128 ];
get_localinfo( "amxx_datadir", iLangDir, charsmax( iLangDir ) )
formatex( iLangDir, charsmax( iLangDir ), "%s/lang/%s", iLangDir, iFile )
new FileP = fopen( iLangDir, "rt" );
if( !FileP )
{
log_amx( "Failed to open: %s", iLangDir );
return 0;
}
new szBuffer[ 512 ], szLang[ 3 ], szKey[ 64 ], szTranslation[ 256 ], TransKey:iKey;
while( !feof( FileP ) )
{
fgets( FileP, szBuffer, 511 );
if( szBuffer[ 0 ] == '[' )
{
strtok( szBuffer[ 1 ], szLang, 2, szBuffer, 1, ']' );
}
else if( szBuffer[ 0 ] )
{
strbreak( szBuffer, szKey, 63, szTranslation, 255 );
iKey = GetLangTransKey( szKey );
if( iKey != TransKey_Bad )
{
replace_all( szTranslation, 255, "!g", "^4" );
replace_all( szTranslation, 255, "!t", "^3" );
replace_all( szTranslation, 255, "!n", "^1" );
AddTranslation( szLang, iKey, szTranslation[ 2 ] );
}
}
}
fclose( FileP );
return 1;
}
client_print_color(id, Color:type, const msg[], {Float,Sql,Result,_}:...)
{
static SayText;
if(!SayText)
SayText = get_user_msgid("SayText");
static message[256];
switch(type)
{
case GREEN: // Green
{
message[0] = 0x04;
}
case TEAM_COLOR: // Team Color. Ie. Red (Terrorist) or blue (Counter-Terrorist).
{
message[0] = 0x03;
}
default: // Yellow.
{
message[0] = 0x01;
}
}
vformat(message[1], 251, msg, 4);
message[192] = '^0';
if(id)
{
if(is_user_connected(id))
{
message_begin(MSG_ONE, SayText, {0, 0, 0}, id);
write_byte(id);
write_string(message);
message_end();
}
} else {
static players[32]; new count, index;
get_players(players, count);
for(new i = 0; i < count; i++)
{
index = players[i];
message_begin(MSG_ONE, SayText, {0, 0, 0}, index);
write_byte(index);
write_string(message);
message_end();
}
}
}