26.09.2009, 08:26
Hello!
Since I have a bunch of loops and I make my loops as efficient as possible, like this:
My question is if looping for the highest ID can improve the performance a little? Sure can, but how do I make a variable store the highest ID?
And then loop like this:
Will that highestID thing work? specially the OnPlayer(Dis)Connect code I showed.
Since I have a bunch of loops and I make my loops as efficient as possible, like this:
pawn Код:
new maxPlayers,
i;
// OnGameModeInit
maxPlayers = GetMaxPlayers();
// Loop
for(i = 0; i < maxPlayers; i++)
{
if(!IsPlayerConnected(i)) continue;
// code
}
pawn Код:
new highestID;
// OnPlayerConnect
if(playerid > highestID)
{
highestID = playerid;
}
// OnPlayerDisconnect
if(playerid == highestID)
{
highestID = playerid - 1;
}
pawn Код:
for(i = 0; i < highestID; i++)
{
if(!IsPlayerConnected(i)) continue;
// code
}