AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   [TF2] player_connect vs player_connect_client? How to track player count on connects? (https://forums.alliedmods.net/showthread.php?t=311957)

Haytil 11-10-2018 00:24

[TF2] player_connect vs player_connect_client? How to track player count on connects?
 
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.

Bacardi 11-10-2018 07:35

Re: [TF2] player_connect vs player_connect_client? How to track player count on conne
 
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;



Powerlord 11-10-2018 08:00

Re: [TF2] player_connect vs player_connect_client? How to track player count on conne
 
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.

Bacardi 11-10-2018 09:13

Re: [TF2] player_connect vs player_connect_client? How to track player count on conne
 
Quote:

Originally Posted by Powerlord (Post 2623395)

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


All times are GMT -4. The time now is 20:23.

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