AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   Proper client iteration (https://forums.alliedmods.net/showthread.php?t=226432)

Gecko 09-17-2013 21:45

Proper client iteration
 
Should iterating over all clients in the server go like this

Code:

for (new i = 1; i <= MAXPLAYERS; i++)
{
}

Or like this?

Code:

for (new i = 0; i < MAXPLAYERS; i++)
{
}


thetwistedpanda 09-17-2013 21:46

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.

hlstriker 09-17-2013 21:48

Re: Proper client iteration
 
Depending on your situation you may consider GetMaxHumanPlayers() instead of MaxClients.

Gecko 09-17-2013 22:09

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.

thetwistedpanda 09-17-2013 22:10

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.

psychonic 09-17-2013 22:27

Re: Proper client iteration
 
Quote:

Originally Posted by hlstriker (Post 2036665)
Depending on your situation you may consider GetMaxHumanPlayers() instead of MaxClients.

Not necessarily. Just because that there is a separate maximum amount of humans that can join doesn't mean that there can't be bot indexes between them, up to a total of MaxClients.

hlstriker 09-17-2013 22:30

Re: Proper client iteration
 
Quote:

Originally Posted by psychonic (Post 2036674)
Not necessarily. Just because that there is a separate maximum amount of humans that can join doesn't mean that there can't be bot indexes between them, up to a total of MaxClients.

So that function doesn't include bots (as the name suggests humans but I was under the impression bots were a part of this but SourceTV was not)?

Powerlord 09-17-2013 22:32

Re: Proper client iteration
 
Quote:

Originally Posted by hlstriker (Post 2036677)
So that function doesn't include bots?

No, which is why it's called GetMaxHumanPlayers.

hlstriker 09-17-2013 22:40

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).

psychonic 09-18-2013 08:11

Re: Proper client iteration
 
Quote:

Originally Posted by hlstriker (Post 2036685)
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).

It's on a game-by-game basis since that function can be implemented differently in different games.

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.