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

Solved Ping Question


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
PC Gamer
Veteran Member
Join Date: Mar 2014
Old 05-09-2022 , 06:53   Ping Question
Reply With Quote #1

Question....

When I use this plugin (or use the server console 'status' command) it tells me I have a ping of 26. When I press the TAB key to view the scoreboard with my ping it states my ping is 5.

Repeated usage gives me similar numbers.

Why the difference?

PHP Code:
#pragma semicolon 1
#pragma newdecls required

#include <sourcemod>

public Plugin myinfo = {
    
name "Ping_Viewer",
    
author "alasfourom, modified by PC Gamer",
    
description "Print Your Ping Into Chat",
    
version "1.1",
    
url "https://forums.alliedmods.net/"
};

public 
void OnPluginStart() {
    
RegConsoleCmd("sm_ping"Command_Ping"Print Ping To Chat");
    
RegAdminCmd("sm_pingall"Command_PingAllADMFLAG_SLAY"Print all Human Ping values to chat");     
}

public 
Action Command_Ping(int clientint args)
{
    if (
IsClientInGame(client) && !IsFakeClient(client))
    {
        
char sBuffer[64];
        
FormatEx(sBuffersizeof(sBuffer), "\x04Your Current Ping:\x05 %.3f ms"GetClientAvgLatency(clientNetFlow_Both));
        
ReplaceString(sBuffersizeof(sBuffer), "0.00"""false);
        
ReplaceString(sBuffersizeof(sBuffer), "0.0"""false);
        
ReplaceString(sBuffersizeof(sBuffer), "0."""false);
        
PrintToChat(clientsBuffer);
    }
    return 
Plugin_Handled;


public 
Action Command_PingAll(int clientint args)
{
    for (
int i 1<= MaxClientsi++)
    {
        if (
IsClientInGame(i) && !IsFakeClient(i)) 
        {
            
char sBuffer[64];
            
FormatEx(sBuffersizeof(sBuffer), "\x04Current Ping:\x05 %.3f ms"GetClientAvgLatency(iNetFlow_Both));
            
ReplaceString(sBuffersizeof(sBuffer), "0.00"""false);
            
ReplaceString(sBuffersizeof(sBuffer), "0.0"""false);
            
ReplaceString(sBuffersizeof(sBuffer), "0."""false);
            
PrintToChat(client"%N: %s"isBuffer);
        }
    }
    return 
Plugin_Handled;


Last edited by PC Gamer; 05-10-2022 at 05:55.
PC Gamer is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 05-09-2022 , 14:02   Re: Ping Question
Reply With Quote #2

scoreboard ping never worked right way. It use player cl_cmdrate and cl_updaterate. And maybe to do with TICKS

I maybe found that scoreboard code, below

Code:
void CPlayerResource::UpdatePlayerData( void )
{
	for ( int i = 1; i <= gpGlobals->maxClients; i++ )
	{
		CBasePlayer *pPlayer = (CBasePlayer*)UTIL_PlayerByIndex( i );
		
		if ( pPlayer && pPlayer->IsConnected() )
		{
			m_iKills.Set( i, pPlayer->FragCount() );
			m_iAssists.Set(i, pPlayer->AssistsCount() ); 
			m_iDeaths.Set( i, pPlayer->DeathCount() );
			m_bConnected.Set( i, 1 );
			m_iTeam.Set( i, pPlayer->GetTeamNumber() );
			m_iPendingTeam.Set( i, pPlayer->GetPendingTeamNumber() );
			m_bAlive.Set( i, pPlayer->IsAlive()?1:0 );
			m_iHealth.Set(i, MAX( 0, pPlayer->GetHealth() ) );
			m_iCoachingTeam.Set( i, pPlayer->GetCoachingTeam() );

			// Don't update ping / packetloss everytime

			if ( !(m_nUpdateCounter%20) )
			{
				// update ping all 20 think ticks = (20*0.1=2seconds)
				int ping, packetloss;
				UTIL_GetPlayerConnectionInfo( i, ping, packetloss );
				
				// calc avg for scoreboard so it's not so jittery
				ping = 0.8f * m_iPing.Get(i) + 0.2f * ping;

				
				m_iPing.Set( i, ping );
				// m_iPacketloss.Set( i, packetloss );
			}
		}
		else
		{
			m_bConnected.Set( i, 0 );
		}
	}
}


//... SECOND CODE BLOCK ...

//-----------------------------------------------------------------------------
// Purpose: 
// Input  : playerIndex - 
//			ping - 
//			packetloss - 
//-----------------------------------------------------------------------------
void UTIL_GetPlayerConnectionInfo( int playerIndex, int& ping, int &packetloss )
{
	CBasePlayer *player =  UTIL_PlayerByIndex( playerIndex );
	if ( player->IsSplitScreenPlayer() && 
		 player->GetSplitScreenPlayerOwner() )
	{
		player = player->GetSplitScreenPlayerOwner();
		playerIndex = player->entindex();
	}

	INetChannelInfo *nci = engine->GetPlayerNetInfo(playerIndex);

	if ( nci && player && !player->IsBot() )
	{
		float latency = nci->GetAvgLatency( FLOW_OUTGOING ); // in seconds
		
		// that should be the correct latency, we assume that cmdrate is higher 
		// then updaterate, what is the case for default settings
		const char * szCmdRate = engine->GetClientConVarValue( playerIndex, "cl_cmdrate" );
		const char * szUpdateRate = engine->GetClientConVarValue( playerIndex, "cl_updaterate" );

		static const ConVar *pSvClientCmdrateDifference = g_pCVar->FindVar( "sv_client_cmdrate_difference" );
		static const ConVar *pMinUpdateRate = g_pCVar->FindVar( "sv_minupdaterate" );
		static const ConVar *pMaxUpdateRate = g_pCVar->FindVar( "sv_maxupdaterate" );

		float flUpdateRateValue = Q_atof( szUpdateRate );
		if ( !player->IsHLTV() )
		{
			if ( pMinUpdateRate && pMaxUpdateRate )
				flUpdateRateValue = clamp( flUpdateRateValue, pMinUpdateRate->GetFloat(), pMaxUpdateRate->GetFloat() );
		}
		
		float flCmdRateValue = Q_atof( szCmdRate );
		if ( player->IsHLTV() )
		{
			flCmdRateValue = flUpdateRateValue;
		}
		else
		{
			// First, we make it stay within range of cl_updaterate.
			if ( pSvClientCmdrateDifference )
			{
				float diff = flCmdRateValue - flUpdateRateValue;
				float diffMaxCap = pSvClientCmdrateDifference->GetFloat();
				if ( fabs( diff ) > diffMaxCap )
				{
					if ( diff > 0 )
						flCmdRateValue = flUpdateRateValue + diffMaxCap;
					else
						flCmdRateValue = flUpdateRateValue - diffMaxCap;
				}
			}
			static const ConVar *pMinCmdRate = g_pCVar->FindVar( "sv_mincmdrate" );
			static const ConVar *pMaxCmdRate = g_pCVar->FindVar( "sv_maxcmdrate" );
			if ( pMinUpdateRate && pMaxUpdateRate )
				flCmdRateValue = clamp( flCmdRateValue, pMinCmdRate->GetFloat(), pMaxCmdRate->GetFloat() );
		}

		latency -= (0.5f/flCmdRateValue) + TICKS_TO_TIME( 1.0f ); // correct latency

		// in GoldSrc we had a different, not fixed tickrate. so we have to adjust
		// Source pings by half a tick to match the old GoldSrc pings.
		latency -= TICKS_TO_TIME( 0.5f );

		ping = latency * 1000.0f; // as msecs
		ping = clamp( ping, 5, 1000 ); // set bounds, dont show pings under 5 msecs
		
		packetloss = 100.0f * nci->GetAvgLoss( FLOW_INCOMING ); // loss in percentage
		packetloss = clamp( packetloss, 0, 100 );
	}
	else
	{
		ping = 0;
		packetloss = 0;
	}
}
*edit
This is maybe STATUS in console
Code:
/*
==================
Host_Status_PrintClient

Print client info to console 
==================
*/
void Host_Status_PrintClient( IClient *client, bool bShowAddress, void (*print) (const char *fmt, ...) )
{
	INetChannelInfo *nci = client->GetNetChannel();

	const char *state = "challenging";

	if ( client->IsActive() )
		state = "active";
	else if ( client->IsSpawned() )
		state = "spawning";
	else if ( client->IsConnected() )
		state = "connecting";
	
	if ( nci != NULL )
	{
		print( "# %2i %i \"%s\" %s %s %i %i %s %d", 
			client->GetUserID(), client->GetPlayerSlot() + 1, client->GetClientName(), client->GetNetworkIDString(), COM_FormatSeconds( nci->GetTimeConnected() ),
			(int)(1000.0f*nci->GetAvgLatency( FLOW_OUTGOING )), (int)(100.0f*nci->GetAvgLoss(FLOW_INCOMING)), state, (int)nci->GetDataRate() );

		if ( bShowAddress ) 
		{
			print( " %s", nci->GetAddress() );
		}
	}
	else
	{
		print( "#%2i \"%s\" %s %s %.0f", 
			client->GetUserID(), client->GetClientName(), client->GetNetworkIDString(), state, client->GetUpdateRate() );
	}
	
	print( "\n" );

}
__________________
Do not Private Message @me

Last edited by Bacardi; 05-09-2022 at 14:15.
Bacardi is offline
PC Gamer
Veteran Member
Join Date: Mar 2014
Old 05-10-2022 , 05:55   Re: Ping Question
Reply With Quote #3

Thanks Bacardi! As usual, a great answer.
PC Gamer 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 15:54.


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