Just looping through all available player-slots and checking if they're online is fast enough.
PHP код:
new starttime, endtime, blabla;
starttime = GetTickCount();
for (new i; i < 1000000; i++)
if (APlayerData[0][LoggedIn] == true)
blabla = 0;
endtime = GetTickCount();
printf("Total time to loop 1.000.000 times: %i milliseconds", endtime - starttime);
I used this code to test the speed for looping 1 million times and checking if a player is connected and it's executed in only 43 milliseconds on my home-pc.
This is 1000 times more than the highest populated server, which is only a 1000-player server.
Looping through 1000 players and checking their online status would only take 43 microseconds. This would be for the highest populated server.
In your case, a 500 player server, this would only take 21 microseconds.
This is negligable.
Increasing the loop to 25 million iterations takes 1 second, I doubt anyone would use such big loops in their server.
Real servers do it even faster than my home-pc.
I'm not bothering to use foreach and other stuff.
It doesn't give a noticeable speed-increase.
My own server only has 50 players, so each time I loop through all players, it would only take 2 microseconds.
To your question: redefining MAX_PLAYERS would require a recompile of your script and a restart of your server for changes to take effect.
And don't forget to adjust the value in your server.cfg file as well to match your script.
It's not a good idea to monitor your server constantly and restart the server with an adjusted MAX_PLAYERS value when your server is getting full or empty.
Just set it to the maximum you're allowed and leave it at that.