Radio Problem
#1

The problem is that when you enter the server, and if you go in to anycar as passanger the radio will start palying and never stop, also when you enter a car with radio and turn it on off, leave enter there is no effect, radio just plays, the code is below:

pawn Код:
new RadioIsOn2[MAX_VEHICLES] = 0;
new RadioIsOn[MAX_PLAYERS] = 0;
Turn Radio On
pawn Код:
CarRadio[0][playerid] = Audio_PlayStreamed(playerid, "http://yp.shoutcast.com/sbin/tunein-station.pls?id=1821702",false,false,false);
                    new vehicleid = GetPlayerVehicleID(playerid);
                    RadioIsOn2[vehicleid] = 1;
                    for(new i=0; i<MAX_PLAYERS; i++)
                    {
                        if(GetPlayerVehicleID(i) == GetPlayerVehicleID(playerid))
                        {
                            CarRadio[0][i] = Audio_PlayStreamed(playerid, "http://yp.shoutcast.com/sbin/tunein-station.pls?id=1821702",false,false,false);
                        }
                    }
Turn Radio OFF
pawn Код:
Audio_Stop(playerid, CarRadio[0][playerid]);
                    new vehicleid = GetPlayerVehicleID(playerid);
                    RadioIsOn2[vehicleid] = 0;
                    for(new i=0; i<MAX_PLAYERS; i++)
                    {
                        if(GetPlayerVehicleID(i) == GetPlayerVehicleID(playerid))
                        {
                            Audio_Stop(i, CarRadio[0][playerid]);
                        }
                    }
When you enter and radio is on, it will play for you.
pawn Код:
if(newstate == PLAYER_STATE_DRIVER)
    {

        if(IsPlayerInVehicle(playerid, Vehicle090[playerid]))
        {
            new vehicleid = GetPlayerVehicleID(playerid);
            if(RadioIsOn2[vehicleid] == 1)
            {
                CarRadio[0][playerid] = Audio_PlayStreamed(playerid, "http://yp.shoutcast.com/sbin/tunein-station.pls?id=1821702",false,false,false);
            }
        }
If you enter as passanger radio will come back on if its on
pawn Код:
if(newstate == PLAYER_STATE_PASSENGER)
    {
        new name[MAX_PLAYER_NAME];
        GetPlayerName(playerid, name, sizeof(name));
        new vehicleid = GetPlayerVehicleID(playerid);
        for(new i = 0; i < MAX_PLAYERS; i++)
        {
            if(IsPlayerConnected(i))
            {
                for(new i=0; i<MAX_PLAYERS; i++)
                {
                    if(GetPlayerVehicleID(i) == GetPlayerVehicleID(playerid))
                    {
                        CarRadio[0][i] = Audio_PlayStreamed(playerid, "http://yp.shoutcast.com/sbin/tunein-station.pls?id=1821702",false,false,false);
                    }
                }
Stop Radio When you leave the car
pawn Код:
if(newstate == PLAYER_STATE_ONFOOT)
    {
        for(new i=0; i<MAX_PLAYERS; i++)
        {
            if(GetPlayerVehicleID(i) == GetPlayerVehicleID(playerid))
            {
                Audio_Stop(i, CarRadio[0][i]);
            }
        }
        Audio_Stop(playerid, CarRadio[0][playerid]);
Any ideas?
Reply
#2

The last section, the bit of code that checks whether they've exited:

pawn Код:
if(newstate == PLAYER_STATE_ONFOOT)
    {
        for(new i=0; i<MAX_PLAYERS; i++)
        {
            if(GetPlayerVehicleID(i) == GetPlayerVehicleID(playerid))
            {
                Audio_Stop(i, CarRadio[0][i]);
            }
        }
        Audio_Stop(playerid, CarRadio[0][playerid]);
is quite redundant; Firstly, I don't see the point in this check?

pawn Код:
// .. for loop through players
if(GetPlayerVehicleID(i) == GetPlayerVehicleID(playerid))
// ..
This just runs through the entire player list and checks whether their vehicleid is the same as the player's one - which will only return the player's - because vehicle id's are unique, thus making this bit of code quite pointless.

Secondly, it's not essential, but I don't know why CarRadio is a multidimensional array? You're always calling index 0 of it:

pawn Код:
// ..
CarRadio[0][playerid]

And lastly, it checks whether the player is on foot, then if it evaluates as true it executes code to check the player's vehicle id - which they cannot be within; because they are on foot - because of the previous evaluation. This will just return false or 0, resulting in wrong values being called, and ultimately - errors.

You could fix this by removing the redundant checks, to stop the player's radio regardless of what vehicle they're in:

pawn Код:
if(newstate == PLAYER_STATE_ONFOOT)
{
    Audio_Stop(playerid, CarRadio[0][playerid]);
}
Reply
#3

Ive made some changes and radio doesnt start until i turn it on, but when i exit vehicle the radio stays on.

Im using Audio_Stop(playerid, CarRadio[0][playerid]); at OnPlayerExitVehicle and Audio_Stop(playerid, CarRadio[0][playerid]); if(newstate == PLAYER_STATE_ONFOOT)

But the radio (CarRadio[0][playerid] = Audio_PlayStreamed(playerid, "http://yp.shoutcast.com/sbin/tunein-station.pls?id=1821702",false,false,false) still stays on.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)