Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * By RaFaeL zilberman (c) 2012
- * This include have writed for Sa:Mp - San andress multi player!
- *
- */
- #if defined _Radio_included
- #endinput
- #endif
- #if !defined _dof2_included
- #error DOF2 isn't included, please include and tsY again!
- #endif
- #define _Radio_included
- //==========================================================================================
- #define MAX_STREAM_URL 128
- #define MAX_STREAM_TITLE 32
- #define MAX_STREAM_DESC 64
- #define MAX_STREAM_RADOIS 15
- #define MAX_STREAM_SONGS 15
- #define STREAM_FOLDER "Stream"
- #define STREAM_FILE_RADIO "Radio.rst"
- #define STREAM_FILE_SONG "Song.rst"
- //==========================================================================================
- /*
- * Version of file is 0.1 [BETA] realease
- * Use only for radio streaming!
- *** Reguired DOF2 files include for currect working
- */
- /*
- native CheckStreamFiles();
- native StopStreamForPlayer(playerid);
- native StopStreamForAllPlayers();
- native CreateRadio(url[], title[], string[], Float:sX = 0.0, Float:sY = 0.0, Float:sZ = 0.0, Float:Distance = 0.0, bool:UsePos = false); //Return: id/Faild
- native EditRadio(radioid, url[], title[], string[], Float:sX = 0.0, Float:sY = 0.0, Float:sZ = 0.0, Float:Distance = 0.0, bool:UsePos = false); //Return: Success/Faild
- native DeleteRadio(radioid); //Return: T/F
- native IsRadioExists(radioid); //Return: T/F
- native IsValidRadio(radioid); //Return: T/F
- native PlayRadio(playerid, radioid);
- native PlayRadioForAll(radioid);
- native GetRadioTitle(radioid);
- native GetRadioDesc(radioid);
- native CountRadios();
- native AddSong(url[], title[], string[], Float:sX = 0.0, Float:sY = 0.0, Float:sZ = 0.0, Float:Distance = 0.0, bool:UsePos = false); //Return: id/Faild
- native EsitSong(songid, url[], title[], string[], Float:sX = 0.0, Float:sY = 0.0, Float:sZ = 0.0, Float:Distance = 0.0, bool:UsePos = false); //Return: Success/Faild
- native DeleteSong(songid); //Return: T/F
- native IsSongExists(songid); //Return: T/F
- native IsValidSong(songid); //Return: T/F
- native PlaySong(playerid, songid);
- native PlaySongForAll(songid);
- native CountSongs();
- */
- forward OnRadioPlayed(radioid, playerid);
- forward OnSongPlayed(songid, playerid);
- new
- ffile[50], str[128];
- //==========================================================================================
- stock CheckStreamFiles() {
- if(!fexist(STREAM_FILE_RADIO)) DOF2_CreateFile(STREAM_FILE_RADIO);
- if(!fexist(STREAM_FILE_SONG)) DOF2_CreateFile(STREAM_FILE_SONG);
- return true;
- }
- stock StopStreamForPlayer(playerid) {
- StopAudioStreamForPlayer(playerid);
- return true;
- }
- stock StopStreamForAll() {
- for(new i, j = GetMaxPlayers(); i<j; i++) if(IsPlayerConnected(i)) StopAudioStreamForPlayer(i);
- return true;
- }
- stock CreateRadio(url[], title[], string[], Float:sX = 0.0, Float:sY = 0.0, Float:sZ = 0.0, Float:Distance = 0.0, bool:UsePos = false) {
- for(new i; i<MAX_STREAM_RADOIS; i++) {
- format(ffile, sizeof(ffile), "%s/Radio%d.rst", STREAM_FOLDER, i);
- if(!fexist(ffile)) {
- DOF2_CreateFile(ffile);
- DOF2_SetString(ffile, "url", url);
- DOF2_SetString(ffile, "title", title);
- DOF2_SetString(ffile, "string", string);
- DOF2_SetFloat(ffile, "PosX", sX);
- DOF2_SetFloat(ffile, "PosY", sY);
- DOF2_SetFloat(ffile, "PosZ", sZ);
- DOF2_SetFloat(ffile, "Distance", Distance);
- DOF2_SetBool(ffile, "usspos", UsePos);
- DOF2_SaveFile();
- return i;
- }
- }
- return false;
- }
- stock EditRadio(radioid, url[], title[], string[], Float:sX = 0.0, Float:sY = 0.0, Float:sZ = 0.0, Float:Distance = 0.0, bool:UsePos = false) {
- format(ffile, sizeof(ffile), "%s/Radio%d.rst", STREAM_FOLDER, radioid);
- if(fexist(ffile)) {
- DOF2_SetString(ffile, "url", url);
- DOF2_SetString(ffile, "title", title);
- DOF2_SetString(ffile, "string", string);
- DOF2_SetFloat(ffile, "PosX", sX);
- DOF2_SetFloat(ffile, "PosY", sY);
- DOF2_SetFloat(ffile, "PosZ", sZ);
- DOF2_SetFloat(ffile, "Distance", Distance);
- DOF2_SetBool(ffile, "usspos", UsePos);
- DOF2_SaveFile();
- return true;
- }
- return false;
- }
- stock DeleteRadio(radioid) {
- format(ffile, sizeof(ffile), "%s/Radio%d.rst", STREAM_FOLDER, radioid);
- if(fexist(ffile)) {
- DOF2_RemoveFile(ffile);
- return true;
- }
- return false;
- }
- stock IsRadioExists(radioid) {
- format(ffile, sizeof(ffile), "%s/Radio%d.rst", STREAM_FOLDER, radioid);
- return (fexist(ffile)? (true):(false));
- }
- stock IsValidRadio(radioid) {
- format(ffile, sizeof(ffile), "%s/Radio%d.rst", STREAM_FOLDER, radioid);
- return ((fexist(ffile) && radioid < MAX_STREAM_RADOIS)? (true):(false));
- }
- stock PlayRadio(playerid, radioid) {
- if(!IsRadioExists(radioid)) return false;
- format(ffile, sizeof(ffile), "%s/Radio%d.rst", STREAM_FOLDER, radioid);
- PlayAudioStreamForPlayer(playerid, DOF2_GetString(ffile, "url"), DOF2_GetFloat(ffile, "PosX"), DOF2_GetFloat(ffile, "PosY"), DOF2_GetFloat(ffile, "PosZ"), DOF2_GetFloat(ffile, "Distance"), (DOF2_GetBool(ffile, "usspos"))? (1):(0));
- OnRadioPlayed(radioid, playerid);
- return true;
- }
- stock PlayRadioForAll(radioid) {
- if(!IsRadioExists(radioid)) return false;
- format(ffile, sizeof(ffile), "%s/Radio%d.rst", STREAM_FOLDER, radioid);
- new
- url[MAX_STREAM_URL], Float:Pos[4], usepos;
- format(url, MAX_STREAM_URL, DOF2_GetString(ffile, "url"));
- Pos[0] = DOF2_GetFloat(ffile, "PosX");
- Pos[1] = DOF2_GetFloat(ffile, "PosY");
- Pos[2] = DOF2_GetFloat(ffile, "PosZ");
- Pos[3] = DOF2_GetFloat(ffile, "Distance");
- usepos = (DOF2_GetBool(ffile, "usspos"))? (1):(0);
- for(new i, j = GetMaxPlayers(); i<j; i++) if(IsPlayerConnected(i)) {
- PlayAudioStreamForPlayer(i, url, Pos[0], Pos[1], Pos[2], Pos[3], usepos);
- OnRadioPlayed(radioid, i);
- }
- return true;
- }
- stock GetRadioTitle(radioid) {
- new
- title[MAX_STREAM_TITLE];
- if(IsRadioExists(radioid)) {
- format(ffile, sizeof(ffile), "%s/Radio%d.rst", STREAM_FOLDER, radioid);
- format(title, MAX_STREAM_TITLE, DOF2_GetString(ffile, "title"));
- return title;
- }
- format(title, MAX_STREAM_TITLE, "");
- return title;
- }
- stock GetRadioDesc(radioid) {
- new
- desc[MAX_STREAM_DESC];
- if(IsRadioExists(radioid)) {
- format(ffile, sizeof(ffile), "%s/Radio%d.rst", STREAM_FOLDER, radioid);
- format(desc, MAX_STREAM_DESC, DOF2_GetString(ffile, "string"));
- return desc;
- }
- format(desc, MAX_STREAM_TITLE, "");
- return desc;
- }
- stock CountRadios() {
- for(new i; i<MAX_STREAM_RADOIS; i++) {
- format(ffile, sizeof(ffile), "%s/Radio%d.rst", STREAM_FOLDER, i);
- if(!fexist(ffile)) return i;
- }
- return 0;
- }
- //
- stock AddSong(url[], title[], string[], Float:sX = 0.0, Float:sY = 0.0, Float:sZ = 0.0, Float:Distance = 0.0, bool:UsePos = false) {
- for(new i; i<MAX_STREAM_SONGS; i++) {
- format(ffile, sizeof(ffile), "%s/Song%d.rst", STREAM_FOLDER, i);
- if(!fexist(ffile)) {
- DOF2_CreateFile(ffile);
- DOF2_SetString(ffile, "url", url);
- DOF2_SetString(ffile, "title", title);
- DOF2_SetString(ffile, "string", string);
- DOF2_SetFloat(ffile, "PosX", sX);
- DOF2_SetFloat(ffile, "PosY", sY);
- DOF2_SetFloat(ffile, "PosZ", sZ);
- DOF2_SetFloat(ffile, "Distance", Distance);
- DOF2_SetBool(ffile, "usspos", UsePos);
- DOF2_SaveFile();
- return i;
- }
- }
- return false;
- }
- stock EditSong(songid, url[], title[], string[], Float:sX = 0.0, Float:sY = 0.0, Float:sZ = 0.0, Float:Distance = 0.0, bool:UsePos = false) {
- format(ffile, sizeof(ffile), "%s/Song%d.rst", STREAM_FOLDER, songid);
- if(fexist(ffile)) {
- DOF2_SetString(ffile, "url", url);
- DOF2_SetString(ffile, "title", title);
- DOF2_SetString(ffile, "string", string);
- DOF2_SetFloat(ffile, "PosX", sX);
- DOF2_SetFloat(ffile, "PosY", sY);
- DOF2_SetFloat(ffile, "PosZ", sZ);
- DOF2_SetFloat(ffile, "Distance", Distance);
- DOF2_SetBool(ffile, "usspos", UsePos);
- DOF2_SaveFile();
- return true;
- }
- return false;
- }
- stock DeleteSong(songid) {
- format(ffile, sizeof(ffile), "%s/Song%d.rst", STREAM_FOLDER, songid);
- if(fexist(ffile)) {
- DOF2_RemoveFile(ffile);
- return true;
- }
- return false;
- }
- stock IsSongExists(songid) {
- format(ffile, sizeof(ffile), "%s/Song%d.rst", STREAM_FOLDER, songid);
- return (fexist(ffile)? (true):(false));
- }
- stock IsValidSong(songid) {
- format(ffile, sizeof(ffile), "%s/Song%d.rst", STREAM_FOLDER, songid);
- return ((fexist(ffile) && songid < MAX_STREAM_SONGS)? (true):(false));
- }
- stock PlaySong(playerid, songid) {
- if(!IsSongExists(songid)) return false;
- format(ffile, sizeof(ffile), "%s/Song%d.rst", STREAM_FOLDER, songid);
- PlayAudioStreamForPlayer(playerid, DOF2_GetString(ffile, "url"), DOF2_GetFloat(ffile, "PosX"), DOF2_GetFloat(ffile, "PosY"), DOF2_GetFloat(ffile, "PosZ"), DOF2_GetFloat(ffile, "Distance"), (DOF2_GetBool(ffile, "usspos"))? (1):(0));
- OnSongPlayed(songid, playerid);
- return true;
- }
- stock PlaySongForAll(songid) {
- if(!IsSongExists(songid)) return false;
- format(ffile, sizeof(ffile), "%s/Song%d.rst", STREAM_FOLDER, songid);
- new
- url[MAX_STREAM_URL], Float:Pos[4], usepos;
- format(url, MAX_STREAM_URL, DOF2_GetString(ffile, "url"));
- Pos[0] = DOF2_GetFloat(ffile, "PosX");
- Pos[1] = DOF2_GetFloat(ffile, "PosY");
- Pos[2] = DOF2_GetFloat(ffile, "PosZ");
- Pos[3] = DOF2_GetFloat(ffile, "Distance");
- usepos = (DOF2_GetBool(ffile, "usspos"))? (1):(0);
- for(new i, j = GetMaxPlayers(); i<j; i++) if(IsPlayerConnected(i)) {
- PlayAudioStreamForPlayer(i, url, Pos[0], Pos[1], Pos[2], Pos[3], usepos);
- OnSongPlayed(songid, i);
- }
- return true;
- }
- stock GetSongTitle(songid) {
- new
- title[MAX_STREAM_TITLE];
- if(IsSongExists(songid)) {
- format(ffile, sizeof(ffile), "%s/Song%d.rst", STREAM_FOLDER, songid);
- format(title, MAX_STREAM_TITLE, DOF2_GetString(ffile, "title"));
- return title;
- }
- format(title, MAX_STREAM_TITLE, "");
- return title;
- }
- stock GetSongDesc(songid) {
- new
- desc[MAX_STREAM_DESC];
- if(IsSongExists(songid)) {
- format(ffile, sizeof(ffile), "%s/Song%d.rst", STREAM_FOLDER, songid);
- format(desc, MAX_STREAM_DESC, DOF2_GetString(ffile, "string"));
- return desc;
- }
- format(desc, MAX_STREAM_TITLE, "");
- return desc;
- }
- stock CountSongs() {
- for(new i; i<MAX_STREAM_SONGS; i++) {
- format(ffile, sizeof(ffile), "%s/Song%d.rst", STREAM_FOLDER, i);
- if(!fexist(ffile)) return i;
- }
- return 0;
- }
- //==========================================================================================
Add Comment
Please, Sign In to add comment