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

Get num players and player info


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Despirator
Senior Member
Join Date: Jun 2011
Location: Kazakhstan ->Shymkent
Old 04-03-2017 , 10:18   Get num players and player info
Reply With Quote #1

Hi community!
How can I get num players, max players and player info in the metamod plugin?
Also I would like to know how to loop through them?
Despirator is offline
Emil
Junior Member
Join Date: May 2010
Location: Skövde, Sweden
Old 05-25-2017 , 15:08   Re: Get num players and player info
Reply With Quote #2

You can get player info via IPlayerInfoManager

Code:
bool CSGOPlugin::Load(CreateInterfaceFn interfaceFactory, CreateInterfaceFn gameServerFactory)
{
    ConnectTier1Libraries( &interfaceFactory, 1 );

    // Set engine globals
    g_playerinfomanager = (IPlayerInfoManager *)gameServerFactory(INTERFACEVERSION_PLAYERINFOMANAGER, NULL);


    int g_maxPlayers = g_playerinfomanager->GetGlobalVars()->maxClients();
}
Save info on connect / disconnect
Code:
PLUGIN_RESULT CSGOPlugin::ClientConnect(bool *bAllowConnect, edict_t *pEntity, const char *pszName, const char *pszAddress, char *reject, int maxrejectlen)
{
    IPlayerInfo* info = g_playerinfomanager->GetPlayerInfo(pEntity);
}

void Players::ClientDisconnect(edict_t *pEntity)
{
}

Well i guess you can iterate through all entitys to get all players without saving on connect/disconnect.

Code:
void CSGOPlugin::CheckPlayers(void)
{
    for(int i = 0; i<g_playerinfomanager->GetGlobalVars()->maxEntities; ++i)
    {
        edict_t* pEntity = g_playerinfomanager->GetGlobalVars()->pEdicts + i;

        if(pEntity == NULL){
            continue;
        }
        if(pEntity->IsFree()){
            continue;
        }

        IPlayerInfo* info = g_playerinfomanager->GetPlayerInfo(pEntity);

        if(info != NULL)
        {
            //do something with info
        }
    }
}

Last edited by Emil; 05-25-2017 at 16:21.
Emil is offline
Send a message via Skype™ to Emil
Reply



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 01:41.


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