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

Solved L4d2 Plug-in not getting correct amount of players .


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Jaylow
Junior Member
Join Date: Dec 2021
Old 01-09-2022 , 23:20   L4d2 Plug-in not getting correct amount of players .
Reply With Quote #1

Hi all.

So I have a plug in which gets data from the game and sends it to a database .

So I have put in test logs to see where the problem is and I can’t seem to figure it out.

I have it linked to readyup.smx so at the start of every round after the countdown timer it gets all 8 players on either survivor or infected, it stores that along with map, time, team player is on and score of the map.

It seems to be getting the correct players on survivor and infected but it is constantly stopping after getting 4,6,7 players and sometimes 8. It won’t ever get the full amount of players . I do have IsClientConneted but it seems to be breaking before getting the 8 players needed, it seems to be coming from the IsClientConnected break but without it I get errors of the server saying client 2 not connected ect .

Any help would be much appreciated

PHP Code:

char starttime
[512];
int rounds;

char steamid[64][32];
int team[64];
int playerscount;
Database g_db;

public 
void OnPluginStart()
{
    
    
ConnectToDatabase();
}

public 
void OnMapStart()
{
    
rounds 0;
    
playerscount 0;
    
FormatTime(starttime512"%Y-%d-%m - %H:%M:%S"GetTime());
}

public 
void OnMapEnd()
{
    if(
rounds != 2)
        return;
        
    
char map[128];
    
GetCurrentMap(map128);
    
    for(
int i 0playerscounti++)
    {
        
char query[512];
        
Format(query512"INSERT INTO plugin_match(steamid, starttime, scoreA, scoreB, map, team) VALUES('%s', '%s', '%i', '%i', '%s', '%i')"steamid[i], starttimeGameRules_GetProp("m_iChapterScore"40), GameRules_GetProp("m_iChapterScore"41), mapteam[i]);
        
g_db.Query(Query_ErrorCheckCallBackqueryDBPrio_Normal);
            
        
LogAction(-1,-1,"Did query number %i / %i - %s - %i"iplayerscountsteamid[i], team[i]);
        
    }
        

}


public 
void OnRoundIsLive()
{
    
    
    if(
rounds == 0)
    {
        
        for(
int i 1MaxClients 1i++)
        {
            
Format(steamid[i], 32"");
            
team[i] = 0;
        }
        
        
playerscount 0;
        for(
int i 1MaxClients 1i++)
        {
            if(!
IsClientConnected(i))
                break;
                
            if(
GetClientTeam(i) != &&  GetClientTeam(i) != || IsFakeClient(i))
                continue;
                
            
GetClientAuthId(iAuthId_Steam2,steamid[playerscount], 32);
            
team[playerscount] = GetClientTeam(i);
            
            
playerscount += 1;
            
            
        }

    }
    

    
rounds rounds 1;
    



Last edited by Jaylow; 01-11-2022 at 17:39.
Jaylow is offline
Marttt
Veteran Member
Join Date: Jan 2019
Location: Brazil
Old 01-10-2022 , 07:55   Re: L4d2 Plug-in not getting correct amount of players .
Reply With Quote #2

probably your issue is here

Code:
        for(int i = 1; i < MaxClients - 1; i++)
        {
            if(!IsClientConnected(i))
                break;  
             
            if(GetClientTeam(i) != 2 &&  GetClientTeam(i) != 3 || IsFakeClient(i))
                continue;
                
            GetClientAuthId(i, AuthId_Steam2,steamid[playerscount], 32);
            team[playerscount] = GetClientTeam(i);
            
            playerscount += 1;
__________________

Last edited by Marttt; 01-10-2022 at 07:55.
Marttt is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 01-10-2022 , 07:56   Re: L4d2 Plug-in not getting correct amount of players .
Reply With Quote #3

break; = stop code in that scope {} and stop loop
continue; = stop code in that scope {} and continue loop

Client index start from 1, and end to MaxClients.
MaxClients is amount of player entity which server can create. You could think those like as "server slots".
You can set this max players amount at server launch parameter -maxplayers, of course this not work in all games.
For example CS:GO use all 64 index, but dynamically it set max amount human clients in different game modes.

If you like, you can check how many human players can be in game with:
GetMaxHumanPlayers

Let's continue, now you know, you have range 1 to 8 client indexes (L4D2 versus).
But you need check is anyone connected into that.

IsClientConnected
...is one way to look, but you need understand when this is "true", in which state player is in server.
- When client connecting, he have loading screen while connecting.

When you try use other SM functions you get errors because some require client to be in game rather than connected.

Here output example:
Code:
// client connecting into server while spamming F11 button "sm_test"


// coop
MAXPLAYERS = 65
MaxClients = 18
GetMaxHumanPlayers = 4
IsClientConnected(1) = 1
IsClientInGame(1) = 0
IsFakeClient(1) = 0
GetClientAuthId(1) = STEAM_1:1:14163588
L 01/10/2022 - 14:39:44: [SM] Exception reported: Client 1 is not in game
L 01/10/2022 - 14:39:44: [SM] Blaming: test.smx
L 01/10/2022 - 14:39:45: [SM] Call stack trace:
L 01/10/2022 - 14:39:45: [SM]   [0] GetClientTeam
L 01/10/2022 - 14:39:45: [SM]   [1] Line 20, test.sp::test

// in game
MAXPLAYERS = 65
MaxClients = 18
GetMaxHumanPlayers = 4
IsClientConnected(1) = 1
IsClientInGame(1) = 1
IsFakeClient(1) = 0
GetClientAuthId(1) = STEAM_1:1:14163588
GetClientTeam(1) = 0



// versus
MAXPLAYERS = 65
MaxClients = 18
GetMaxHumanPlayers = 8
IsClientConnected(1) = 1
IsClientInGame(1) = 0
IsFakeClient(1) = 0
GetClientAuthId(1) = STEAM_1:1:14163588
L 01/10/2022 - 14:38:23: [SM] Exception reported: Client 1 is not in game
L 01/10/2022 - 14:38:23: [SM] Blaming: test.smx
L 01/10/2022 - 14:38:23: [SM] Call stack trace:
L 01/10/2022 - 14:38:23: [SM]   [0] GetClientTeam
L 01/10/2022 - 14:38:23: [SM]   [1] Line 20, test.sp::test

// in game
MAXPLAYERS = 65
MaxClients = 18
GetMaxHumanPlayers = 8
IsClientConnected(1) = 1
IsClientInGame(1) = 1
IsFakeClient(1) = 0
GetClientAuthId(1) = STEAM_1:1:14163588
GetClientTeam(1) = 0
So use this instead, not need check is client connected separately.
IsClientInGame



PHP Code:
    char steamid[65];
    
int team;

    for(
int i 1<= MaxClientsi++)
    {
        
// Not in game or bot
        
if(!IsClientInGame(i) || IsFakeClient(i))
            continue;


        
GetClientAuthId(iAuthId_Steam2steamidsizeof(steamid));
        
team GetClientTeam(i);
        
        
PrintToServer("%s %i"steamidteam);
    } 
Bacardi is offline
Jaylow
Junior Member
Join Date: Dec 2021
Old 01-10-2022 , 08:46   Re: L4d2 Plug-in not getting correct amount of players .
Reply With Quote #4

So if I use isClientInGame it will go through the loop only 8 times until it gets all the players in either survivor or infected ?
Jaylow is offline
Jaylow
Junior Member
Join Date: Dec 2021
Old 01-10-2022 , 08:55   Re: L4d2 Plug-in not getting correct amount of players .
Reply With Quote #5

Server is set up 30 slots . So MaxClients returns 30.

But why does it break after only getting 3-7 players when there is 8? It Should be going through all players until there is no more connected right?

If I disable the getclientteam check it still only gets 3-7 players even if it has to go through spectators first. It just doesn’t make sense why it’s breaking before getting all players connected
Jaylow is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 01-10-2022 , 09:46   Re: L4d2 Plug-in not getting correct amount of players .
Reply With Quote #6

We don't know -> when you execute that code.
Do you execute when map start or after few minutes (so clients made in game).
__________________
Do not Private Message @me
Bacardi is offline
Marttt
Veteran Member
Join Date: Jan 2019
Location: Brazil
Old 01-10-2022 , 10:20   Re: L4d2 Plug-in not getting correct amount of players .
Reply With Quote #7

Probably you should count "playerscount" on RoundEnd, instead.

There is no guarantee, most unlikely, that the same players from RoundStart/Live are in the round end.
__________________
Marttt is offline
Jaylow
Junior Member
Join Date: Dec 2021
Old 01-10-2022 , 23:21   Re: L4d2 Plug-in not getting correct amount of players .
Reply With Quote #8

Quote:
Originally Posted by Bacardi View Post
We don't know -> when you execute that code.
Do you execute when map start or after few minutes (so clients made in game).
it is executed once all 8 players have ready up and after a 3 second countown.

so all players are in game already
Jaylow is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 01-11-2022 , 02:59   Re: L4d2 Plug-in not getting correct amount of players .
Reply With Quote #9

You maybe need start debugging.

In beginning of your code:
PHP Code:
public void OnRoundIsLive()
{

    
// debug your code

    
LogAction(-1, -1"\n\n");
    
LogAction(-1, -1"OnRoundIsLive()");

    
char buffer[64];
    
int teamindex;
    
    for(
int i 1<= MaxClientsi++)
    {
        if(!
IsClientConnected(i))
            continue;

        
teamindex = -1;
        
GetClientAuthId(iAuthId_Steam2buffersizeof(buffer));

        if(
IsClientInGame(i))
        {
            
teamindex GetClientTeam(i);
        }

        
// if team is -1 in logs = client is not in game
        
LogAction(-1, -1"%i - Player %N - steamid %s - team %i",
                
i,
                
i,
                
buffer,
                
teamindex);
    }




    
// your rest code at bottom
   
...







__________________
Do not Private Message @me
Bacardi is offline
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 00:01.


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