Advertisement
2ky

2K-Radio

2ky
Feb 28th, 2012
544
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 5.38 KB | None | 0 0
  1. #include    <a_samp>
  2. #include    <zcmd>
  3. #include    <YSI/y_ini>
  4. #include    <sscanf2_5>
  5.  
  6. #define     RadioLocation   "Radio"
  7.             /*
  8.                 Create a folder in your 'scriptfiles' folder named whatever is in the quotations.
  9.             */
  10.  
  11. #define     MAXIMUM_RADIO_STATIONS      100
  12.  
  13. #define     RADIO_DIALOG                1010
  14.  
  15. #define     STATION_ID_COLOUR           0x509E08FF
  16. #define     STATION_NAME_COLOUR         0x12A7C4FF
  17.  
  18. #define     STATIONGENRE                "{509E08}"
  19. #define     STATIONNAME                 "{12A7C4}"
  20.  
  21.  
  22. enum E_radVars
  23. {
  24.     StationName[64],        StationURL[64],
  25.     StationGenre[32]
  26. }
  27.  
  28. new
  29.     radInfo[MAXIMUM_RADIO_STATIONS][E_radVars];
  30.  
  31. public OnFilterScriptInit()
  32. {
  33.     new
  34.         rStr[16];
  35.        
  36.     for( new r = 1; r < MAXIMUM_RADIO_STATIONS; r++ )
  37.     {
  38.         format( rStr, sizeof( rStr ), "%s/%d.ini", RadioLocation, r );
  39.        
  40.         if( fexist( rStr ) )
  41.         {
  42.             INI_ParseFile( rStr, "LoadRadio_%s", .bExtra = true, .extra = r), printf("[LOAD] Radio Station %d loaded. Station Name: %s | Station URL: %s", r, radInfo[r][StationName], radInfo[r][StationURL]);
  43.         }
  44.     }
  45.     return true;
  46. }
  47.  
  48. public OnFilterScriptExit()
  49. {
  50.     new
  51.         rStr[16];
  52.        
  53.     for( new r = 1; r < MAXIMUM_RADIO_STATIONS; r++ )
  54.     {
  55.         format( rStr, sizeof( rStr ), "%s/%d.ini", RadioLocation, r );
  56.        
  57.         if( fexist( rStr ) )
  58.         {
  59.             new
  60.                 INI:radFile = INI_Open( rStr );
  61.                
  62.             INI_SetTag( radFile, "station" );
  63.            
  64.             INI_WriteString( radFile, "Station_Name", radInfo[r][StationName] );
  65.             INI_WriteString( radFile, "Station_Genre", radInfo[r][StationGenre] );
  66.            
  67.             INI_WriteString( radFile, "Station_URL", radInfo[r][StationURL] );
  68.            
  69.             INI_Close( radFile );
  70.         }
  71.     }
  72.     return true;
  73. }
  74.  
  75. forward LoadRadio_station( radioid, name[], value[] );
  76. public LoadRadio_station( radioid, name[], value[] )
  77. {
  78.     INI_String( "Station_Name",         radInfo[radioid][StationName],          64 );
  79.     INI_String( "Station_Genre",        radInfo[radioid][StationGenre],         32 );
  80.    
  81.     INI_String( "Station_URL",          radInfo[radioid][StationURL],           64 );
  82.     return true;
  83. }
  84.  
  85. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[] )
  86. {
  87.     switch( dialogid )
  88.     {
  89.         case RADIO_DIALOG:
  90.         {
  91.             if( response )
  92.             {
  93.                 PlayAudioStreamForPlayer(playerid, radInfo[listitem][StationURL]);
  94.             }
  95.             else return StopAudioStreamForPlayer(playerid);
  96.         }
  97.     }
  98.     return true;
  99. }
  100.  
  101. CMD:radio(playerid, params[]) {
  102.    
  103.     new
  104.         availableStations[256],
  105.         holder[256],
  106.         //256 on both of these support about 8 radio stations, so adjust the size accordingly.
  107.         rStr[16],
  108.         radioCount = 0;
  109.    
  110.     strcat ( holder, "[Select a Station]\n" )
  111.     for( new r = 1; r < MAXIMUM_RADIO_STATIONS; r ++ )
  112.     {
  113.         format( rStr, sizeof( rStr ), "%s/%d.ini", RadioLocation, r );
  114.         if( fexist( rStr ) )
  115.         {
  116.             format( availableStations, sizeof( availableStations ), ""#STATIONGENRE"[%s]\t\t"#STATIONNAME"%s\n", radInfo[r][StationGenre], radInfo[r][StationName] );
  117.             strcat( holder, availableStations );
  118.             radioCount++;
  119.         }
  120.     }
  121.    
  122.     if(radioCount == 0)
  123.         return SendClientMessage(playerid, -1, "ERROR: No Radio Stations available.");
  124.        
  125.     ShowPlayerDialog(playerid, RADIO_DIALOG, DIALOG_STYLE_LIST, "Please select a Radio Station", holder, "Play", "Cancel");
  126.     return true;
  127. }
  128.  
  129. CMD:createstation(playerid, params[])
  130. {
  131.     new
  132.         StatID = GetOpenStationID(),
  133.         stat_Genre[32],
  134.         stat_Name[64],
  135.         stat_URL[64],
  136.         rStr[32];
  137.        
  138.     if(!IsPlayerAdmin( playerid ) )
  139.         return SendClientMessage(playerid, -1, "ERROR: Not authorized to use this!");
  140.        
  141.     if(sscanf(params, "s[32]s[64]s[64]", stat_Genre, stat_Name, stat_URL))
  142.         return SendClientMessage(playerid, -1, "<USAGE> /createstation <station genre> <station name> <station url (http://.... NO WWW.)>");
  143.        
  144.     format( rStr, sizeof( rStr), "%s/%d.ini", RadioLocation, StatID);
  145.    
  146.     if( !fexist( rStr ) )
  147.     {
  148.         new
  149.             INI:radFile = INI_Open( rStr );
  150.            
  151.         INI_SetTag(radFile, "station");
  152.        
  153.         INI_WriteString( radFile, "Station_Name", stat_Name );
  154.         INI_WriteString( radFile, "Station_Genre", stat_Genre );
  155.            
  156.         INI_WriteString( radFile, "Station_URL", stat_URL );
  157.            
  158.         INI_Close( radFile );
  159.        
  160.         LoadStations();
  161.        
  162.         format( rStr, sizeof( rStr ), "> Station \"%s\" created.", stat_Name);
  163.         SendClientMessage(playerid, -1, rStr);
  164.     }
  165.     return true;
  166. }
  167.  
  168. CMD:deletestation(playerid, params[])
  169. {
  170.     new
  171.         stationID,
  172.         rStr[32];
  173.        
  174.     if(!IsPlayerAdmin( playerid ) )
  175.         return SendClientMessage(playerid, -1, "ERROR: Not authorized to use this!");
  176.        
  177.     if( sscanf(params, "i", stationID ))
  178.         return SendClientMessage(playerid, -1, "<USAGE> /deletestation <station id>");
  179.        
  180.     format( rStr, sizeof( rStr), "%s/%d.ini", RadioLocation, stationID);
  181.        
  182.     if( fexist ( rStr ) )
  183.     {
  184.         fremove( rStr );
  185.        
  186.         LoadStations();
  187.        
  188.         format( rStr, sizeof( rStr ), "> Station ID %d has been deleted.", stationID);
  189.         SendClientMessage( playerid, -1, rStr );
  190.     }
  191.     else return SendClientMessage(playerid, -1, "ERROR: Station does not exist!");
  192.     return true;
  193. }
  194.  
  195. stock GetOpenStationID()
  196. {
  197.     new
  198.         rID = -1,
  199.         radStr[16];
  200.        
  201.     for( new r = 1; r < MAXIMUM_RADIO_STATIONS; r++ )
  202.     {
  203.         format( radStr, sizeof( radStr ), "%s/%d.ini", RadioLocation, r );
  204.        
  205.         if(!fexist(radStr))
  206.         {
  207.             return rID = r;
  208.         }
  209.     }
  210.     return rID;
  211. }
  212.  
  213. stock LoadStations()
  214. {
  215.     new
  216.         radStr[32];
  217.        
  218.     for( new r = 1; r < MAXIMUM_RADIO_STATIONS; r++ )
  219.     {
  220.         format( radStr, sizeof( radStr ), "%s/%d.ini", RadioLocation,  r );
  221.            
  222.         if(fexist(radStr))
  223.         {
  224.             INI_ParseFile( radStr, "LoadRadio_%s", .bExtra = true, .extra = r );
  225.         }
  226.     }
  227.     return true;
  228. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement