Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ---------------------------------------------------------------------
- // -------------------- Dynamic Radio Stations.inc ---------------------
- // ------------------------- (c) Jochemd 2012 --------------------------
- // ------------------------- Forked by SHOROOP -------------------------
- // ---------------------------------------------------------------------
- #include "YSI\y_hooks"
- #define MAX_RADIO_STATIONS 20
- #define NAME_SIZE 30
- #define LINK_SIZE 128
- //#define GM_TRIGGER
- #define PRESSED(%0) (((newkeys & (%0)) == (%0)) && ((oldkeys & (%0)) != (%0)))
- #define ENABLE_DEFAULT_STATIONS
- #define GetVehicleRadioStation(%1) v_VehicleStation[%1]
- #define GetStationName(%1) r_RadioInfo[%1][r_Name]
- enum r_info
- {
- r_Name[NAME_SIZE],
- r_Link[LINK_SIZE]
- };
- new r_RadioInfo[MAX_RADIO_STATIONS][r_info];
- new v_VehicleStation[MAX_VEHICLES];
- new RadioCount = 0;
- stock IsPlayerInSameVehicle(playerid, asplayerid)
- {
- if(GetPlayerVehicleID(playerid) == GetPlayerVehicleID(asplayerid)) return 1;
- else return 0;
- }
- stock InitializeScript()
- {
- AddRadioStation("Radio off","Off");
- return 1;
- }
- stock AddRadioStation(name[NAME_SIZE], link[LINK_SIZE])
- {
- if(RadioCount == MAX_RADIO_STATIONS - 1)
- {
- printf("Ошибка: необходимо увеличить значение MAX_RADIO_STATIONS. Текущее значение - %d.",MAX_RADIO_STATIONS);
- return -1;
- }
- else
- {
- format(r_RadioInfo[RadioCount][r_Name],NAME_SIZE,"%s",name);
- format(r_RadioInfo[RadioCount][r_Link],LINK_SIZE,"%s",link);
- if(RadioCount) printf("Dynamic Radio System: добавлен поток. ID: %d, название: '%s'",RadioCount,name);
- RadioCount ++;
- return RadioCount -1;
- }
- }
- stock SetRadioStation(vehicleid, stationid)
- {
- v_VehicleStation[vehicleid] = stationid;
- for(new i = 0; i < MAX_PLAYERS; i ++)
- {
- if(IsPlayerConnected(i))
- {
- if(GetPlayerVehicleID(i) == vehicleid)
- {
- new temp[128];
- format (temp, sizeof(temp), "~n~~n~~n~~n~~n~~n~~n~~n~~n~~n~%s", r_RadioInfo[stationid][r_Name]);
- GameTextForPlayer(i, temp, 2000, 3);
- #if defined ENABLE_DEFAULT_STATIONS
- if(stationid) PlayAudioStreamForPlayer(i,r_RadioInfo[stationid][r_Link]);
- else StopAudioStreamForPlayer(i);
- #else
- PlayAudioStreamForPlayer(i,r_RadioInfo[stationid][r_Link]);
- #endif
- }
- }
- }
- return 1;
- }
- stock GetRadioStationsString()
- {
- new string[NAME_SIZE * MAX_RADIO_STATIONS],str[NAME_SIZE + 20];
- for(new i = 0; i < MAX_RADIO_STATIONS; i ++)
- {
- if(!i) format(str,sizeof(str),"{FFFF00}%s{FFFFFF}",r_RadioInfo[i][r_Name]);
- else format(str,sizeof(str),"\n%s",r_RadioInfo[i][r_Name]);
- strcat(string,str,sizeof(string));
- }
- return string;
- }
- #if defined GM_TRIGGER
- Hook:D_OnGameModeInit() InitializeScript();
- #else
- Hook:D_OnFilterScriptInit() InitializeScript();
- #endif
- Hook:D_OnPlayerStateChange(playerid, newstate, oldstate)
- {
- if(newstate == PLAYER_STATE_DRIVER || newstate == PLAYER_STATE_PASSENGER)
- {
- new vehicleid = GetPlayerVehicleID(playerid),
- playingid = v_VehicleStation[vehicleid];
- new temp[128];
- format (temp, sizeof(temp), "~n~~n~~n~~n~~n~~n~~n~~n~~n~~n~%s", r_RadioInfo[playingid][r_Name]);
- GameTextForPlayer(playerid, temp, 2000, 3);
- #if defined ENABLE_DEFAULT_STATIONS
- if(playingid) PlayAudioStreamForPlayer(playerid,r_RadioInfo[playingid][r_Link]);
- #else
- PlayAudioStreamForPlayer(playerid,r_RadioInfo[playingid][r_Link]);
- #endif
- return 1;
- }
- if(oldstate == PLAYER_STATE_DRIVER || oldstate == PLAYER_STATE_PASSENGER)
- {
- StopAudioStreamForPlayer(playerid);
- }
- return 1;
- }
- Hook:D_OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
- {
- if(IsPlayerInAnyVehicle(playerid) && GetPlayerState(playerid)==PLAYER_STATE_DRIVER)
- {
- if(PRESSED(KEY_YES))
- {
- new vehicleid = GetPlayerVehicleID(playerid),newstation = v_VehicleStation[vehicleid] + 1;
- if(newstation == RadioCount) newstation = 0;
- SetRadioStation(vehicleid,newstation);
- return 1;
- }
- else if(PRESSED(KEY_NO))
- {
- new vehicleid = GetPlayerVehicleID(playerid),newstation = v_VehicleStation[vehicleid] - 1;
- if(newstation == -1) newstation = RadioCount - 1;
- SetRadioStation(vehicleid,newstation);
- return 1;
- }
- }
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement