Advertisement
Guest User

Untitled

a guest
Aug 3rd, 2015
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.27 KB | None | 0 0
  1. #include < amxmodx >
  2. #include < amxmisc >
  3.  
  4. #define PLUGIN "Music Menu From File"
  5. #define VERSION "1.1"
  6. #define AUTHOR "SUSYABASHTI"
  7.  
  8. new Array:g_aSongFile;
  9. new Array:g_aSongName;
  10. new g_iTotalSongs;
  11.  
  12. new Float:g_flVolume[ 33 ];
  13. new g_iSong[ 33 ];
  14.  
  15. const Float:MIN_VOL = 0.4;
  16.  
  17. public plugin_init( )
  18. {
  19. register_plugin( PLUGIN, VERSION, AUTHOR );
  20.  
  21. register_clcmd( "say /music", "cmdMusic" );
  22.  
  23. register_clcmd( "nightvision", "cmdMusic" );
  24. }
  25.  
  26. public caseMusic( client, menu, item )
  27. {
  28. if ( item == MENU_EXIT )
  29. {
  30. menu_destroy( menu );
  31. cmdShowMenu( client );
  32. return;
  33. }
  34.  
  35. new name[ 32 ];
  36. get_user_name( client, name, sizeof( name ) - 1 );
  37.  
  38. client_cmd( play_for_all[ client ] ? 0 : client, "mp3 play ^"sound/%s^"", menu_action[ client ] ? Heb_Songs_dir[ item ] : Eng_Songs_dir[ item ] );
  39. 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 ] );
  40. client_cmd( play_for_all[ client ] ? 0 : client, "MP3Volume %.1f", Volume[ client ]);
  41. }
  42.  
  43.  
  44. public plugin_precache( )
  45. {
  46. ReadFile( );
  47. }
  48.  
  49. public plugin_end( )
  50. {
  51. ArrayDestroy( g_aSongFile );
  52. ArrayDestroy( g_aSongName );
  53. }
  54.  
  55. ReadFile( )
  56. {
  57. g_aSongName = ArrayCreate( 64, 1 );
  58. g_aSongFile = ArrayCreate( 64, 1 );
  59.  
  60. new szConfigsDir[ 64 ];
  61. get_configsdir( szConfigsDir, charsmax( szConfigsDir ) );
  62.  
  63. add( szConfigsDir, charsmax( szConfigsDir ), "/songs.ini" );
  64.  
  65. if( !file_exists( szConfigsDir ) )
  66. {
  67. write_file( szConfigsDir, "; Music Menu From File was made by SUSYABASHTI^n; Example of how to add music: ^"Song Name^" ^"Song Path without sound/^"" );
  68. log_amx( "No Songs were found!" );
  69. pause( "a" );
  70. return 1;
  71. }
  72.  
  73. new iFile = fopen( szConfigsDir, "rt" );
  74.  
  75. if( !iFile )
  76. return 0;
  77.  
  78. new szBuffer[ 512 ], szSongName[ 64 ], szSongFile[ 64 ];
  79.  
  80. while( !feof( iFile ) )
  81. {
  82. fgets( iFile, szBuffer, charsmax( szBuffer ) );
  83.  
  84. replace( szBuffer, charsmax( szBuffer ), "^n", "" );
  85.  
  86. if( !szBuffer[ 0 ] || szBuffer[ 0 ] == '/' || szBuffer[ 0 ] == ';' )
  87. continue;
  88.  
  89. strbreak( szBuffer, szSongName, 63, szSongFile, charsmax( szSongFile ) );
  90.  
  91. remove_quotes( szSongName );
  92. remove_quotes( szSongFile );
  93.  
  94. /*if( containi( szSongFile, ".mp3" ) != -1 )
  95. continue;*/
  96.  
  97. // Precaching right from the sounds folder
  98. precache_sound( szSongFile );
  99.  
  100. log_amx( "Song Name: %s, Song File: %s", szSongName, szSongFile );
  101.  
  102. ArrayPushString( g_aSongName, szSongName );
  103. ArrayPushString( g_aSongFile, szSongFile );
  104.  
  105. ++g_iTotalSongs;
  106. }
  107.  
  108. if( !g_iTotalSongs )
  109. {
  110. log_amx( "No Songs were found!" );
  111. pause( "a" );
  112. return 1;
  113. }
  114.  
  115. else
  116. {
  117. log_amx( "Total Songs Loaded: %i", g_iTotalSongs );
  118. }
  119.  
  120. return 1;
  121. }
  122.  
  123. public client_putinserver( iIndex )
  124. {
  125. g_flVolume[ iIndex ] = 0.4;
  126.  
  127. set_task( 5.0, "Task_Ask", iIndex );
  128. }
  129.  
  130. public Task_Ask( iIndex )
  131. {
  132. if( !is_user_connected( iIndex ) )
  133. return;
  134.  
  135. new iMenu = menu_create( "[IDF]Allow us to change your volume?", "menuHandler_Ask" );
  136.  
  137. menu_additem( iMenu, "Yes", "" );
  138. menu_additem( iMenu, "No", "" );
  139.  
  140. menu_setprop( iMenu, MPROP_EXIT, MEXIT_NEVER );
  141. menu_display( iIndex, iMenu );
  142. }
  143.  
  144. public menuHandler_Ask( iIndex, iMenu, iItem )
  145. {
  146. switch( iItem )
  147. {
  148. // Yes
  149. case 0:
  150. {
  151. client_print( iIndex, print_chat, "[IDF]Your volume has changed to %.1f", g_flVolume[ iIndex ] );
  152. client_cmd( iIndex, "; MP3Volume %.1f", g_flVolume[ iIndex ] );
  153. }
  154.  
  155. // No
  156. case 1:
  157. {
  158. menu_destroy( iMenu );
  159. }
  160. }
  161. }
  162.  
  163. public cmdMusic( iIndex )
  164. {
  165. static szBuffer[ 256 ], iMenu, szSong[ 64 ];
  166. formatex( szBuffer, charsmax( szBuffer ), "\yMusic Menu - Main Menu" );
  167.  
  168. iMenu = menu_create( szBuffer, "menuHandler_Music" );
  169.  
  170. ArrayGetString( g_aSongName, g_iSong[ iIndex ], szSong, charsmax( szSong ) );
  171. formatex( szBuffer, charsmax( szBuffer ), "Current Song - \r[\y%s\r]", szSong );
  172.  
  173. menu_additem( iMenu, szBuffer, "" );
  174.  
  175. new iNextSong = g_iSong[ iIndex ] + 1;
  176.  
  177. if( iNextSong + 1 > g_iTotalSongs )
  178. {
  179. iNextSong = 0;
  180. }
  181.  
  182. ArrayGetString( g_aSongName, iNextSong, szSong, charsmax( szSong ) );
  183. formatex( szBuffer, charsmax( szBuffer ), "Next Song -\y %s", szSong );
  184.  
  185. menu_additem( iMenu, szBuffer, "" );
  186.  
  187. //menu_addblank( iMenu );
  188.  
  189. formatex( szBuffer, charsmax( szBuffer ), "Current Volume -\y %.1f", g_flVolume[ iIndex ] );
  190. menu_additem( iMenu, szBuffer, "" );
  191.  
  192. formatex( szBuffer, charsmax( szBuffer ), "\rStop Music" );
  193. menu_additem( iMenu, szBuffer, "" );
  194.  
  195. menu_display( iIndex, iMenu );
  196. }
  197.  
  198. public menuHandler_Music( iIndex, iMenu, iItem )
  199. {
  200. if( iItem == MENU_EXIT )
  201. {
  202. menu_destroy( iMenu );
  203. return;
  204. }
  205.  
  206. switch( iItem )
  207. {
  208. // Songs List
  209. case 0:
  210. {
  211. menu_destroy( iMenu );
  212. SongList( iIndex );
  213.  
  214. return;
  215. }
  216.  
  217. // Next Song
  218. case 1:
  219. {
  220. ++g_iSong[ iIndex ];
  221.  
  222. if( g_iSong[ iIndex ] >= g_iTotalSongs )
  223. {
  224. g_iSong[ iIndex ] = 0;
  225. }
  226.  
  227. PlaySong( iIndex );
  228. }
  229.  
  230. // Volume
  231. case 2:
  232. {
  233. g_flVolume[ iIndex ] += 0.1;
  234.  
  235. if( g_flVolume[ iIndex ] > 1.1 )
  236. {
  237. g_flVolume[ iIndex ] = MIN_VOL;
  238. }
  239.  
  240. client_cmd( iIndex, "; MP3Volume %.1f", g_flVolume[ iIndex ] );
  241. }
  242.  
  243. // Stop Music
  244. case 3:
  245. {
  246. client_cmd( iIndex, "; mp3 stop" );
  247. }
  248. }
  249.  
  250. cmdMusic( iIndex );
  251. }
  252.  
  253. public SongList( iIndex )
  254. {
  255. static szBuffer[ 256 ], iMenu, szSong[ 64 ];
  256. formatex( szBuffer, charsmax( szBuffer ), "\yMusic Menu - Songs List" );
  257.  
  258. iMenu = menu_create( szBuffer, "menuHandler_Songs" );
  259.  
  260. for( new i = 0; i < g_iTotalSongs; ++i )
  261. {
  262. ArrayGetString( g_aSongName, i, szSong, charsmax( szSong ) );
  263.  
  264. menu_additem( iMenu, szSong, "" );
  265. }
  266.  
  267. menu_display( iIndex, iMenu );
  268. }
  269.  
  270. public menuHandler_Songs( iIndex, iMenu, iItem )
  271. {
  272. if( iItem == MENU_EXIT )
  273. {
  274. menu_destroy( iMenu );
  275. cmdMusic( iIndex );
  276.  
  277. return;
  278. }
  279.  
  280. g_iSong[ iIndex ] = iItem;
  281. PlaySong( iIndex );
  282.  
  283. menu_destroy( iMenu );
  284. cmdMusic( iIndex );
  285. }
  286.  
  287. PlaySong( iIndex )
  288. {
  289. new szSongFile[ 128 ];
  290. ArrayGetString( g_aSongFile, g_iSong[ iIndex ], szSongFile, charsmax( szSongFile ) );
  291.  
  292. client_cmd( iIndex, "; mp3 play ^"sound/%s", szSongFile );
  293. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement