Advertisement
Guest User

Tracks_V1

a guest
May 2nd, 2013
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.59 KB | None | 0 0
  1. #include " a_samp "
  2. #include " a_mysql " //MySQL R8, cu functii cache.
  3. #include " sscanf2 "
  4. #include " zcmd "
  5. #include " ytstream "
  6. /* Ca sa va mearga bine stream-ul, trebuie sa puneti partea de PHP
  7. al acestui script, in celalate fisiere .php unde aveti forumul.
  8. http://forum.sa-mp.com/showthread.php?t=370450
  9.  
  10. PS> Sa fiu sincer, pe Windows nu prea stiu unde sa puneti chestia aia :))
  11. */
  12.  
  13. #define mysql_host "localhost"
  14. #define mysql_user "root"
  15. #define mysql_pass ""
  16. #define mysql_db "samp"
  17.  
  18. #define MAX_PLAYER_TRACKS (10)
  19. #define DIALOG_SELECT_TRACK (1000)
  20. #define DIALOG_INSERT_TRACK_URL (1001)
  21. #define DIALOG_INSERT_TRACK_NAME (1002)
  22. //============================================================================//
  23. new
  24. c_Handle,
  25. f_global_query[ 512 ],
  26. f_global_string[ 512 ],
  27. bool:g_IsInDatabase[ MAX_PLAYERS ],
  28. g_PlayerTrackLing[ MAX_PLAYERS ][ MAX_PLAYER_TRACKS ][ 256 ],
  29. g_PlayerTrackName[ MAX_PLAYERS ][ MAX_PLAYER_TRACKS ][ 256 ],
  30. g_PlayerTotalTracks[ MAX_PLAYERS ]
  31. ;
  32. //============================================================================//
  33. public OnPlayerConnect( playerid )
  34. {
  35. format( f_global_query, 128, "SELECT * FROM `Tracks` WHERE `user` = '%s'", n_Get( playerid ) );
  36. return mysql_function_query( c_Handle, f_global_query, true, "CheckInTable", "i", playerid );
  37. }
  38. public OnFilterScriptInit( )
  39. {
  40. c_Handle = mysql_connect( mysql_host, mysql_user, mysql_db, mysql_pass, 3306 );
  41. mysql_function_query( c_Handle, "CREATE TABLE IF NOT EXISTS `Tracks` (`user` TEXT, `links` TEXT, `names` TEXT)", false, "", "" );
  42.  
  43. return 1;
  44. }
  45. public OnDialogResponse( playerid, dialogid, response, listitem, inputtext[ ] )
  46. {
  47. switch( dialogid )
  48. {
  49. case DIALOG_SELECT_TRACK:
  50. {
  51. if ( !response )
  52. return 1;
  53.  
  54. YoutubeStreamForPlayer( playerid, g_PlayerTrackLing[ playerid ][ listitem + 1 ] );
  55.  
  56. format( f_global_string, 128, "INFO: {FFFFFF}You are now playing '{33AA33}%s{FFFFFF}'", g_PlayerTrackName[ playerid ][ listitem + 1 ] );
  57. SendClientMessage( playerid, 0xFFFF00FF, f_global_string );
  58. }
  59. case DIALOG_INSERT_TRACK_URL:
  60. {
  61. if ( !response )
  62. return 1;
  63.  
  64. new url[ 256 ];
  65. if ( sscanf( inputtext, "s[256]", url ) )
  66. return ShowPlayerDialog( playerid, DIALOG_INSERT_TRACK_URL, DIALOG_STYLE_INPUT, "Add Track", "{FFFFFF}Please put here the youtube url of track do you want to\nbe in your playlist", "Add", "Cancel" );
  67.  
  68. if ( strlen( url ) < 30 )
  69. return ShowPlayerDialog( playerid, DIALOG_INSERT_TRACK_URL, DIALOG_STYLE_INPUT, "Add Track", "{FFFFFF}Please put here the youtube url of track do you want to\nbe in your playlist", "Add", "Cancel" );
  70.  
  71. if ( strfind( url, "youtube", false ) == -1 )
  72. return ShowPlayerDialog( playerid, DIALOG_INSERT_TRACK_URL, DIALOG_STYLE_INPUT, "Add Track", "{FFFFFF}Please put here the youtube url of track do you want to\nbe in your playlist", "Add", "Cancel" );
  73.  
  74. format( g_PlayerTrackLing[ playerid ][ g_PlayerTotalTracks[ playerid ] + 1 ], 256, url );
  75. format( g_PlayerTrackName[ playerid ][ g_PlayerTotalTracks[ playerid ] + 1 ], 128, "No-Name Set" );
  76.  
  77. g_PlayerTotalTracks[ playerid ]++;
  78.  
  79. format( f_global_query, 128, "UPDATE `Tracks` SET `total_tracks` = %d WHERE `user` = '%s';", g_PlayerTotalTracks[ playerid ], n_Get( playerid ) );
  80. mysql_function_query( c_Handle, f_global_query, false, "", "" );
  81.  
  82. ShowPlayerDialog( playerid, DIALOG_INSERT_TRACK_NAME, DIALOG_STYLE_INPUT, "Music Name", "{FFFFFF}Please type here the music name for what you've added it at your playlist", "Set", "Cancel" );
  83. return 1;
  84. }
  85. case DIALOG_INSERT_TRACK_NAME:
  86. {
  87. if ( !response )
  88. return 1;
  89.  
  90. new t_name[ 256 ];
  91. if ( sscanf( inputtext, "s[256]", t_name ) )
  92. return ShowPlayerDialog( playerid, DIALOG_INSERT_TRACK_NAME, DIALOG_STYLE_INPUT, "Music Name", "{FFFFFF}Please type here the music name for what you've added it at your playlist", "Set", "Cancel" );
  93.  
  94. if ( strlen( t_name ) < 3 )
  95. return ShowPlayerDialog( playerid, DIALOG_INSERT_TRACK_NAME, DIALOG_STYLE_INPUT, "Music Name", "{FFFFFF}Please type here the music name for what you've added it at your playlist", "Set", "Cancel" );
  96.  
  97. format( g_PlayerTrackName[ playerid ][ g_PlayerTotalTracks[ playerid ] ], 128, t_name );
  98.  
  99. format( f_global_string, 128, "You've added a track, called '{33AA33}%s{FFFFFF}'", g_PlayerTrackName[ playerid ][ g_PlayerTotalTracks[ playerid ] ] );
  100. SendClientMessage( playerid, ~1, f_global_string );
  101.  
  102. format( f_global_query, 256, "SELECT `links`,`names` FROM `Tracks` WHERE `user` = '%s'", n_Get( playerid ) );
  103. mysql_function_query( c_Handle, f_global_query, true, "AddToTracklist", "i", playerid );
  104. return 1;
  105. }
  106. }
  107. return 1;
  108. }
  109. //============================================================================//
  110. COMMAND:mp3( playerid, params[ ] )
  111. {
  112. if ( g_IsInDatabase[ playerid ] == false )
  113. return SendClientMessage( playerid, 0xFF0000FF, "ERROR: {FFFFFF}You don't have any track in your track list" );
  114.  
  115. format( f_global_query, 128, "SELECT * FROM `Tracks` WHERE `user` = '%s'", n_Get( playerid ) );
  116. return mysql_function_query( c_Handle, f_global_query, true, "ShowTracks", "i", playerid );
  117. }
  118. COMMAND:tadd( playerid, params[ ] )
  119. {
  120. if ( g_PlayerTotalTracks[ playerid ] >= MAX_PLAYER_TRACKS )
  121. return SendClientMessage( playerid, ~1, "You already have 10 in your track list" );
  122.  
  123. if ( g_IsInDatabase[ playerid ] == true )
  124. ShowPlayerDialog( playerid, DIALOG_INSERT_TRACK_URL, DIALOG_STYLE_INPUT, "Add Track", "{FFFFFF}Please put here the youtube url of track do you want to\nbe in your playlist", "Add", "Cancel" );
  125. else
  126. {
  127. format( f_global_string, 128, "INSERT INTO `Tracks` (`user`,`links`,`names`) VALUES('%s',' ', ' ' )", n_Get( playerid ) );
  128. mysql_function_query( c_Handle, f_global_string, false, "", "" );
  129.  
  130. g_IsInDatabase[ playerid ] = true;
  131.  
  132. ShowPlayerDialog( playerid, DIALOG_INSERT_TRACK_URL, DIALOG_STYLE_INPUT, "Add Track", "{FFFFFF}Please put here the youtube url of track do you want to\nbe in your playlist", "Add", "Cancel" );
  133. }
  134. return 1;
  135. }
  136. COMMAND:tstop( playerid, params[ ] )
  137. {
  138. YoutubeStopStreamForPlayer( playerid );
  139. return SendClientMessage( playerid, 0xFFFF00FF, "INFO: {FFFFFF}You've stopped the audio streaming" );
  140. }
  141. //============================================================================//
  142. forward CheckInTable( playerid );
  143. public CheckInTable( playerid )
  144. {
  145. if ( !IsPlayerConnected( playerid ) )
  146. return 0;
  147.  
  148. new Rows, Fields;
  149. cache_get_data( Rows, Fields, c_Handle );
  150.  
  151. if ( Rows )
  152. g_IsInDatabase[ playerid ] = true;
  153. else
  154. g_IsInDatabase[ playerid ] = false;
  155.  
  156. return 1;
  157. }
  158. forward ShowTracks( playerid );
  159. public ShowTracks( playerid )
  160. {
  161. if ( !IsPlayerConnected( playerid ) )
  162. return 0;
  163.  
  164. new Rows, Fields, Field[ 1024 ], string[ 1024 ];
  165. cache_get_data( Rows, Fields, c_Handle );
  166.  
  167. if ( !Rows )
  168. return SendClientMessage( playerid, ~1, "An error has encountered." );
  169.  
  170. format( string, 128, "p<|>a<s[256]>[%d]", g_PlayerTotalTracks[ playerid ] );
  171.  
  172. cache_get_field_content( 0, "links", Field, c_Handle );
  173.  
  174. for ( new i = 0; i < MAX_PLAYER_TRACKS; ++ i )
  175. sscanf( Field, string, g_PlayerTrackLing[ playerid ][ i ] );
  176.  
  177. cache_get_field_content( 0, "names", Field, c_Handle );
  178.  
  179. for ( new i = 0; i < MAX_PLAYER_TRACKS; ++ i )
  180. sscanf( Field, string, g_PlayerTrackName[ playerid ][ i ] );
  181.  
  182. for ( new i = 0; i < MAX_PLAYER_TRACKS; ++ i )
  183. format( string, 1024, "%s", g_PlayerTrackName[ playerid ][ i ] );
  184.  
  185. return ShowPlayerDialog( playerid, DIALOG_SELECT_TRACK, DIALOG_STYLE_LIST, "Tracks", string, "Play", "Quit" );
  186. }
  187. forward AddToTracklist( playerid );
  188. public AddToTracklist( playerid )
  189. {
  190. if ( !IsPlayerConnected( playerid ) )
  191. return 0;
  192.  
  193. new Field[ 2 ][ 1024 ];
  194. cache_get_field_content( 0, "links", Field[ 0 ] );
  195. cache_get_field_content( 0, "names", Field[ 1 ] );
  196.  
  197. format( f_global_query, 256, "UPDATE `Tracks` SET `links` = '%s%s|',`names` = '%s%s|' WHERE `user` = '%s'", Field[ 0 ], g_PlayerTrackLing[ playerid ][ g_PlayerTotalTracks[ playerid ] ], Field[ 1 ], g_PlayerTrackName[ playerid ][ g_PlayerTotalTracks[ playerid ] ], n_Get( playerid ) );
  198. return mysql_function_query( c_Handle, f_global_query, false, "", "" );
  199. }
  200. //============================================================================//
  201. stock n_Get( playerid )
  202. {
  203. new name[ MAX_PLAYER_NAME ];
  204. GetPlayerName( playerid, name, MAX_PLAYER_NAME );
  205. return name;
  206. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement