Raised This Month: $ Target: $400
 0% 

Solved [L4D2] how to check for the latest joined player


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
tiphong
Member
Join Date: Aug 2022
Location: Taiwan
Old 07-07-2023 , 00:35   [L4D2] how to check for the latest joined player
Reply With Quote #1

hi , i am currently trying to find out out of everyone in the server who is the latest connected player (i.e, the person with the least concurrent playtime in server, the person who has just joined to the server).

I can get the earliest player with GetClientTime() but how can i get the latest player?

Last edited by tiphong; 07-12-2023 at 07:30.
tiphong is offline
Marttt
Veteran Member
Join Date: Jan 2019
Location: Brazil
Old 07-07-2023 , 06:19   Re: [L4D2] how to check for the latest joined player
Reply With Quote #2

Using the inverse logic of GetClientTime()?
__________________
Marttt is offline
HarryPotter
Veteran Member
Join Date: Sep 2017
Location: Taiwan, Asia
Old 07-07-2023 , 17:01   Re: [L4D2] how to check for the latest joined player
Reply With Quote #3

Use global variable to save server time for every client


PHP Code:
float g_fConnectInServer[MAXPLAYERS+1];

public 
void OnClientPutInServer(int client)
{
    if(
IsFakeClient(client)) return;

    
g_fConnectInServer[client] = GetEngineTime();

__________________

Last edited by HarryPotter; 07-07-2023 at 17:02.
HarryPotter is offline
tiphong
Member
Join Date: Aug 2022
Location: Taiwan
Old 07-07-2023 , 18:12   Re: [L4D2] how to check for the latest joined player
Reply With Quote #4

Quote:
Originally Posted by HarryPotter View Post
Use global variable to save server time for every client


PHP Code:
float g_fConnectInServer[MAXPLAYERS+1];

public 
void OnClientPutInServer(int client)
{
    if(
IsFakeClient(client)) return;

    
g_fConnectInServer[client] = GetEngineTime();

thanks alot!
tiphong is offline
tiphong
Member
Join Date: Aug 2022
Location: Taiwan
Old 07-07-2023 , 18:14   Re: [L4D2] how to check for the latest joined player
Reply With Quote #5

Quote:
Originally Posted by Marttt View Post
Using the inverse logic of GetClientTime()?
yes sorry maybe i write post wrong but i was just wondering if there was better method to save/check gametime of client

Last edited by tiphong; 07-07-2023 at 18:17.
tiphong is offline
tiphong
Member
Join Date: Aug 2022
Location: Taiwan
Old 07-11-2023 , 01:35   Re: [L4D2] how to check for the latest joined player
Reply With Quote #6

Quote:
Originally Posted by HarryPotter View Post
Use global variable to save server time for every client


PHP Code:
float g_fConnectInServer[MAXPLAYERS+1];

public 
void OnClientPutInServer(int client)
{
    if(
IsFakeClient(client)) return;

    
g_fConnectInServer[client] = GetEngineTime();

hi, when trying to return this variable, it seems to return "Console" which is not a player, i am not sure why that is, what is the proper usage to find the earliest player in g_fConnectInServer[]? i have used g_fConnectInServer[len - 1] but still returns Console. i am very new to coding

Last edited by tiphong; 07-11-2023 at 01:36.
tiphong is offline
Marttt
Veteran Member
Join Date: Jan 2019
Location: Brazil
Old 07-11-2023 , 14:08   Re: [L4D2] how to check for the latest joined player
Reply With Quote #7

Console is the [0] index, no reason to do "len-1", since client indexes starts from "1" and not from "0"
Without code snippet is hard to help
__________________
Marttt is offline
HarryPotter
Veteran Member
Join Date: Sep 2017
Location: Taiwan, Asia
Old 07-12-2023 , 04:17   Re: [L4D2] how to check for the latest joined player
Reply With Quote #8

Quote:
Originally Posted by tiphong View Post
hi, when trying to return this variable, it seems to return "Console" which is not a player, i am not sure why that is, what is the proper usage to find the earliest player in g_fConnectInServer[]? i have used g_fConnectInServer[len - 1] but still returns Console. i am very new to coding
PHP Code:
public void OnPluginStart()
{
    
RegConsoleCmd("sm_test"Cmd_test);
}

Action Cmd_test(int clientint args)
{
    
float fMax 0.0;
    
int iTarget;
    for(
int player 1player <= MaxClientsplayer++)
    {
        if(!
IsClientInGame(player)) continue;

        if(
IsFakeClient(player)) continue;

        if(
fMax g_fConnectInServer[player])
        {
            
fMax g_fConnectInServer[player];
            
iTarget player;
        }
    }

    
PrintToChatAll("latest joined player: %N"iTarget);

    return 
Plugin_Handled;

__________________
HarryPotter is offline
tiphong
Member
Join Date: Aug 2022
Location: Taiwan
Old 07-12-2023 , 07:27   Re: [L4D2] how to check for the latest joined player
Reply With Quote #9

Quote:
Originally Posted by HarryPotter View Post
PHP Code:
public void OnPluginStart()
{
    
RegConsoleCmd("sm_test"Cmd_test);
}

Action Cmd_test(int clientint args)
{
    
float fMax 0.0;
    
int iTarget;
    for(
int player 1player <= MaxClientsplayer++)
    {
        if(!
IsClientInGame(player)) continue;

        if(
IsFakeClient(player)) continue;

        if(
fMax g_fConnectInServer[player])
        {
            
fMax g_fConnectInServer[player];
            
iTarget player;
        }
    }

    
PrintToChatAll("latest joined player: %N"iTarget);

    return 
Plugin_Handled;

very thanks!! this has made things a lot clearer
tiphong is offline
tiphong
Member
Join Date: Aug 2022
Location: Taiwan
Old 07-12-2023 , 07:35   Re: [L4D2] how to check for the latest joined player
Reply With Quote #10

Quote:
Originally Posted by Marttt View Post
Console is the [0] index, no reason to do "len-1", since client indexes starts from "1" and not from "0"
Without code snippet is hard to help
thank you, i did not know, my original code was the same as HarryPotter's but I was checking
PHP Code:
 if(fMax <= g_fConnectInServer[player]) 
i am guessing the <= operator is why it was returning console? i was using >= to check for the latest player (works) and i assumed that the same but reverse would be for the earliest player ( i am not home atm so i can not check out it )

Last edited by tiphong; 07-12-2023 at 07:53.
tiphong 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 11:21.


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