for(new a;a<55,IsPlayerConnected(a);a++) problem need help please
#1

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
Reply
#2

remove IsPlayerConnected(a); then
Reply
#3

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.
Reply
#4

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
Reply
#5

Why would that be a problem?
Reply
#6

Could you post the function? or explain more
Reply
#7

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.
Reply
#8

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
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)