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

[TF2] player_connect vs player_connect_client? How to track player count on connects?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Haytil
Junior Member
Join Date: Oct 2018
Old 11-10-2018 , 01:24   [TF2] player_connect vs player_connect_client? How to track player count on connects?
Reply With Quote #1

Two questions, probably quite related:

A) What is the difference between the "player_connect" and "player_connect_client" events?

The documentation for "player_connect" says: "Note: A new client connected"

The documentation for "player_connect_client" says: "Note: A new client connected, only present in OB". It provides no explanation for what "OB" is or what "OB" stands for.

Can someone explain the difference? And what is "OB?"


B) What I'm trying to do is keep a global track of the numbers of human players who are online, by tracking their number and incrementing/decrementing when they connect and disconnect.

-Bots should not be counted (though we have none)
-SourceTV should not be counted (we DO have this, perhaps this is a bot)
-Players should NOT be counted when they attempt, but fail, to connect due to a reserved slot blocking them.

I initially used "HookEvent" on "player_connect," but this was getting clients with a value of 0. (My research suggested this was connection attempts either from not-fully-connected players or from players who were later rejected due to slot reseveration limits - neither of which are events I want to fire on).

I tried "HookEvent" on "player_activate" events, hoping to avoid tracking a newly-joined player until AFTER he was fully connected to the server (and thus avoid clients of value 0), but this fires for every player when the map changes as well.

So what event should I hook on to increment my global "players_connected" variable (avoiding bots and failed slot reservation attempts)? How do I avoid exceptions of "Exception reported: Client index 0 is invalid"?

Thanks.
Haytil is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 11-10-2018 , 08:35   Re: [TF2] player_connect vs player_connect_client? How to track player count on conne
Reply With Quote #2

A) You can find in most of HL2 game mods event "player_connect".
Maybe "player_connect_client" is TF2 mod specific event... perhaps to tell it is human who connect.

I recommend to use "player_connect" and "player_disconnect" events.

OB = Orange Box serie of HL2 games (it Half-Life 2, Half-Life 2: Episode One, Half-Life 2: Episode Two, Portal ja Team Fortress 2.). https://en.wikipedia.org/wiki/The_Orange_Box
-Before SteamCMD upgrade, when TF2 game had a lot of updates, those also affect cs:s, dod:s, hl2:dm games also.
It was like pain in ass. Updates, updates, updates...

out of topic. https://forums.alliedmods.net/showthread.php?t=311384

B) On "player_connect" event, player is connecting to server, not in game yet.
And again "player_disconnect" event, player is still in game and team...
net_showevents 2



If you want track player count on server... I would recommend to use repeating timer, maybe every 2 sec ?
PHP Code:
public void OnPluginStart()
{
    
CreateTimer(2.0MyTimer_TIMER_REPEAT);
}

public 
Action MyTimer(Handle timer)
{
    
int counter;

    
// Loop client indexs
    
for(int client 1client <= MaxClientsclient++)
    {
        
// skip client indexs which are not in use or player is not in game (connecting)
        
if(!IsClientInGame(client)) continue;

        
// skip bots
        
if(IsFakeClient(client)) continue;

        
counter++;

        
PrintToServer("Human player - '%N'"client);
    }

    
PrintToServer("Human player count %i"counter);

    return 
Plugin_Continue;

__________________

Last edited by Bacardi; 11-10-2018 at 08:39.
Bacardi is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 11-10-2018 , 09:00   Re: [TF2] player_connect vs player_connect_client? How to track player count on conne
Reply With Quote #3

If you see anything marked as being OB, you can assume Team Fortress 2 uses it... and there's a good chance that Counter-Strike: Source, Day of Defeat: Source, and Half-Life 2: Deathmatch do as well.

Valve started using player_connect_client so all clients don't get sent other client IP addresses.

It wouldn't surprise me if CS:GO also used this event, but I've never checked.
__________________
Am I back? Well, we'll see.
Powerlord is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 11-10-2018 , 10:13   Re: [TF2] player_connect vs player_connect_client? How to track player count on conne
Reply With Quote #4

Quote:
Originally Posted by Powerlord View Post

Valve started using player_connect_client so all clients don't get sent other client IP addresses.

It wouldn't surprise me if CS:GO also used this event, but I've never checked.
Perhaps in LAN mode, where steamid is not in use anymore... *edit, not really. Can't see IP
__________________

Last edited by Bacardi; 11-10-2018 at 10:20.
Bacardi 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 14:32.


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