Client Looping
Hi Team,
Just looking for some solid input from devs around client index looping. I loop clients like (depending on needs): Code:
for (int client=1; client <= MaxClients; client++) Code:
for (int client=1; client < MAXPLAYERS; client++) |
Re: Client Looping
MaxClients is not equal to MAXPLAYERS. MAXPLAYERS is always 64 and MaxClients is equal to server slots count.
When using MAXPLAYERS it is necessary to add +1 because numeration starts from zero, and last available slot is 64, so that is MAXPLAYERS+1 (i.e. while i < 65, so last i will be 64). So basically you should use MAXPLAYERS+1 to declare global variables and MaxClients in local variables and for loop. For optimization you should use <= as it is same instructions as < (require same amount of time to execute). |
Re: Client Looping
Doesn't MAXPLAYERS == 65?
https://github.com/alliedmodders/sou...lients.inc#L72 https://github.com/alliedmodders/sou...rHelpers.h#L52 Edit: My question is mainly around MaxClients. I understand the zero indexing for creating arrays using MAXPLAYERS. |
Re: Client Looping
My mistake, MAXPLAYERS is 65. But because SourceTV is legal fake client, you still have to add +1 to MAXPLAYERS, otherwise last client will be outside of loop.
I don't understand question about MaxClients then. Yes, it is waste of CPU cycles if you check for (< MaxClients+1) since for cycle check this expression every iteration. It is better to check for (<= MaxClients). But MaxClients is equal to max players count (for my local server it is 24, if I try to IsClientInGame(25), I'll recieve error "Client index 25 is invalid"). |
Re: Client Looping
I don't think you ever need to loop all the way to MAXPLAYERS, even when setting variables back to a 'default' etc. The server can't go above MaxClients until it's shut off changes slot count and restarted which by then the plugin would be reloaded etc.
You should size for MAXPLAYERS+1 and you should plan with MaxClients |
Re: Client Looping
Quote:
|
All times are GMT -4. The time now is 06:00. |
Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.