Problem with my radio script (regarding PlayAudioStreamForPlayer)
#1

Hello there folks,

So the past five days I've been working on a radio script. The script allows you to place a radio (object) onto the ground and set it to a specefic channel. Setting this channel will cause all the near players to hear the stream. Once they get out of the range of the radio, the stream will stop. This is basically so different people will be able to place radios on different locations.

pawn Код:
forward Boombox(playerid);
public Boombox(playerid)
{
    foreach(Player,i) // Looping through all the players
    {
        if(pInfo[i][BoomboxStreamOn] == 1) // If a player has a radio which has it's stream on.
        {
            if(IsPlayerInRangeOfPoint(playerid, 40, pInfo[i][BoomboxX], pInfo[i][BoomboxY], pInfo[i][BoomboxZ]))
// If the player (where the timer is set for) is in range of a radio of another player where the stream is on from.
            {
                if(pInfo[playerid][ListeningBoombox] == 0) // Checking if the player already listens to a stream.
                {
                    pInfo[playerid][ListeningBoombox] = 1; // Setting the listening variable to 1.
                    new Float:Distance = 40;
                    PlayAudioStreamForPlayer(playerid, pInfo[i][BoomboxStream], pInfo[i][BoomboxX], pInfo[i][BoomboxY], pInfo[i][BoomboxZ], Distance, 1); // Play the stream.
                }
            }
            else
            {
                pInfo[playerid][ListeningBoombox] = 0; // Listening variable to 0.
                StopAudioStreamForPlayer(playerid); // Stopping stream.
            }
        }
        else
        {
            pInfo[playerid][ListeningBoombox] = 0;
            StopAudioStreamForPlayer(playerid);
        }
    }
   
    return 1;
}
As you can see I made a timer for each player seperatly. This timer will repeat itself every second. It's basically regarding the fact if someone comes near a radio, it will the play the stream for him/her, and if they get out of range, it will stop. My problem seems taking place in this code.

Right now, if I test this and there are a couple of players online, the stream does not start for the person where the radio is from, while the other players will get the stream get spammed in the chat non-stop.

I hope anyone has the right solution for this problem and I'd really appreciate some assistance!

Greetings,
Chilco.
Reply
#2

48 hours passed so I think I'm allowed to bump it now. I didn't find any solutions yet and tried many things out. Hope someone is able to help me.
Reply
#3

Ahh I finally found your problem

This is what's happening:

Let's take that you are playerid 0, and there are two other players: 1 and 2
1 and 2 have created a radio.

You enter the range of player1's radio, so it starts streaming.
In that same loop, the code detects that you are Not in range of player2's radio. So the streaming stops.


Your solution would be to create a variable that tracks who's radio player0 is listening to.
StopAudioStream may only happen if the playerid of that variable has been changed

Another solution is to make sure that StopAudioStream is only called when the player is in range of None radio.
(so don't call it from the moment the player isn't in range of A radio, but only call it if the player isn't in range of Any radio).
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)