Proper client iteration
Should iterating over all clients in the server go like this
Code:
for (new i = 1; i <= MAXPLAYERS; i++)Code:
for (new i = 0; i < MAXPLAYERS; i++) |
Re: Proper client iteration
Client indexes start at 1 so it'd be <= MAXPLAYERS or MaxClients. Listen servers start at 0, but it's not a case you should take into consideration since clients shouldn't be hosting on listen servers.
*Edit: Rather, you should use MAXPLAYERS + 1 for declarations inside the global scope, MAXPLAYERS within OnPluginStart, and MaxClients for anything afterwards. |
Re: Proper client iteration
Depending on your situation you may consider GetMaxHumanPlayers() instead of MaxClients.
|
Re: Proper client iteration
Okay, the only reason I ask is because I'm using the first iteration method that I posted, but for some reason I'm getting errors of invalid client index #, where the # is equal to my max players + 1.
|
Re: Proper client iteration
Can ya show us the code that's giving you issues? But you shouldn't be using MAXPLAYERS + 1 in a loop, not with <=. Use < MAXPLAYERS + 1 or <= MAXPLAYERS, assuming that's related. But without seeing code, can't say much more.
|
Re: Proper client iteration
Quote:
|
Re: Proper client iteration
Quote:
|
Re: Proper client iteration
Quote:
|
Re: Proper client iteration
Here is the bug report that made me think this:
https://bugs.alliedmods.net/show_bug.cgi?id=5757 So if GetMaxHumanPlayers only returns the number of humans, then the only option for CS:GO is to use MaxClients which always returns 64. Is there no function to get the number of humans + bots so we don't need to iterate over 64 indexes every time when most of the time only 1/2 - 1/3 of those indexes will actually have players. Even after adding bots to the server GetMaxHumanPlayers is still showing 16 (which is what I have maxplayers set to). |
Re: Proper client iteration
Quote:
In this specific case, you can use it for the count of players that can be in the server, including bots, since CS:GO doesn't add bots beyond that count. It just uses them to replace humans when desired, up to that count. |
| All times are GMT -4. The time now is 14:27. |
Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.