PDA

View Full Version : Question Number Of Players



SyntaxX
02-13-2011, 07:38 AM
Hey all,

is it somehow possible to receive the number of players, that are currently active on a server that im playing on ?.

Tryed it with EntList->NumberOfEntities(false), but this one also returns weapons and shit.

Regards.

freax
02-13-2011, 07:43 AM
gpGlobals->maxClients

SyntaxX
02-13-2011, 08:25 AM
gpGlobals->maxClients

yes, but this returns the max client count, I need the count of the players that are connected to the server :)

Casual_Hacker
02-13-2011, 08:56 AM
how about you count the number of player entities, or you just lookup using pEngine->GetPlayerInfo, or you use the player resource thing, or reading the team entities or something, idk.

Gumble
02-13-2011, 09:14 AM
simply reverse the scoreboard, it also got a player count part, find the pointer or sth.

Casual_Hacker
02-13-2011, 09:17 AM
simply reverse the scoreboard, it also got a player count part, find the pointer or sth.

It uses the player resource thing.

b2k5
02-13-2011, 10:04 AM
quick question: what do u need that for?

i use IVEngineClient::GetMaxClients(); and then just continue; in my loop if not existing/not alive.

freax
02-13-2011, 11:29 AM
It uses the player resource thing.

This is probably the best way.

boecke
02-16-2011, 04:59 PM
int g_maxPlayers = 0;
for ( int j = 0; j <= pEngine->GetMaxClients(); ++j )
{
if ( j == pEngine->GetLocalPlayer() )
continue;

IClientEntity *pEnt = pClientEntityList->GetClientEntity( j );
if ( !pEnt )
continue;

if ( pEnt->IsDormant() )
continue;

player_info_t info;
if ( pEngine->GetPlayerInfo( j, &info ) )
{
g_maxPlayers++;
}
}

lev1ath4n
02-19-2011, 08:59 AM
I do it like this:

for( int index = 0; index < g_pEntList->GetHighestEntityIndex();index++ )
{
if( strstr(GameRes()->GetPlayerName( index ),"unconnected"))
continue;
if( index == g_pEngine->GetLocalPlayer() )
continue;
else if( GameRes()->IsFakePlayer( index ))
continue;
else
/*Count whatever up*/
}

freax
02-19-2011, 09:32 AM
IMHO yours can be optimized a lot.

Some facts:

1.) IGameResources* pointer changes to unknown times. So use the signature to the GetGameResources()-function and call it every time (like leviath4n does it already). Otherwise you WILL get crashes.

2.) pEntList->GetHighestEntityIndex() ist NOT needed. It can has a number up to 1024 [2048 with logical and local entities] and you DO NOT NEED THEM.
I guess most people don't know it, but the clients are stored from index 1 to pGlobals->maxClients (in CSS, this is 64); thats why you can simply use it to save time.

3.) The unconnected bug does not exists anymore since the OB port.

Using that sort of information, you get:
unsigned short Utils::GetPlayerCount(bool bAlive)
{
IGameResources *pGR = Utils::GetGameResources();
unsigned short nCount = 0;

for (unsigned short i = 1; i <= pGlobals->maxClients /*64*/; ++i)
{
if (pGR->IsConnected(i) && !pGR->IsFakePlayer(i) && (!bAlive || pGR->IsAlive(i)))
{
++nCount;
}
}

return nCount;
}

K THX BYE

wav
02-19-2011, 10:29 AM
post increment not pre increment you infidel otherwise you will not laugh when ents do not show up

also i hate all of your methods as they are gay as hell ask the german nazi guys how i do it and trust me your pants will fill up with fecoscat upon realization

freax
02-20-2011, 05:48 AM
...pre increments are faster than post increments. I know that this is micro optimizing with nearly no effect, but I love to program strictly.

DeepblueSea
02-20-2011, 07:20 AM
You gotta be kidding me...

freax
02-20-2011, 07:46 AM
<3

Casual_Hacker
02-20-2011, 10:53 AM
Compiler can optimize the extra copy away in most cases anyway.

wav
02-20-2011, 01:36 PM
You gotta be kidding me...

I believe that this whole thread is a joke.


...pre increments are faster than post increments. I know that this is micro optimizing with nearly no effect, but I love to program strictly.

your code will skip a whole ent

freax
02-20-2011, 02:09 PM
Can you say why? Index 0 is ALWAYS the "worldspawn" entity if you mean that.

wav
02-20-2011, 02:15 PM
Can you say why? Index 0 is ALWAYS the "worldspawn" entity if you mean that.

look your code over and think about it

freax
02-20-2011, 02:19 PM
I can't see a mistake, sorry.

wav
02-20-2011, 02:21 PM
I can't see a mistake, sorry.

Clean off the cum gluing your eyelids together and you will see it clearly.

Casual_Hacker
02-21-2011, 06:36 AM
wav, his code is flawless. See that <= ? If that were a < I'd agree there would be a bug.

inb4 http://lol.i.trollyou.com/

wav
02-21-2011, 12:55 PM
wav, his code is flawless. See that <= ? If that were a < I'd agree there would be a bug.

inb4 http://lol.i.trollyou.com/

Thanks for ruining my trolling you faggot.

stev3
02-21-2011, 01:24 PM
lettuce be reality.



























http://i.imgur.com/oqcT5.gif

wav
02-21-2011, 01:56 PM
lettuce be reality.


























http://i.imgur.com/oqcT5.gif

lettuce is not as tasty as cabbage

lev1ath4n
02-24-2011, 03:58 PM
3.) The unconnected bug does not exists anymore since the OB port.


I used it to remove them then. I dunno, done this some time ago to choose at which player to shoot and not, and my method worked flawlessly fast and good. http://video.xfire.com/247bf4-4.jpg (http://www.xfire.com/video/247bf4/)
ignore the Parkinson's like mouse movements.

boecke
02-26-2011, 06:42 AM
What is this shit?