Raised This Month: $51 Target: $400
 12% 

[L4D2] How to hook player connect without players from last chapter


Post New Thread Reply   
 
Thread Tools Display Modes
dustinandband
Senior Member
Join Date: May 2015
Old 04-04-2018 , 09:24   Re: [L4D2] How to hook player connect without players from last chapter
Reply With Quote #11

Quote:
Originally Posted by pride95 View Post
userid.

if a client connects from lobby then userid++;
if a client connects from map change the old userid (from the previous map) == userid (from this map).

try to create a fakeclient onmapstart, get his userid and then check if userid from player connected > userid from fakeclient.
So, just to clarify, does a user ID ever get reused on another client after so many connections / disconnections? Like say 100 people have been connecting & disconnecting all day - will client #2’s (second person to connect that day) user ID not be reused in someone else at a later time? (Of course not counting when the server reboots.)
dustinandband is offline
Lux
Veteran Member
Join Date: Jan 2015
Location: Cat
Old 04-04-2018 , 10:54   Re: [L4D2] How to hook player connect without players from last chapter
Reply With Quote #12

Userid is fine that don't change unless they disconnect from the server that's all i use
__________________
Connect
My Plugins: KlickME
[My GitHub]

Commission me for L4D
Lux is offline
pride95
Senior Member
Join Date: Aug 2015
Old 04-04-2018 , 12:03   Re: [L4D2] How to hook player connect without players from last chapter
Reply With Quote #13

Quote:
Originally Posted by dustinandband View Post
So, just to clarify, does a user ID ever get reused on another client after so many connections / disconnections? Like say 100 people have been connecting & disconnecting all day - will client #2’s (second person to connect that day) user ID not be reused in someone else at a later time? (Of course not counting when the server reboots.)
let's clarify.

if i'm the first player connected on the server (in the morning with 0 players online) let's say i have userid 100
if i reconnect on the server i will have userid: 101
if the map changes i will have the same userid: 100

the userid will increase itself after player connection which is not from map change.
so if 100 people connects & disconnects all day then the userid will increase with how many connections were in that day.
userid is unique and no one will ever have that userid before server hibernation or server restart (i think just server restart, idk) ...

userid is a number from engine, not from sourcemod so you are not losing data if the plugin reloads.

Last edited by pride95; 04-04-2018 at 12:04.
pride95 is offline
eyal282
Veteran Member
Join Date: Aug 2011
Old 04-04-2018 , 14:49   Re: [L4D2] How to hook player connect without players from last chapter
Reply With Quote #14

Quote:
Originally Posted by pride95 View Post
let's clarify.

if i'm the first player connected on the server (in the morning with 0 players online) let's say i have userid 100
if i reconnect on the server i will have userid: 101
if the map changes i will have the same userid: 100

the userid will increase itself after player connection which is not from map change.
so if 100 people connects & disconnects all day then the userid will increase with how many connections were in that day.
userid is unique and no one will ever have that userid before server hibernation or server restart (i think just server restart, idk) ...

userid is a number from engine, not from sourcemod so you are not losing data if the plugin reloads.
The player_connect event should contain something about it tbh... Ty for info and I'll attempt something.
__________________
I am available to make plugins for pay.

Discord: Eyal282#1334
eyal282 is offline
pride95
Senior Member
Join Date: Aug 2015
Old 04-04-2018 , 15:14   Re: [L4D2] How to hook player connect without players from last chapter
Reply With Quote #15

Quote:
Originally Posted by eyal282 View Post
The player_connect event should contain something about it tbh... Ty for info and I'll attempt something.
check my code from previous posts.
pride95 is offline
Kyu67
New Member
Join Date: Apr 2018
Old 04-05-2018 , 07:48   Re: [L4D2] How to hook player connect without players from last chapter
Reply With Quote #16

Quote:
Originally Posted by pride95 View Post
PHP Code:

int IntMaxUserId
;

public 
void OnPluginStart()
{
    
HookEvent("player_connect_full"Event_PlayerConnect);
}

public 
void OnMapStart()
{
    
int Bot CreateFakeClient("Bot");
    
IntMaxUserid GetClientUserId(Bot);
    
KickClient(Bot);
}

public 
Action Event_PlayerConnect(Event event, const char[] namebool dontBroadcast
{
    
int Id event.GetInt("userid");
    
int Client GetClientOfUserId(Id);
    
    if(
Id IntMaxUserid)
    {
        ... 
connection from previous map
    
}

i don't know if the bot has some userid, but this is an idea. You should find a signature and use in gamedata (if exists) for connections from previous maps. If the players keep their userid on map change i think there should be a signature for this.
I am doing something that requires this same thing, where I want to keep tract of new people joining - specifically, joining for the first time in a campaign (I want to do something if somebody is joining for the first time in a campaign - or if they disconnect and rejoin at some point - so NOT when a new chapter of a campaign is loaded into).

I've tested with the mentioned user ID method, and it looks like it doesn't change while loading the 2nd or 3rd level of a campaign - You only get a new user ID if you connect again after leaving. So from my tests, if I store a user ID, and check people who join against the stored ID's, it has always worked for checking if someone is joining for the first time.

The problem is that the OnMapStart() event happens both during new map loads as well as during map changes to the next chapter in a campaign; so this can't be used to clear the stored user ID's since that would be saying everyone who loads into the next part of a campaign is joining for the first time.

Does anyone know if there is some other event for something like starting a new campaign/the first level?

Edit: "Round_Start" won't work, this happens even more often than OnMapStart

Last edited by Kyu67; 04-05-2018 at 08:21.
Kyu67 is offline
Visual77
Veteran Member
Join Date: Jan 2009
Old 04-05-2018 , 08:54   Re: [L4D2] How to hook player connect without players from last chapter
Reply With Quote #17

Quote:
Originally Posted by Kyu67 View Post

Does anyone know if there is some other event for something like starting a new campaign/the first level?

Edit: "Round_Start" won't work, this happens even more often than OnMapStart
I'm not sure what you want. But here's what you can do.
Code:
public void OnMapStart()
{
	char map[32];
	GetCurrentMap(map, sizeof(map));
	
	if (StrContains(map, "m1_", false) != -1)
	{
		// clear array? 
	}
}

Last edited by Visual77; 04-05-2018 at 09:14.
Visual77 is offline
cravenge
Veteran Member
Join Date: Nov 2015
Location: Chocolate Factory
Old 04-06-2018 , 06:21   Re: [L4D2] How to hook player connect without players from last chapter
Reply With Quote #18

I don't know if OnClientAuthorized is fired once the client has connected to the server... but it is a safer bet than having nothing.

PHP Code:
bool bMapChangingbInLastMap[MAXPLAYERS+1];
ArrayList alLastPlayers;

public 
void OnPluginStart()
{
    
alLastPlayers = new ArrayList(ByteCountToCells(32));
}

public 
void OnClientAuthorized(int client, const char[] auth)
{
    if (
IsFakeClient(client))
    {
        return;
    }
    
    
int iIDMatch alLastPlayers.FindString(auth);
    if (
iIDMatch != -1)
    {
        
bInLastMap[client] = true;
    }
}

public 
void OnClientConnected(int client)
{
    if (
bMapChanging || bInLastMap[client]) /* Gotcha! */
    
{
        return;
    }
}

public 
void OnMapStart()
{
    
bMapChanging false;
}

public 
void OnMapEnd()
{
    
bMapChanging true;
    if (
alLastPlayers.Length 0)
    {
        
alLastPlayers.Clear();
    }
    
    for (
int i 1<= MaxClientsi++)
    {
        if (
IsClientInGame(i) && !IsFakeClient(i))
        {
            if (
bInLastMap[i])
            {
                
bInLastMap[i] = false;
            }
            
            
char sSteamID[32];
            
GetClientAuthId(iAuthId_Steam2sSteamIDsizeof(sSteamID);
            
alLastPlayers.PushString(sSteamID);
        }
    }

Quote:
Originally Posted by Visual77 View Post
[...]
Wouldn't L4DT2 be helpful in this case? The idea of "using one native vs. hardcoding all first maps of all campaigns" is better.

... That is unless no custom campaigns are involved.

Last edited by cravenge; 04-06-2018 at 06:33.
cravenge is offline
Visual77
Veteran Member
Join Date: Jan 2009
Old 04-06-2018 , 06:55   Re: [L4D2] How to hook player connect without players from last chapter
Reply With Quote #19

Quote:
Originally Posted by cravenge View Post
Wouldn't L4DT2 be helpful in this case? The idea of "using one native vs. hardcoding all first maps of all campaigns" is better.

... That is unless no custom campaigns are involved.
For linux users, yes. For windows users, I would either hardcode or look for some kind of entity that all first maps have (avoid downtown if you're on windows).

On a side note, I'm not sure how practical this is but would OnClientConnected + GetClientTime be easier to detect the first connection. GetClientTime most likely returns 0 or 1 s for newly connected players.

Code:
public void OnClientConnected(int client)
{
	if (IsFakeClient(client)) return;

	int connectionTime = RoundFloat(GetClientTime(client));
	if (connectionTime != 0) return;
	
	LogMessage("%N connected for the first time", client);
}

Last edited by Visual77; 04-06-2018 at 07:27.
Visual77 is offline
MasterMind420
BANNED
Join Date: Nov 2010
Old 04-06-2018 , 11:42   Re: [L4D2] How to hook player connect without players from last chapter
Reply With Quote #20

possibly use player_entered_start_area eventhook, which will fire when players enter the first maps start area. Set a bool in there to identify it as the first campaign map, and in player_first_spawn hook if that bool is true, do what u want, set the bool to false during round_end hook, I use this method for things I only wanna do during the first campaign map to players...also I wouldnt put anything directly into player_entered_start_area other than a bool because a player could leave the start area and walk back into it and trigger it over and over again...just use it to identify the first campaign map. Should work for custom maps as well if they trigger this hook also, i dont know though...

Last edited by MasterMind420; 04-06-2018 at 11:45.
MasterMind420 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 01:26.


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