Advertisement
Rejack

Music Menu 1.0

Feb 17th, 2014 (edited)
847
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 3.98 KB | None | 0 0
  1. #include < amxmodx >
  2.  
  3. enum g_enSongs
  4. {
  5.     g_mFolder[ 64 ],
  6.     g_mAuthor[ 32 ],
  7.     g_mName[ 64 ]
  8. };
  9.  
  10. new const szMusic[ ][ g_enSongs ] =
  11. {
  12.     { "Directory""Author1""Name1" },
  13.     { "Directory""Author2""Name2" },
  14.     { "Directory""Author3""Name3" }
  15. };
  16.  
  17. new const szPrefix[ ] = "AdvGames";
  18.  
  19. new szItem[ 128 ], g_iSong[ 33 ], g_iVolume[ 33 ];
  20.  
  21. public plugin_init()
  22. {
  23.     register_plugin( "Music Menu", "1.0", "Rejack" );
  24.    
  25.     register_clcmd( "say /music", "CmdMusicMenu" );
  26.     register_clcmd( "say /stop", "CmdStopMusic" );
  27. }
  28.  
  29. public plugin_natives()
  30. {
  31.     register_library( "Music" );
  32.    
  33.     register_native( "MusicOn", "_MusicOn" );
  34. }
  35.  
  36. public plugin_precache()
  37. {
  38.     for ( new i; i < sizeof szMusic; i++ )
  39.         precache_sound( szMusic[ i ][ g_mFolder ] );
  40. }
  41.  
  42. public client_putinserver( client )
  43. {
  44.     client_cmd( client, "MP3Volume ^"1.0^"" );
  45.    
  46.     g_iVolume[ client ] = 5;
  47.    
  48.     g_iSong[ client ] = 0;
  49. }
  50.  
  51. public _MusicOn()
  52. {
  53.     for ( new i = 1; i < get_maxplayers(); i++ )
  54.     {
  55.         if ( !is_user_connected( i ) )
  56.             continue;
  57.        
  58.         g_iSong[ i ] = 0;
  59.        
  60.         PlaySong( i );
  61.        
  62.         CmdMusicMenu( i );
  63.     }
  64. }
  65.  
  66. public CmdStopMusic( client )
  67. {
  68.     StopSong( client );
  69. }
  70.  
  71. public CmdMusicMenu( client )
  72. {
  73.     formatex( szItem, charsmax( szItem ), "\r[%s]\w Music Menu", szPrefix );
  74.    
  75.     new Menu = menu_create( szItem, "SubMusicMenu" );
  76.    
  77.     formatex( szItem, charsmax( szItem ), "\dPlaying:\y %s\w by\r %s^n", szMusic[ g_iSong[ client ] ][ g_mName ], szMusic[ g_iSong[ client ] ][ g_mAuthor ] );
  78.    
  79.     menu_additem( Menu, szItem );
  80.    
  81.     menu_additem( Menu, "\d[\r>>\d]\w Next Song " );
  82.     menu_additem( Menu, "\d[\r<<\d]\w Previous Song" );
  83.     menu_additem( Menu, "\d[\r><\d]\w Stop Song^n" );
  84.    
  85.     formatex( szItem, charsmax( szItem ), "Volume:\d %i0%%^n", g_iVolume[ client ] );
  86.    
  87.     menu_additem( Menu, szItem );
  88.    
  89.     menu_additem( Menu, "\yVolume Up" );
  90.    
  91.     menu_additem( Menu, "\rVolume Down" );
  92.    
  93.     menu_display( client, Menu );
  94.    
  95.     return 1;
  96. }
  97.  
  98. public SubMusicMenu( client, Menu, Item )
  99. {
  100.     if ( Item == MENU_EXIT )
  101.     {
  102.         menu_destroy( Menu );
  103.        
  104.         return 1;
  105.     }
  106.    
  107.     switch ( Item )
  108.     {
  109.         case 0: return CmdMusicMenu( client );
  110.        
  111.         case 1:
  112.         {
  113.             if ( g_iSong[ client ] == charsmax( szMusic ) )
  114.                 g_iSong[ client ] = -1;
  115.                
  116.             g_iSong[ client ]++;
  117.            
  118.             PlaySong( client );
  119.            
  120.             return CmdMusicMenu( client );
  121.         }
  122.        
  123.         case 2:
  124.         {
  125.             if ( g_iSong[ client ] == 0 )
  126.                 g_iSong[ client ] = sizeof szMusic;
  127.                
  128.             g_iSong[ client ]--;
  129.            
  130.             PlaySong( client );
  131.            
  132.             return CmdMusicMenu( client );
  133.         }
  134.        
  135.         case 3:
  136.         {
  137.             StopSong( client );
  138.            
  139.             return CmdMusicMenu( client );
  140.         }
  141.        
  142.         case 4: return CmdMusicMenu( client );
  143.        
  144.         case 5:
  145.         {
  146.             if ( g_iVolume[ client ] != 10 )
  147.             {
  148.                 g_iVolume[ client ]++;
  149.                
  150.                 SetVolume( client );
  151.             }
  152.            
  153.             return CmdMusicMenu( client );
  154.         }
  155.        
  156.         case 6:
  157.         {
  158.             if ( g_iVolume[ client ] != 0 )
  159.             {
  160.                 g_iVolume[ client ]--;
  161.                
  162.                 SetVolume( client );
  163.             }
  164.            
  165.             return CmdMusicMenu( client );
  166.         }
  167.     }
  168.    
  169.     return 1;
  170. }
  171.  
  172. stock PlaySong( const index )
  173. {
  174.     client_cmd( index, "mp3 play ^"sound/%s^"", szMusic[ g_iSong[ index ] ][ g_mFolder ] );
  175. }
  176.  
  177. stock SetVolume( const index )
  178. {
  179.     static Float: volume;
  180.    
  181.     volume = g_iVolume[ index ] * 0.2;
  182.    
  183.     client_cmd( index, "MP3Volume ^"%.1f^"", volume );
  184. }
  185.  
  186. stock StopSong( const index )
  187. {
  188.     client_cmd( index, "mp3 stop" );
  189. }
  190.  
  191. stock ColorPrint( const index, const string[], any:... )
  192. {
  193.     new szMsg[ 191 ], Players[ 32 ], PNum = 1;
  194.    
  195.     static iLen; iLen = formatex( szMsg, charsmax( szMsg ), "^4[%s]^1 ", szPrefix );
  196.    
  197.     vformat( szMsg[ iLen ], charsmax( szMsg ) - iLen, string, 3 );
  198.    
  199.     if ( index )
  200.         Players[ 0 ] = index;
  201.    
  202.     else
  203.         get_players( Players, PNum, "ch" );
  204.    
  205.     for ( new i; i < PNum; i++ )
  206.     {
  207.         if( is_user_connected( Players[ i ] ) )
  208.         {
  209.             message_begin( MSG_ONE_UNRELIABLE, get_user_msgid( "SayText" ), _, Players[ i ] );
  210.            
  211.             write_byte( Players[ i ] );
  212.            
  213.             write_string( szMsg );
  214.            
  215.             message_end( );
  216.         }
  217.     }
  218.    
  219.     return 1;
  220. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement