Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <a_samp>
- #include <zcmd>
- #include <YSI/y_ini>
- #include <sscanf2_5>
- #define RadioLocation "Radio"
- /*
- Create a folder in your 'scriptfiles' folder named whatever is in the quotations.
- */
- #define MAXIMUM_RADIO_STATIONS 100
- #define RADIO_DIALOG 1010
- #define STATION_ID_COLOUR 0x509E08FF
- #define STATION_NAME_COLOUR 0x12A7C4FF
- #define STATIONGENRE "{509E08}"
- #define STATIONNAME "{12A7C4}"
- enum E_radVars
- {
- StationName[64], StationURL[64],
- StationGenre[32]
- }
- new
- radInfo[MAXIMUM_RADIO_STATIONS][E_radVars];
- public OnFilterScriptInit()
- {
- new
- rStr[16];
- for( new r = 1; r < MAXIMUM_RADIO_STATIONS; r++ )
- {
- format( rStr, sizeof( rStr ), "%s/%d.ini", RadioLocation, r );
- if( fexist( rStr ) )
- {
- 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]);
- }
- }
- return true;
- }
- public OnFilterScriptExit()
- {
- new
- rStr[16];
- for( new r = 1; r < MAXIMUM_RADIO_STATIONS; r++ )
- {
- format( rStr, sizeof( rStr ), "%s/%d.ini", RadioLocation, r );
- if( fexist( rStr ) )
- {
- new
- INI:radFile = INI_Open( rStr );
- INI_SetTag( radFile, "station" );
- INI_WriteString( radFile, "Station_Name", radInfo[r][StationName] );
- INI_WriteString( radFile, "Station_Genre", radInfo[r][StationGenre] );
- INI_WriteString( radFile, "Station_URL", radInfo[r][StationURL] );
- INI_Close( radFile );
- }
- }
- return true;
- }
- forward LoadRadio_station( radioid, name[], value[] );
- public LoadRadio_station( radioid, name[], value[] )
- {
- INI_String( "Station_Name", radInfo[radioid][StationName], 64 );
- INI_String( "Station_Genre", radInfo[radioid][StationGenre], 32 );
- INI_String( "Station_URL", radInfo[radioid][StationURL], 64 );
- return true;
- }
- public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[] )
- {
- switch( dialogid )
- {
- case RADIO_DIALOG:
- {
- if( response )
- {
- PlayAudioStreamForPlayer(playerid, radInfo[listitem][StationURL]);
- }
- else return StopAudioStreamForPlayer(playerid);
- }
- }
- return true;
- }
- CMD:radio(playerid, params[]) {
- new
- availableStations[256],
- holder[256],
- //256 on both of these support about 8 radio stations, so adjust the size accordingly.
- rStr[16],
- radioCount = 0;
- strcat ( holder, "[Select a Station]\n" );
- for( new r = 1; r < MAXIMUM_RADIO_STATIONS; r ++ )
- {
- format( rStr, sizeof( rStr ), "%s/%d.ini", RadioLocation, r );
- if( fexist( rStr ) )
- {
- format( availableStations, sizeof( availableStations ), ""#STATIONGENRE"[%s]\t\t"#STATIONNAME"%s\n", radInfo[r][StationGenre], radInfo[r][StationName] );
- strcat( holder, availableStations );
- radioCount++;
- }
- }
- if(radioCount == 0)
- return SendClientMessage(playerid, -1, "ERROR: No Radio Stations available.");
- ShowPlayerDialog(playerid, RADIO_DIALOG, DIALOG_STYLE_LIST, "Please select a Radio Station", holder, "Play", "Cancel");
- return true;
- }
- CMD:createstation(playerid, params[])
- {
- new
- StatID = GetOpenStationID(),
- stat_Genre[32],
- stat_Name[64],
- stat_URL[64],
- rStr[32];
- if(!IsPlayerAdmin( playerid ) )
- return SendClientMessage(playerid, -1, "ERROR: Not authorized to use this!");
- if(sscanf(params, "s[32]s[64]s[64]", stat_Genre, stat_Name, stat_URL))
- return SendClientMessage(playerid, -1, "<USAGE> /createstation <station genre> <station name> <station url (http://.... NO WWW.)>");
- format( rStr, sizeof( rStr), "%s/%d.ini", RadioLocation, StatID);
- if( !fexist( rStr ) )
- {
- new
- INI:radFile = INI_Open( rStr );
- INI_SetTag(radFile, "station");
- INI_WriteString( radFile, "Station_Name", stat_Name );
- INI_WriteString( radFile, "Station_Genre", stat_Genre );
- INI_WriteString( radFile, "Station_URL", stat_URL );
- INI_Close( radFile );
- LoadStations();
- format( rStr, sizeof( rStr ), "> Station \"%s\" created.", stat_Name);
- SendClientMessage(playerid, -1, rStr);
- }
- return true;
- }
- CMD:deletestation(playerid, params[])
- {
- new
- stationID,
- rStr[32];
- if(!IsPlayerAdmin( playerid ) )
- return SendClientMessage(playerid, -1, "ERROR: Not authorized to use this!");
- if( sscanf(params, "i", stationID ))
- return SendClientMessage(playerid, -1, "<USAGE> /deletestation <station id>");
- format( rStr, sizeof( rStr), "%s/%d.ini", RadioLocation, stationID);
- if( fexist ( rStr ) )
- {
- fremove( rStr );
- LoadStations();
- format( rStr, sizeof( rStr ), "> Station ID %d has been deleted.", stationID);
- SendClientMessage( playerid, -1, rStr );
- }
- else return SendClientMessage(playerid, -1, "ERROR: Station does not exist!");
- return true;
- }
- stock GetOpenStationID()
- {
- new
- rID = -1,
- radStr[16];
- for( new r = 1; r < MAXIMUM_RADIO_STATIONS; r++ )
- {
- format( radStr, sizeof( radStr ), "%s/%d.ini", RadioLocation, r );
- if(!fexist(radStr))
- {
- return rID = r;
- }
- }
- return rID;
- }
- stock LoadStations()
- {
- new
- radStr[32];
- for( new r = 1; r < MAXIMUM_RADIO_STATIONS; r++ )
- {
- format( radStr, sizeof( radStr ), "%s/%d.ini", RadioLocation, r );
- if(fexist(radStr))
- {
- INI_ParseFile( radStr, "LoadRadio_%s", .bExtra = true, .extra = r );
- }
- }
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement