Boombox problem.. Help.
#1

I created a boombox, anyone that owns one can use /placeboombox, /setboombox and /pickupboombox. All of these commands work, except I have a problem with playing music:
pawn Код:
forward BoomboxPlay(playerid);
public BoomboxPlay(playerid)
{
    foreach(Player, i)
    {
        if(IsPlayerInRangeOfPoint(playerid, 30.0, GetPVarFloat(i, "Boombox_FLOAT_X"), GetPVarFloat(i, "Boombox_FLOAT_Y"), GetPVarFloat(i, "Boombox_FLOAT_Z")))
        {
            if(IsPlayerInAnyVehicle(playerid)) return 1;
            if(BoomboxListen[playerid] != BoomboxStation[i])
            {
                new station[64];
                switch(BoomboxStation[i])
                {
                    case 1:
                    {
                        format(station, sizeof(station), "http://yp.shoutcast.com/sbin/tunein-station.pls?id=1280356");
                        BoomboxListen[playerid] = 1;
                    }
                    case 2:
                    {
                        format(station, sizeof(station), "http://yp.shoutcast.com/sbin/tunein-station.pls?id=1281016");
                        BoomboxListen[playerid] = 2;
                    }
                    case 3:
                    {
                        format(station, sizeof(station), "http://yp.shoutcast.com/sbin/tunein-station.pls?id=1283896");
                        BoomboxListen[playerid] = 3;
                    }
                    case 4:
                    {
                        format(station, sizeof(station), "http://yp.shoutcast.com/sbin/tunein-station.pls?id=616366&");
                        BoomboxListen[playerid] = 4;
                    }
                    case 5:
                    {
                        format(station, sizeof(station), "http://yp.shoutcast.com/sbin/tunein-station.pls?id=663859&");
                        BoomboxListen[playerid] = 5;
                    }
                    case 6:
                    {
                        format(station, sizeof(station), "http://yp.shoutcast.com/sbin/tunein-station.pls?id=1283516&");
                        BoomboxListen[playerid] = 6;
                    }
                }
                PlayAudioStreamForPlayer(playerid, station, GetPVarFloat(i, "Boombox_FLOAT_X"), GetPVarFloat(i, "Boombox_FLOAT_Y"), GetPVarFloat(i, "Boombox_FLOAT_Z"), 30, 1); // Play the stream.
            }
        }
        else
        {
            if(BoomboxListen[playerid] > 0)
            {
                BoomboxListen[playerid] = 0;
                StopAudioStreamForPlayer(playerid);
            }
        }
    }
    return 1;
}
Now the problem is, when two people are on-line (or more of course), the players chat fills with spam audio messages (More players = more spam), which bugs the player and the audio wont stop. I have a small idea into the problem, which is the players audio 'BoomboxListen[playerid]' matches the boombox in which the player is near, except the other players boombox (which is not placed) is interfeing and doesnt match the players 'BoomboxListen[playerid]' which results in the station chaging (the spam), I don't know how the other part is executed due to the other players boombox not being placed? However, I don't have any idea on how I can stop this. Help?!

By the way, "BoomboxPlay(playerid);" is called every second.. With a timer.
Reply
#2

well idk whats wrong here but it seems ur not using audio plugin
and cool boombox i wish i had one i been lookin for one for years and never find one
Reply
#3

Then audio plays if one person is on-line and the boom-box works perfectly, the problem occurs when more than 1 person is on-line. It's not a problem the the audio plugin.
Reply
#4

Bump.. (I think it's 24 hours?.. Lol)
If there's no solution to this, how else could I do it?
Reply
#5

Well i take it you have one main timer calling that? Like just SetTimer? If so then either change all your "playerid" in that function over to "i" and get rid of the playerid param so it would be only
pawn Код:
forward BoomboxPlay();
public BoomboxPlay()
or you could set individual timers like SetTimerEx and get rid of the foreach loop and just change all the "i" over to playerid.
Cause how you have it your checking everyones positon then just checking if playerid is in a car (if you only used SetTimer then it only works for id 0).

So what i am saying is either switch to playerid or get rid of player id and just use the loop and make all the playerid's "i".
Reply
#6

That function-loop posted by the OP is a nightmare. You have a function that looks for playerid, and then you loop through all the players, except you don't because you're using a player-loop (foreach Player,i) to loop through radio stations.

I strongly advise against individual timers. Do a SetTimer, and do a loop in that. W/ that loop, check each players proximity to each boombox and act accordingly. Careful: this timer/loop can get wildly out of control REALLY easily, so pay close attention and make sure you are being efficient about everything.
Reply
#7

I don't use individual timers, "BoomboxPlay(playerid);" is in a one and the only one global timer which is called every second, I just used a separate function to avoid clutter (A bit OCD .. lol). I removed the 'playerid' in exchange for 'i', however the problem still occurs. When I was testing apparently playerid 1 didn't get spammed, like playerid 0 did. I've attempted many things but still no luck. This is what I've got now:

pawn Код:
forward BoomboxPlay();
public BoomboxPlay()
{
    foreach(Player, i)
    {
        if(IsPlayerInRangeOfPoint(i, 35.0, GetPVarFloat(i, "DYN_Boombox_FLOAT_X"), GetPVarFloat(i, "DYN_Boombox_FLOAT_Y"), GetPVarFloat(i, "DYN_Boombox_FLOAT_Z")))
        {
            if(IsPlayerInAnyVehicle(i)) return 1;
            if(BoomboxListen[i] != BoomboxStation[i])
            {
                new station[64];
                switch(BoomboxStation[i])
                {
                    case 1:
                    {
                        format(station, sizeof(station), "http://yp.shoutcast.com/sbin/tunein-station.pls?id=1280356");
                        BoomboxListen[i] = 1;
                    }
                    case 2:
                    {
                        format(station, sizeof(station), "http://yp.shoutcast.com/sbin/tunein-station.pls?id=1281016");
                        BoomboxListen[i] = 2;
                    }
                    case 3:
                    {
                        format(station, sizeof(station), "http://yp.shoutcast.com/sbin/tunein-station.pls?id=1283896");
                        BoomboxListen[i] = 3;
                    }
                    case 4:
                    {
                        format(station, sizeof(station), "http://yp.shoutcast.com/sbin/tunein-station.pls?id=616366&");
                        BoomboxListen[i] = 4;
                    }
                    case 5:
                    {
                        format(station, sizeof(station), "http://yp.shoutcast.com/sbin/tunein-station.pls?id=663859&");
                        BoomboxListen[i] = 5;
                    }
                    case 6:
                    {
                        format(station, sizeof(station), "http://yp.shoutcast.com/sbin/tunein-station.pls?id=1283516&");
                        BoomboxListen[i] = 6;
                    }
                }
                PlayAudioStreamForPlayer(i, station, GetPVarFloat(i, "DYN_Boombox_FLOAT_X"), GetPVarFloat(i, "DYN_Boombox_FLOAT_Y"), GetPVarFloat(i, "DYN_Boombox_FLOAT_Z"), 35, 1); // Play the stream.
            }
        }
        else
        {
            if(BoomboxListen[i] > 0)
            {
                BoomboxListen[i] = 0;
                StopAudioStreamForPlayer(i);
            }
        }
    }
    return 1;
}
Timer:

pawn Код:
public MainTimer() // One and only timer!
{
    new string[128];
    foreach(Player, i)
    {
        BoomboxPlay();
            //Rest of code...
pawn Код:
public OnGameModeInit()
{
    SetTimer("MainTimer", 1000, true);
Suggestion?

Edit: Doesn't spam any more, but the player who placed it is the only one who can hear it.
Reply
#8

Bump! Update: After changing the script many times and resulting in problems, this is what I've got now! (Code above only played for the player who placed the Boombox)

pawn Код:
forward BoomboxPlay();
public BoomboxPlay()
{
    foreach(Player, i)
    {
        foreach(Player, x)
        {
            if(IsPlayerInRangeOfPoint(i, 35.0, BoomboxPosition[x][0], BoomboxPosition[x][1],BoomboxPosition[x][2]))
            {
                if(IsPlayerInAnyVehicle(i)) return 1;
                if(BoomboxListen[i] != BoomboxStation[x])
                {
                    new station[64];
                    switch(BoomboxStation[x])
                    {
                        case 1:
                        {
                            format(station, sizeof(station), "http://yp.shoutcast.com/sbin/tunein-station.pls?id=1280356");
                            BoomboxListen[i] = 1;
                        }
                        case 2:
                        {
                            format(station, sizeof(station), "http://yp.shoutcast.com/sbin/tunein-station.pls?id=1281016");
                            BoomboxListen[i] = 2;
                        }
                        case 3:
                        {
                            format(station, sizeof(station), "http://yp.shoutcast.com/sbin/tunein-station.pls?id=1283896");
                            BoomboxListen[i] = 3;
                        }
                        case 4:
                        {
                            format(station, sizeof(station), "http://yp.shoutcast.com/sbin/tunein-station.pls?id=616366&");
                            BoomboxListen[i] = 4;
                        }
                        case 5:
                        {
                            format(station, sizeof(station), "http://yp.shoutcast.com/sbin/tunein-station.pls?id=663859&");
                            BoomboxListen[i] = 5;
                        }
                        case 6:
                        {
                            format(station, sizeof(station), "http://yp.shoutcast.com/sbin/tunein-station.pls?id=1283516&");
                            BoomboxListen[i] = 6;
                        }
                    }
                    PlayAudioStreamForPlayer(i, station, BoomboxPosition[x][0], BoomboxPosition[x][1],BoomboxPosition[x][2], 35, 1); // Play the stream.
                }
            }
            else
            {
                if(BoomboxListen[i] > 0)
                {
                    BoomboxListen[i] = 0;
                    StopAudioStreamForPlayer(i);
                }
            }
        }
    }
    return 1;
}
This code only plays when one person is online and spams audio when more than one person is online, cannot figure out how to fix it!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)