[HELP]Loop and count players
#1

Can somebody please tell me if this piece of code will work? Because I ain't sure and don't have time to test it and I ain't so good in scripting. I wanted that the server checks if 2 or more players are in some area and if there are, do something.... If 0 or 1 player is in area it suppose to do nothing. Here is what I got.
Код:
  	new count = 0;
		for(new i=0; i<=MAXPLAYERS; i++)
		{
 			if(IsPlayerConnected(i)) count++;
 			if((IsPlayerInArea(bla, bla, bla, bla) && ((count) >= 2));
 			{
 			  //Do something if at least 2 players are in area...
 				return 1;
			}
		}
Reply
#2

pawn Код:
new count = 0;
for(new i=0; i<=MAXPLAYERS; i++)
{
    if(IsPlayerConnected(i)) count++;
    if((IsPlayerInArea(bla, bla, bla, bla) && count >= 2)
    {
      //Do something if at least 2 players are in area...
      return 1;
    }
}
Reply
#3

Thank you. But are you sure that that will work 100%? I have to make sure...

Because i just thought of this-
Код:
if(IsPlayerConnected(i)) count++;
I think this will count player's who are connected and not the players who are in area. So maybe it will check if that player is player in area && count how many player's are online. So I think that won't be right. So maybe it should be like this, no?
Код:
new count = 0;
for(new i=0; i<=MAXPLAYERS; i++)
{
 	if(IsPlayerInArea(bla, bla, bla, bla) count++;
 	if((IsPlayerInArea(bla, bla, bla, bla) && count >= 2)
 	{
 	  //Do something if at least 2 players are in area...
 	  return 1;
    }
}
EXPLANATION: if a player is in area count +1. Then another one comes +1. And if there are 2 or more, do something...
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)