Thread: Useful Snippets
View Single Post
Old 28/01/2007, 10:49 AM   #3
Sacky
Big Clucker
 
Join Date: Aug 2006
Posts: 78
Reputation: 0
Default Re: Useful Snippets

Well this is a small thing but i find it a bit more efficient,

instead of using for(new i=0;i<MAX_PLAYERS

I use this:

Code:
new maxplayers; //Global Variable

public OnPlayerConnect(playerid){
	if(playerid > maxplayers-1) maxplayers = playerid+1; //Getting the maximum playerid
}

public OnPlayerDisconnect(playerid){
	if(playerid == maxplayers+1) for(new i=0;i<maxplayers;i++) if(IsPlayerConnected(i)) maxplayers = i+1; //Getting the minimum playerid
}

for(new i=0;i<maxplayers;i++) //the new more efficient loop
Sacky is offline   Reply With Quote