Can we do something like this?
#1

pawn Код:
new ConnectedPlayers;

public OnPlayerConnect(playerid)
{
    ConnectedPlayers++;
    return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
    ConnectedPlayers--;
    return 1;
}

public OnSomethingHappens(playerid)
{
    for(new a = 0, b = ConnectedPlayers; a < b; a++)
    {
        SendClientMessage(a, -1, "hello");
    }
    return 1;
}
Reply
#2

yes why not
Reply
#3

But it's not recommended.

Let's say 5 players join and the IDs 0, 1, 2, 3, 4 are taken. Another 5 players join and the IDs 5, 6, 7, 8, 9 are taken as well. The first 5 players joined leave the game and ConnectedPlayers is 5 and the players (connected players) are: 5, 6, 7, 8, 9.

Your loop will go from 0 to 4 and it will NOT go through the players who are connected.

If you want to optimize the loops for the players, then use foreach. It's really powerful and it loops through the online players ONLY!
Reply
#4

Ahh.. Never thought of that.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)