Raised This Month: $32 Target: $400
 8% 

Question about players count


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Robotex
Junior Member
Join Date: Mar 2016
Old 03-20-2017 , 16:39   Question about players count
Reply With Quote #1

I am writing a plugin that needs to know how many players are connected.

However I am not sure about these matters:
  1. On map changes, do the functions GetNumPlayers/GetClientCount still return the number of players that haven't quitted the game and will be playing in next map?
  2. In OnClientDisconnected, is the disconnected player still counted in GetNumPlayer/GetClientCount?

Thanks in advance.
Robotex is offline
SytekBox
AlliedModders Donor
Join Date: Feb 2017
Location: 404 not found
Old 03-20-2017 , 20:23   Re: Question about players count
Reply With Quote #2

Quote:
Originally Posted by Robotex View Post
I am writing a plugin that needs to know how many players are connected.

However I am not sure about these matters:
  1. On map changes, do the functions GetNumPlayers/GetClientCount still return the number of players that haven't quitted the game and will be playing in next map?
  2. In OnClientDisconnected, is the disconnected player still counted in GetNumPlayer/GetClientCount?

Thanks in advance.
I could be wrong as i've been out of the game for long now (Used to do work on 1.7 and don't know much about 1. but i recall seeing in one of the Docs for 1.7 that the GetNumPlayers would retrieve the Total of Connected players, therefor if that's correct then relatively speaking OnClientDisconnected wouldn't be able to find said player (As it's not longer being counted due to being offline otherwise it would be a bit wrong to keep counting a Ghost -that's what i think-).

Of course, i've been away from SM in general for a long time and i could be wrong. Better wait for a more accurate and updated answer from one of this genius chaps at AM.

Nonetheless, you could've debugged the results in order to see if it's indeed like you think it is. That's the easiest way to find your answers

Have a good one
SytekBox is offline
RumbleFrog
Great Tester of Whatever
Join Date: Dec 2016
Location: Fish Tank
Old 03-21-2017 , 23:04   Re: Question about players count
Reply With Quote #3

1. GetClientCount(bool inGameOnly) will include clients as they are passed through OnClientPutInServer() forward

2. I don't believe so.
RumbleFrog is offline
ambn
Veteran Member
Join Date: Feb 2015
Location: Fun servers
Old 03-22-2017 , 08:52   Re: Question about players count
Reply With Quote #4

You can also try this stock:
PHP Code:
int GetPlayerCount()
{
    
int PlayerNumb 0;
    for (
int x 1<= MaxClientsx++)
    {
        if(
IsClientInGame(x) && !IsFakeClient(x))
        {
            
PlayerNumb++;
        }
    }
    return 
PlayerNumb;

__________________

Last edited by ambn; 03-22-2017 at 08:52.
ambn is offline
Robotex
Junior Member
Join Date: Mar 2016
Old 03-25-2017 , 00:56   Re: Question about players count
Reply With Quote #5

Well after some tests this is what I noticed:
1. GetClientCount returns the number of currently playing+connecting players, HOWEVER when a map change occurs it will return 0 because clients will be briefly disconnected (OnClientDisconnected is called).
2. In OnClientDisconnected the user that has left is not counted.

So my question now is, how can I get reliably the number of players when the map change triggers? I believe the server must know it because otherwise it would go on hibernation. Maybe querying the master server somehow?

Last edited by Robotex; 03-25-2017 at 01:00.
Robotex is offline
Chaosxk
Veteran Member
Join Date: Aug 2010
Location: Westeros
Old 03-25-2017 , 01:20   Re: Question about players count
Reply With Quote #6

Yes GetClientCount will return 0 if called OnMapStart because clients will briefly disconnect and reconnect. Perhaps you can call OnMapEnd?
Or OnConfigsExecuted (should be called after OnMapStart). Or call an event (depending on your game) such as round start or something? Or create a 2/3/4 second timer OnMapStart?
__________________

Last edited by Chaosxk; 03-25-2017 at 01:23.
Chaosxk is offline
Robotex
Junior Member
Join Date: Mar 2016
Old 03-25-2017 , 06:24   Re: Question about players count
Reply With Quote #7

Quote:
Originally Posted by Chaosxk View Post
Yes GetClientCount will return 0 if called OnMapStart because clients will briefly disconnect and reconnect. Perhaps you can call OnMapEnd?
Or OnConfigsExecuted (should be called after OnMapStart). Or call an event (depending on your game) such as round start or something? Or create a 2/3/4 second timer OnMapStart?
Is OnMapEnd called when all players disconnect in middle of game? I cannot use any OnXXXXStart simply because... there won't be any called! My plugin has the objective of running a "quit" command once nobody is playing as part of a self updating infrastructure.
So speaking back about the idea of querying the Master server, I have noticed that an another extension called Left4Downtown2 hooks the value in CBaseServer::GetMasterServerPlayerCounts but I cannot find any reference on the net of that method in other games so it seems that won't be portable.
My other thought now is hooking an "OnHibernate" event that is fired only when it's really empty, however it seems there's none exported from SourceMod by default, which uses it in PlayerManager::OnServerHibernationUpdate..

// EDIT:
I guess I can exclude OnServerHibernationUpdate because for some reason hooking it breaks up the engine in an endless reboot..

Last edited by Robotex; 03-25-2017 at 13:32. Reason: derp
Robotex is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 12:36.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode