[HELP]Loop and count players - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: [HELP]Loop and count players (
/showthread.php?tid=121271)
[HELP]Loop and count players -
[HT]playstation - 16.01.2010
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;
}
}
Re: [HELP]Loop and count players -
[HiC]TheKiller - 16.01.2010
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;
}
}
Re: [HELP]Loop and count players -
[HT]playstation - 16.01.2010
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...