RaFaeLs

Plug n Use Static Streaming system (rStream)

Oct 5th, 2012
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 10.43 KB | None | 0 0
  1. /*
  2.     * By RaFaeL zilberman (c) 2012
  3.     * This include have writed for Sa:Mp - San andress multi player!
  4.     *
  5. */
  6.  
  7. #if defined _Radio_included
  8.   #endinput
  9. #endif
  10. #if !defined _dof2_included
  11.   #error DOF2 isn't included, please include and tsY again!
  12. #endif
  13.  
  14. #define _Radio_included
  15.  
  16. //==========================================================================================
  17.  
  18. #define MAX_STREAM_URL        128
  19. #define MAX_STREAM_TITLE      32
  20. #define MAX_STREAM_DESC       64
  21. #define MAX_STREAM_RADOIS     15
  22. #define MAX_STREAM_SONGS      15
  23.  
  24. #define STREAM_FOLDER         "Stream"
  25. #define STREAM_FILE_RADIO     "Radio.rst"
  26. #define STREAM_FILE_SONG      "Song.rst"
  27.  
  28. //==========================================================================================
  29.  
  30. /*
  31.     * Version of file is 0.1 [BETA] realease
  32.     * Use only for radio streaming!
  33.     *** Reguired DOF2 files include for currect working
  34. */
  35.  
  36. /*
  37. native CheckStreamFiles();
  38. native StopStreamForPlayer(playerid);
  39. native StopStreamForAllPlayers();
  40.  
  41. 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
  42. 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
  43. native DeleteRadio(radioid); //Return: T/F
  44. native IsRadioExists(radioid); //Return: T/F
  45. native IsValidRadio(radioid); //Return: T/F
  46. native PlayRadio(playerid, radioid);
  47. native PlayRadioForAll(radioid);
  48. native GetRadioTitle(radioid);
  49. native GetRadioDesc(radioid);
  50. native CountRadios();
  51.  
  52. 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
  53. 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
  54. native DeleteSong(songid); //Return: T/F
  55. native IsSongExists(songid); //Return: T/F
  56. native IsValidSong(songid); //Return: T/F
  57. native PlaySong(playerid, songid);
  58. native PlaySongForAll(songid);
  59. native CountSongs();
  60. */
  61.  
  62. forward OnRadioPlayed(radioid, playerid);
  63. forward OnSongPlayed(songid, playerid);
  64.  
  65. new
  66.     ffile[50], str[128];
  67.  
  68. //==========================================================================================
  69.  
  70. stock CheckStreamFiles() {
  71.     if(!fexist(STREAM_FILE_RADIO)) DOF2_CreateFile(STREAM_FILE_RADIO);
  72.     if(!fexist(STREAM_FILE_SONG)) DOF2_CreateFile(STREAM_FILE_SONG);
  73.    
  74.     return true;
  75. }
  76. stock StopStreamForPlayer(playerid) {
  77.     StopAudioStreamForPlayer(playerid);
  78.  
  79.     return true;
  80. }
  81. stock StopStreamForAll() {
  82.     for(new i, j = GetMaxPlayers(); i<j; i++) if(IsPlayerConnected(i)) StopAudioStreamForPlayer(i);
  83.  
  84.     return true;
  85. }
  86.  
  87. stock CreateRadio(url[], title[], string[], Float:sX = 0.0, Float:sY = 0.0, Float:sZ = 0.0, Float:Distance = 0.0, bool:UsePos = false) {
  88.    
  89.     for(new i; i<MAX_STREAM_RADOIS; i++) {
  90.         format(ffile, sizeof(ffile), "%s/Radio%d.rst", STREAM_FOLDER, i);
  91.         if(!fexist(ffile)) {
  92.            
  93.             DOF2_CreateFile(ffile);
  94.             DOF2_SetString(ffile, "url", url);
  95.             DOF2_SetString(ffile, "title", title);
  96.             DOF2_SetString(ffile, "string", string);
  97.             DOF2_SetFloat(ffile, "PosX", sX);
  98.             DOF2_SetFloat(ffile, "PosY", sY);
  99.             DOF2_SetFloat(ffile, "PosZ", sZ);
  100.             DOF2_SetFloat(ffile, "Distance", Distance);
  101.             DOF2_SetBool(ffile, "usspos", UsePos);
  102.            
  103.             DOF2_SaveFile();
  104.             return i;
  105.            
  106.         }
  107.     }
  108.    
  109.     return false;
  110. }
  111. 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) {
  112.    
  113.     format(ffile, sizeof(ffile), "%s/Radio%d.rst", STREAM_FOLDER, radioid);
  114.     if(fexist(ffile)) {
  115.        
  116.         DOF2_SetString(ffile, "url", url);
  117.         DOF2_SetString(ffile, "title", title);
  118.         DOF2_SetString(ffile, "string", string);
  119.         DOF2_SetFloat(ffile, "PosX", sX);
  120.         DOF2_SetFloat(ffile, "PosY", sY);
  121.         DOF2_SetFloat(ffile, "PosZ", sZ);
  122.         DOF2_SetFloat(ffile, "Distance", Distance);
  123.         DOF2_SetBool(ffile, "usspos", UsePos);
  124.        
  125.         DOF2_SaveFile();
  126.         return true;
  127.        
  128.     }
  129.    
  130.     return false;
  131. }
  132. stock DeleteRadio(radioid) {
  133.    
  134.     format(ffile, sizeof(ffile), "%s/Radio%d.rst", STREAM_FOLDER, radioid);
  135.     if(fexist(ffile)) {
  136.        
  137.         DOF2_RemoveFile(ffile);
  138.         return true;
  139.        
  140.     }
  141.    
  142.     return false;
  143. }
  144. stock IsRadioExists(radioid) {
  145.    
  146.     format(ffile, sizeof(ffile), "%s/Radio%d.rst", STREAM_FOLDER, radioid);
  147.    
  148.     return (fexist(ffile)? (true):(false));
  149. }
  150. stock IsValidRadio(radioid) {
  151.     format(ffile, sizeof(ffile), "%s/Radio%d.rst", STREAM_FOLDER, radioid);
  152.    
  153.     return ((fexist(ffile) && radioid < MAX_STREAM_RADOIS)? (true):(false));
  154. }
  155. stock PlayRadio(playerid, radioid) {
  156.     if(!IsRadioExists(radioid)) return false;
  157.    
  158.     format(ffile, sizeof(ffile), "%s/Radio%d.rst", STREAM_FOLDER, radioid);
  159.    
  160.     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));
  161.     OnRadioPlayed(radioid, playerid);
  162.    
  163.     return true;
  164. }
  165. stock PlayRadioForAll(radioid) {
  166.     if(!IsRadioExists(radioid)) return false;
  167.    
  168.     format(ffile, sizeof(ffile), "%s/Radio%d.rst", STREAM_FOLDER, radioid);
  169.     new
  170.         url[MAX_STREAM_URL], Float:Pos[4], usepos;
  171.    
  172.     format(url, MAX_STREAM_URL, DOF2_GetString(ffile, "url"));
  173.     Pos[0] = DOF2_GetFloat(ffile, "PosX");
  174.     Pos[1] = DOF2_GetFloat(ffile, "PosY");
  175.     Pos[2] = DOF2_GetFloat(ffile, "PosZ");
  176.     Pos[3] = DOF2_GetFloat(ffile, "Distance");
  177.     usepos = (DOF2_GetBool(ffile, "usspos"))? (1):(0);
  178.    
  179.     for(new i, j = GetMaxPlayers(); i<j; i++) if(IsPlayerConnected(i)) {
  180.         PlayAudioStreamForPlayer(i, url, Pos[0], Pos[1], Pos[2], Pos[3], usepos);
  181.         OnRadioPlayed(radioid, i);
  182.     }
  183.  
  184.     return true;
  185. }
  186. stock GetRadioTitle(radioid) {
  187.     new
  188.         title[MAX_STREAM_TITLE];
  189.        
  190.     if(IsRadioExists(radioid)) {       
  191.         format(ffile, sizeof(ffile), "%s/Radio%d.rst", STREAM_FOLDER, radioid);
  192.         format(title, MAX_STREAM_TITLE, DOF2_GetString(ffile, "title"));
  193.        
  194.         return title;
  195.     }
  196.     format(title, MAX_STREAM_TITLE, "");
  197.     return title;
  198. }
  199. stock GetRadioDesc(radioid) {
  200.     new
  201.         desc[MAX_STREAM_DESC];
  202.            
  203.     if(IsRadioExists(radioid)) {
  204.         format(ffile, sizeof(ffile), "%s/Radio%d.rst", STREAM_FOLDER, radioid);
  205.         format(desc, MAX_STREAM_DESC, DOF2_GetString(ffile, "string"));
  206.        
  207.         return desc;
  208.     }
  209.     format(desc, MAX_STREAM_TITLE, "");
  210.     return desc;
  211. }
  212. stock CountRadios() {
  213.     for(new i; i<MAX_STREAM_RADOIS; i++) {
  214.         format(ffile, sizeof(ffile), "%s/Radio%d.rst", STREAM_FOLDER, i);
  215.         if(!fexist(ffile)) return i;
  216.     }
  217.    
  218.     return 0;
  219. }
  220. //
  221. stock AddSong(url[], title[], string[], Float:sX = 0.0, Float:sY = 0.0, Float:sZ = 0.0, Float:Distance = 0.0, bool:UsePos = false) {
  222.    
  223.     for(new i; i<MAX_STREAM_SONGS; i++) {
  224.         format(ffile, sizeof(ffile), "%s/Song%d.rst", STREAM_FOLDER, i);
  225.         if(!fexist(ffile)) {
  226.            
  227.             DOF2_CreateFile(ffile);
  228.             DOF2_SetString(ffile, "url", url);
  229.             DOF2_SetString(ffile, "title", title);
  230.             DOF2_SetString(ffile, "string", string);
  231.             DOF2_SetFloat(ffile, "PosX", sX);
  232.             DOF2_SetFloat(ffile, "PosY", sY);
  233.             DOF2_SetFloat(ffile, "PosZ", sZ);
  234.             DOF2_SetFloat(ffile, "Distance", Distance);
  235.             DOF2_SetBool(ffile, "usspos", UsePos);
  236.            
  237.             DOF2_SaveFile();
  238.             return i;
  239.            
  240.         }
  241.     }
  242.    
  243.     return false;
  244. }
  245. 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) {
  246.    
  247.     format(ffile, sizeof(ffile), "%s/Song%d.rst", STREAM_FOLDER, songid);
  248.     if(fexist(ffile)) {
  249.        
  250.         DOF2_SetString(ffile, "url", url);
  251.         DOF2_SetString(ffile, "title", title);
  252.         DOF2_SetString(ffile, "string", string);
  253.         DOF2_SetFloat(ffile, "PosX", sX);
  254.         DOF2_SetFloat(ffile, "PosY", sY);
  255.         DOF2_SetFloat(ffile, "PosZ", sZ);
  256.         DOF2_SetFloat(ffile, "Distance", Distance);
  257.         DOF2_SetBool(ffile, "usspos", UsePos);
  258.        
  259.         DOF2_SaveFile();
  260.         return true;
  261.        
  262.     }
  263.    
  264.     return false;
  265. }
  266. stock DeleteSong(songid) {
  267.    
  268.     format(ffile, sizeof(ffile), "%s/Song%d.rst", STREAM_FOLDER, songid);
  269.     if(fexist(ffile)) {
  270.        
  271.         DOF2_RemoveFile(ffile);
  272.         return true;
  273.        
  274.     }
  275.    
  276.     return false;
  277. }
  278. stock IsSongExists(songid) {
  279.    
  280.     format(ffile, sizeof(ffile), "%s/Song%d.rst", STREAM_FOLDER, songid);
  281.    
  282.     return (fexist(ffile)? (true):(false));
  283. }
  284. stock IsValidSong(songid) {
  285.     format(ffile, sizeof(ffile), "%s/Song%d.rst", STREAM_FOLDER, songid);
  286.    
  287.     return ((fexist(ffile) && songid < MAX_STREAM_SONGS)? (true):(false));
  288. }
  289. stock PlaySong(playerid, songid) {
  290.     if(!IsSongExists(songid)) return false;
  291.    
  292.     format(ffile, sizeof(ffile), "%s/Song%d.rst", STREAM_FOLDER, songid);
  293.    
  294.     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));
  295.     OnSongPlayed(songid, playerid);
  296.    
  297.     return true;
  298. }
  299. stock PlaySongForAll(songid) {
  300.     if(!IsSongExists(songid)) return false;
  301.    
  302.     format(ffile, sizeof(ffile), "%s/Song%d.rst", STREAM_FOLDER, songid);
  303.     new
  304.         url[MAX_STREAM_URL], Float:Pos[4], usepos;
  305.    
  306.     format(url, MAX_STREAM_URL, DOF2_GetString(ffile, "url"));
  307.     Pos[0] = DOF2_GetFloat(ffile, "PosX");
  308.     Pos[1] = DOF2_GetFloat(ffile, "PosY");
  309.     Pos[2] = DOF2_GetFloat(ffile, "PosZ");
  310.     Pos[3] = DOF2_GetFloat(ffile, "Distance");
  311.     usepos = (DOF2_GetBool(ffile, "usspos"))? (1):(0);
  312.    
  313.     for(new i, j = GetMaxPlayers(); i<j; i++) if(IsPlayerConnected(i)) {
  314.         PlayAudioStreamForPlayer(i, url, Pos[0], Pos[1], Pos[2], Pos[3], usepos);
  315.         OnSongPlayed(songid, i);
  316.     }
  317.  
  318.     return true;
  319. }
  320. stock GetSongTitle(songid) {
  321.     new
  322.         title[MAX_STREAM_TITLE];
  323.        
  324.     if(IsSongExists(songid)) {     
  325.         format(ffile, sizeof(ffile), "%s/Song%d.rst", STREAM_FOLDER, songid);
  326.         format(title, MAX_STREAM_TITLE, DOF2_GetString(ffile, "title"));
  327.        
  328.         return title;
  329.     }
  330.     format(title, MAX_STREAM_TITLE, "");
  331.     return title;
  332. }
  333. stock GetSongDesc(songid) {
  334.     new
  335.         desc[MAX_STREAM_DESC];
  336.            
  337.     if(IsSongExists(songid)) {
  338.         format(ffile, sizeof(ffile), "%s/Song%d.rst", STREAM_FOLDER, songid);
  339.         format(desc, MAX_STREAM_DESC, DOF2_GetString(ffile, "string"));
  340.        
  341.         return desc;
  342.     }
  343.     format(desc, MAX_STREAM_TITLE, "");
  344.     return desc;
  345. }
  346. stock CountSongs() {
  347.     for(new i; i<MAX_STREAM_SONGS; i++) {
  348.         format(ffile, sizeof(ffile), "%s/Song%d.rst", STREAM_FOLDER, i);
  349.         if(!fexist(ffile)) return i;
  350.     }
  351.    
  352.     return 0;
  353. }
  354.  
  355. //==========================================================================================
Add Comment
Please, Sign In to add comment