Advertisement
SHOROOP

dynamic_radio.inc fork

Apr 16th, 2013 (edited)
372
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 4.24 KB | None | 0 0
  1. //  ---------------------------------------------------------------------
  2. //  -------------------- Dynamic Radio Stations.inc ---------------------
  3. //  ------------------------- (c) Jochemd 2012 --------------------------
  4. //  ------------------------- Forked by SHOROOP -------------------------
  5. //  ---------------------------------------------------------------------
  6.  
  7.  
  8. #include "YSI\y_hooks"
  9.  
  10. #define MAX_RADIO_STATIONS 20
  11. #define NAME_SIZE 30
  12. #define LINK_SIZE 128
  13.  
  14. //#define GM_TRIGGER
  15.  
  16. #define PRESSED(%0) (((newkeys & (%0)) == (%0)) && ((oldkeys & (%0)) != (%0)))
  17.  
  18. #define ENABLE_DEFAULT_STATIONS
  19.  
  20. #define GetVehicleRadioStation(%1) v_VehicleStation[%1]
  21. #define GetStationName(%1) r_RadioInfo[%1][r_Name]
  22.  
  23.  
  24. enum r_info
  25. {
  26.     r_Name[NAME_SIZE],
  27.     r_Link[LINK_SIZE]
  28. };
  29.  
  30.  
  31. new r_RadioInfo[MAX_RADIO_STATIONS][r_info];
  32. new v_VehicleStation[MAX_VEHICLES];
  33. new RadioCount = 0;
  34.  
  35.  
  36. stock IsPlayerInSameVehicle(playerid, asplayerid)
  37. {
  38.     if(GetPlayerVehicleID(playerid) == GetPlayerVehicleID(asplayerid)) return 1;
  39.     else return 0;
  40. }
  41.  
  42. stock InitializeScript()
  43. {
  44.     AddRadioStation("Radio off","Off");
  45.     return 1;
  46. }
  47.  
  48. stock AddRadioStation(name[NAME_SIZE], link[LINK_SIZE])
  49. {
  50.     if(RadioCount == MAX_RADIO_STATIONS - 1)
  51.     {
  52.         printf("Ошибка: необходимо увеличить значение MAX_RADIO_STATIONS. Текущее значение - %d.",MAX_RADIO_STATIONS);
  53.         return -1;
  54.     }
  55.     else
  56.     {
  57.         format(r_RadioInfo[RadioCount][r_Name],NAME_SIZE,"%s",name);
  58.         format(r_RadioInfo[RadioCount][r_Link],LINK_SIZE,"%s",link);
  59.         if(RadioCount) printf("Dynamic Radio System: добавлен поток. ID: %d, название: '%s'",RadioCount,name);
  60.         RadioCount ++;
  61.         return RadioCount -1;
  62.     }  
  63. }
  64.  
  65. stock SetRadioStation(vehicleid, stationid)
  66. {
  67.     v_VehicleStation[vehicleid] = stationid;
  68.     for(new i = 0; i < MAX_PLAYERS; i ++)
  69.     {
  70.         if(IsPlayerConnected(i))
  71.         {
  72.             if(GetPlayerVehicleID(i) == vehicleid)
  73.             {
  74.                 new temp[128];
  75.                 format (temp, sizeof(temp), "~n~~n~~n~~n~~n~~n~~n~~n~~n~~n~%s", r_RadioInfo[stationid][r_Name]);
  76.                 GameTextForPlayer(i, temp, 2000, 3);
  77.                 #if defined ENABLE_DEFAULT_STATIONS
  78.                     if(stationid) PlayAudioStreamForPlayer(i,r_RadioInfo[stationid][r_Link]);
  79.                     else StopAudioStreamForPlayer(i);
  80.                 #else
  81.                     PlayAudioStreamForPlayer(i,r_RadioInfo[stationid][r_Link]);
  82.                 #endif
  83.             }
  84.         }
  85.     }
  86.     return 1;
  87. }
  88.  
  89. stock GetRadioStationsString()
  90. {
  91.     new string[NAME_SIZE * MAX_RADIO_STATIONS],str[NAME_SIZE + 20];
  92.     for(new i = 0; i < MAX_RADIO_STATIONS; i ++)
  93.     {  
  94.         if(!i) format(str,sizeof(str),"{FFFF00}%s{FFFFFF}",r_RadioInfo[i][r_Name]);
  95.         else format(str,sizeof(str),"\n%s",r_RadioInfo[i][r_Name]);
  96.         strcat(string,str,sizeof(string));
  97.     }
  98.     return string;
  99. }
  100.  
  101.  
  102. #if defined GM_TRIGGER
  103. Hook:D_OnGameModeInit() InitializeScript();
  104. #else
  105. Hook:D_OnFilterScriptInit() InitializeScript();
  106. #endif
  107.  
  108. Hook:D_OnPlayerStateChange(playerid, newstate, oldstate)
  109. {
  110.     if(newstate == PLAYER_STATE_DRIVER || newstate == PLAYER_STATE_PASSENGER)
  111.     {
  112.         new vehicleid = GetPlayerVehicleID(playerid),
  113.         playingid = v_VehicleStation[vehicleid];
  114.         new temp[128];
  115.         format (temp, sizeof(temp), "~n~~n~~n~~n~~n~~n~~n~~n~~n~~n~%s", r_RadioInfo[playingid][r_Name]);
  116.         GameTextForPlayer(playerid, temp, 2000, 3);
  117.         #if defined ENABLE_DEFAULT_STATIONS
  118.         if(playingid) PlayAudioStreamForPlayer(playerid,r_RadioInfo[playingid][r_Link]);
  119.         #else
  120.         PlayAudioStreamForPlayer(playerid,r_RadioInfo[playingid][r_Link]);
  121.         #endif
  122.         return 1;
  123.     }
  124.     if(oldstate == PLAYER_STATE_DRIVER || oldstate == PLAYER_STATE_PASSENGER)
  125.     {
  126.         StopAudioStreamForPlayer(playerid);
  127.     }
  128.     return 1;
  129. }
  130.  
  131. Hook:D_OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  132. {
  133.     if(IsPlayerInAnyVehicle(playerid) && GetPlayerState(playerid)==PLAYER_STATE_DRIVER)
  134.     {
  135.         if(PRESSED(KEY_YES))
  136.         {
  137.             new vehicleid = GetPlayerVehicleID(playerid),newstation = v_VehicleStation[vehicleid] + 1;
  138.             if(newstation == RadioCount) newstation = 0;   
  139.             SetRadioStation(vehicleid,newstation);
  140.             return 1;
  141.         }
  142.         else if(PRESSED(KEY_NO))
  143.         {
  144.             new vehicleid = GetPlayerVehicleID(playerid),newstation = v_VehicleStation[vehicleid] - 1;
  145.             if(newstation == -1) newstation = RadioCount - 1;  
  146.             SetRadioStation(vehicleid,newstation);
  147.             return 1;
  148.         }
  149.     }
  150.     return 1;
  151. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement