Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include < amxmodx >
- #include < amxmisc >
- #define PLUGIN "Music Menu From File"
- #define VERSION "1.1"
- #define AUTHOR "SUSYABASHTI"
- new Array:g_aSongFile;
- new Array:g_aSongName;
- new g_iTotalSongs;
- new Float:g_flVolume[ 33 ];
- new g_iSong[ 33 ];
- const Float:MIN_VOL = 0.4;
- public plugin_init( )
- {
- register_plugin( PLUGIN, VERSION, AUTHOR );
- register_clcmd( "say /music", "cmdMusic" );
- register_clcmd( "nightvision", "cmdMusic" );
- }
- public caseMusic( client, menu, item )
- {
- if ( item == MENU_EXIT )
- {
- menu_destroy( menu );
- cmdShowMenu( client );
- return;
- }
- new name[ 32 ];
- get_user_name( client, name, sizeof( name ) - 1 );
- client_cmd( play_for_all[ client ] ? 0 : client, "mp3 play ^"sound/%s^"", menu_action[ client ] ? Heb_Songs_dir[ item ] : Eng_Songs_dir[ item ] );
- ColorChat( play_for_all[ client ] ? 0 : client, "%s^x04%s^x01 now playing^x03 %s^x01 song with^x03 %.1f^x01 Vollume.", play_for_all[ client ] ? "Admin: " : "", name, menu_action[ client ] ? Heb_Songs_name[ item ] : Eng_Songs_name[ item ], Volume[ client ] );
- client_cmd( play_for_all[ client ] ? 0 : client, "MP3Volume %.1f", Volume[ client ]);
- }
- public plugin_precache( )
- {
- ReadFile( );
- }
- public plugin_end( )
- {
- ArrayDestroy( g_aSongFile );
- ArrayDestroy( g_aSongName );
- }
- ReadFile( )
- {
- g_aSongName = ArrayCreate( 64, 1 );
- g_aSongFile = ArrayCreate( 64, 1 );
- new szConfigsDir[ 64 ];
- get_configsdir( szConfigsDir, charsmax( szConfigsDir ) );
- add( szConfigsDir, charsmax( szConfigsDir ), "/songs.ini" );
- if( !file_exists( szConfigsDir ) )
- {
- write_file( szConfigsDir, "; Music Menu From File was made by SUSYABASHTI^n; Example of how to add music: ^"Song Name^" ^"Song Path without sound/^"" );
- log_amx( "No Songs were found!" );
- pause( "a" );
- return 1;
- }
- new iFile = fopen( szConfigsDir, "rt" );
- if( !iFile )
- return 0;
- new szBuffer[ 512 ], szSongName[ 64 ], szSongFile[ 64 ];
- while( !feof( iFile ) )
- {
- fgets( iFile, szBuffer, charsmax( szBuffer ) );
- replace( szBuffer, charsmax( szBuffer ), "^n", "" );
- if( !szBuffer[ 0 ] || szBuffer[ 0 ] == '/' || szBuffer[ 0 ] == ';' )
- continue;
- strbreak( szBuffer, szSongName, 63, szSongFile, charsmax( szSongFile ) );
- remove_quotes( szSongName );
- remove_quotes( szSongFile );
- /*if( containi( szSongFile, ".mp3" ) != -1 )
- continue;*/
- // Precaching right from the sounds folder
- precache_sound( szSongFile );
- log_amx( "Song Name: %s, Song File: %s", szSongName, szSongFile );
- ArrayPushString( g_aSongName, szSongName );
- ArrayPushString( g_aSongFile, szSongFile );
- ++g_iTotalSongs;
- }
- if( !g_iTotalSongs )
- {
- log_amx( "No Songs were found!" );
- pause( "a" );
- return 1;
- }
- else
- {
- log_amx( "Total Songs Loaded: %i", g_iTotalSongs );
- }
- return 1;
- }
- public client_putinserver( iIndex )
- {
- g_flVolume[ iIndex ] = 0.4;
- set_task( 5.0, "Task_Ask", iIndex );
- }
- public Task_Ask( iIndex )
- {
- if( !is_user_connected( iIndex ) )
- return;
- new iMenu = menu_create( "[IDF]Allow us to change your volume?", "menuHandler_Ask" );
- menu_additem( iMenu, "Yes", "" );
- menu_additem( iMenu, "No", "" );
- menu_setprop( iMenu, MPROP_EXIT, MEXIT_NEVER );
- menu_display( iIndex, iMenu );
- }
- public menuHandler_Ask( iIndex, iMenu, iItem )
- {
- switch( iItem )
- {
- // Yes
- case 0:
- {
- client_print( iIndex, print_chat, "[IDF]Your volume has changed to %.1f", g_flVolume[ iIndex ] );
- client_cmd( iIndex, "; MP3Volume %.1f", g_flVolume[ iIndex ] );
- }
- // No
- case 1:
- {
- menu_destroy( iMenu );
- }
- }
- }
- public cmdMusic( iIndex )
- {
- static szBuffer[ 256 ], iMenu, szSong[ 64 ];
- formatex( szBuffer, charsmax( szBuffer ), "\yMusic Menu - Main Menu" );
- iMenu = menu_create( szBuffer, "menuHandler_Music" );
- ArrayGetString( g_aSongName, g_iSong[ iIndex ], szSong, charsmax( szSong ) );
- formatex( szBuffer, charsmax( szBuffer ), "Current Song - \r[\y%s\r]", szSong );
- menu_additem( iMenu, szBuffer, "" );
- new iNextSong = g_iSong[ iIndex ] + 1;
- if( iNextSong + 1 > g_iTotalSongs )
- {
- iNextSong = 0;
- }
- ArrayGetString( g_aSongName, iNextSong, szSong, charsmax( szSong ) );
- formatex( szBuffer, charsmax( szBuffer ), "Next Song -\y %s", szSong );
- menu_additem( iMenu, szBuffer, "" );
- //menu_addblank( iMenu );
- formatex( szBuffer, charsmax( szBuffer ), "Current Volume -\y %.1f", g_flVolume[ iIndex ] );
- menu_additem( iMenu, szBuffer, "" );
- formatex( szBuffer, charsmax( szBuffer ), "\rStop Music" );
- menu_additem( iMenu, szBuffer, "" );
- menu_display( iIndex, iMenu );
- }
- public menuHandler_Music( iIndex, iMenu, iItem )
- {
- if( iItem == MENU_EXIT )
- {
- menu_destroy( iMenu );
- return;
- }
- switch( iItem )
- {
- // Songs List
- case 0:
- {
- menu_destroy( iMenu );
- SongList( iIndex );
- return;
- }
- // Next Song
- case 1:
- {
- ++g_iSong[ iIndex ];
- if( g_iSong[ iIndex ] >= g_iTotalSongs )
- {
- g_iSong[ iIndex ] = 0;
- }
- PlaySong( iIndex );
- }
- // Volume
- case 2:
- {
- g_flVolume[ iIndex ] += 0.1;
- if( g_flVolume[ iIndex ] > 1.1 )
- {
- g_flVolume[ iIndex ] = MIN_VOL;
- }
- client_cmd( iIndex, "; MP3Volume %.1f", g_flVolume[ iIndex ] );
- }
- // Stop Music
- case 3:
- {
- client_cmd( iIndex, "; mp3 stop" );
- }
- }
- cmdMusic( iIndex );
- }
- public SongList( iIndex )
- {
- static szBuffer[ 256 ], iMenu, szSong[ 64 ];
- formatex( szBuffer, charsmax( szBuffer ), "\yMusic Menu - Songs List" );
- iMenu = menu_create( szBuffer, "menuHandler_Songs" );
- for( new i = 0; i < g_iTotalSongs; ++i )
- {
- ArrayGetString( g_aSongName, i, szSong, charsmax( szSong ) );
- menu_additem( iMenu, szSong, "" );
- }
- menu_display( iIndex, iMenu );
- }
- public menuHandler_Songs( iIndex, iMenu, iItem )
- {
- if( iItem == MENU_EXIT )
- {
- menu_destroy( iMenu );
- cmdMusic( iIndex );
- return;
- }
- g_iSong[ iIndex ] = iItem;
- PlaySong( iIndex );
- menu_destroy( iMenu );
- cmdMusic( iIndex );
- }
- PlaySong( iIndex )
- {
- new szSongFile[ 128 ];
- ArrayGetString( g_aSongFile, g_iSong[ iIndex ], szSongFile, charsmax( szSongFile ) );
- client_cmd( iIndex, "; mp3 play ^"sound/%s", szSongFile );
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement