for(new a;a<55,IsPlayerConnected(a);a++) problem need help please - 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: for(new a;a<55,IsPlayerConnected(a);a++) problem need help please (
/showthread.php?tid=147828)
for(new a;a<55,IsPlayerConnected(a);a++) problem need help please -
DaneAMattie - 14.05.2010
So i got
for(new a;a<55,IsPlayerConnected(a);a++)
to get all players right
if like we have 6 players in this follow:
id 0
id 1
id 3
id 4
id 5
id 6
ID 2 is just left so ID2 is gone, now my problem is that if there is an ID missing the function wont continue and just stop at ID 1 :/ need help please
Re: for(new a;a<55,IsPlayerConnected(a);a++) problem need help please -
Killa_ - 14.05.2010
remove
IsPlayerConnected(a); then
Re: for(new a;a<55,IsPlayerConnected(a);a++) problem need help please -
juice.j - 14.05.2010
Throw IsPlayerConnected(a) into your for-loop and perform a "continue;" in case the player is not connected. That way, you'll exclude those id's from the following code being processed.
Re: for(new a;a<55,IsPlayerConnected(a);a++) problem need help please -
DaneAMattie - 14.05.2010
Quote:
Originally Posted by Killa_
remove IsPlayerConnected(a); then
|
and
Quote:
Originally Posted by juice.j
Throw IsPlayerConnected(a) into your for-loop and perform a "continue;" in case the player is not connected. That way, you'll exclude those id's from the following code being processed.
|
I know that i can remove IsPlayerConnected
but in my case that also would cause a problem
Re: for(new a;a<55,IsPlayerConnected(a);a++) problem need help please -
juice.j - 14.05.2010
Why would that be a problem?
Re: for(new a;a<55,IsPlayerConnected(a);a++) problem need help please -
Killa_ - 14.05.2010
Could you post the function? or explain more
Re: for(new a;a<55,IsPlayerConnected(a);a++) problem need help please -
Kyosaur - 14.05.2010
Change
Код:
for(new a;a<55,IsPlayerConnected(a);a++)
To
Код:
for(new a=0, i=GetMaxPlayers(); a<i; a++)
{
if(!IsPlayerConnected(a)) continue;
//rest of your code
}
The GetMaxPlayers part will Get the maximum possible players for your server (what ever is specified in youe server.cfg) and is the most efficient way of dueing player loops IMO (some say defining a new MAX_PLAYERS is better, but thats not dynamic / needs to be manually changed if you ever set your player count lower / higher).
If you dont want to skip unconnected id's comment out the "if(!IsPlayerConnected(a)) continue;" part.
Re: for(new a;a<55,IsPlayerConnected(a);a++) problem need help please -
DaneAMattie - 14.05.2010
Quote:
Originally Posted by Kyosaur!!
Change
Код:
for(new a;a<55,IsPlayerConnected(a);a++)
To
Код:
for(new a=0, i=GetMaxPlayers(); a<i; a++)
{
if(!IsPlayerConnected(a)) continue;
//rest of your code
}
The GetMaxPlayers part will Get the maximum possible players for your server (what ever is specified in youe server.cfg) and is the most efficient way of dueing player loops IMO (some say defining a new MAX_PLAYERS is better, but thats not dynamic / needs to be manually changed if you ever set your player count lower / higher).
If you dont want to skip unconnected id's comment out the "if(!IsPlayerConnected(a)) continue;" part.
|
Thanks 100x it worked