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

get average ping


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
pcquad
Member
Join Date: Jan 2012
Old 01-16-2013 , 17:46   get average ping
Reply With Quote #1

Following code should only show the average ping ( Sum of all pings / playercount )
but it just shows some strange charsequence (e.g. the average Server ping is: Y?}BY?*********D******************C)
could anyone help me?

Code:
#pragma semicolon 1

#include <sourcemod>

#define PLUGIN_VERSION "1.4"

// Plugin info
public Plugin:myinfo = 
{
	name = "Get average Ping",
	author = "pcquad",
	description = "Simple average ping collect",
	version = PLUGIN_VERSION,
	url = "http://pcquad.de"
};

// Here we go!
public OnPluginStart()
{
 RegServerCmd("getpings", getpings);
}

// Check the ping!
public Action:getpings(args)
{



	new Float:Ping;
	new Float:Pinga;
	new Float:Pingaverage;
	// Admin flag immunity

	

	// First, let's get a count of the players in-game.
	new Players = 0;
	for (new i = 1; i <= MaxClients; i++)
	{
		if (IsClientConnected(i) && IsClientInGame(i) && !IsFakeClient(i))
			Players++;
	}

	// Perform the actual ping checking and warn issuing.
	for (new i = 1; i <= MaxClients; i++)
	{
		if (IsClientConnected(i) && IsClientInGame(i) && !IsFakeClient(i))
		{


			//GetClientAuthString(i, SteamID, sizeof(SteamID));
			//GetClientName(i, Name, sizeof(Name));

			Ping = GetClientAvgLatency(i, NetFlow_Outgoing) * 1024;
			Pinga = Pinga + Ping;


		}

	}
     Pingaverage = Pinga / MaxClients;

PrintToChatAll("the average Server ping is: %s", Pingaverage);
        Pingaverage = 0;
        Ping = 0;
        Pinga = 0;
return Plugin_Handled;
}
__________________
pcquad is offline
Bimbo1
Senior Member
Join Date: Jan 2010
Location: brazil
Old 01-16-2013 , 18:06   Re: get average ping
Reply With Quote #2

put %f in the place of %s,[since it's a float, not a string] divide Pinga by Players[, which is the player count] and you don't need to perform two loops. you can do the player count and get pings at the same loop. also, you don't to set everything to zero, once finished the code.
__________________
sie sind das essen und wir sind die jäger!

Last edited by Bimbo1; 01-16-2013 at 18:11.
Bimbo1 is offline
Afronanny
Veteran Member
Join Date: Aug 2009
Old 01-16-2013 , 23:56   Re: get average ping
Reply With Quote #3

You'll want to change this line:
PHP Code:
Pingaverage Pinga MaxClients
The average would be not Pinga divided by MaxClients, but Pinga divided by the number of in-game players.
Afronanny is offline
Bimbo1
Senior Member
Join Date: Jan 2010
Location: brazil
Old 01-17-2013 , 01:11   Re: get average ping
Reply With Quote #4

Quote:
Originally Posted by Afronanny View Post
You'll want to change this line:
PHP Code:
Pingaverage Pinga MaxClients
The average would be not Pinga divided by MaxClients, but Pinga divided by the number of in-game players.
yeah, he/she did the calc for the number of in-game players:
Code:
new Players = 0; 	for (new i = 1; i <= MaxClients; i++) 	{ 		if (IsClientConnected(i) && IsClientInGame(i) && !IsFakeClient(i)) 			Players++; 	}
he/she didn't use it, though.
Bimbo1 is offline
berni
SourceMod Plugin Approver
Join Date: May 2007
Location: Austria
Old 01-17-2013 , 11:05   Re: get average ping
Reply With Quote #5

Also keep in mind, that the ping displayed in the player's scoreboard, is not the same ping you get from GetClientAvgLatency.
__________________
Why reinvent the wheel ? Download smlib with over 350 useful functions.

When people ask me "Plz" just because it's shorter than "Please" I feel perfectly justified to answer "No" because it's shorter than "Yes"
powered by Core i7 3770k | 32GB DDR3 1886Mhz | 2x Vertex4 SSD Raid0
berni is offline
pcquad
Member
Join Date: Jan 2012
Old 01-17-2013 , 12:43   Re: get average ping
Reply With Quote #6

thanks guys

Quote:
Originally Posted by berni View Post
Also keep in mind, that the ping displayed in the player's scoreboard, is not the same ping you get from GetClientAvgLatency.
could you explain that ?
__________________
pcquad is offline
berni
SourceMod Plugin Approver
Join Date: May 2007
Location: Austria
Old 01-17-2013 , 15:27   Re: get average ping
Reply With Quote #7

well, have you ever compared the ping from the scoreboard with that you get from GetClientAvgLatency ? It's not the same.

Valve uses some weird formula to calculate a corrected ping.
You can find more details in this function which is a clone of the HL2 SDK code.
__________________
Why reinvent the wheel ? Download smlib with over 350 useful functions.

When people ask me "Plz" just because it's shorter than "Please" I feel perfectly justified to answer "No" because it's shorter than "Yes"
powered by Core i7 3770k | 32GB DDR3 1886Mhz | 2x Vertex4 SSD Raid0
berni is offline
pcquad
Member
Join Date: Jan 2012
Old 01-17-2013 , 17:23   Re: get average ping
Reply With Quote #8

Quote:
Originally Posted by berni View Post
well, have you ever compared the ping from the scoreboard with that you get from GetClientAvgLatency ? It's not the same.

Valve uses some weird formula to calculate a corrected ping.
You can find more details in this function which is a clone of the HL2 SDK code.
now what is the more exact algorithm is that known?
__________________
pcquad is offline
berni
SourceMod Plugin Approver
Join Date: May 2007
Location: Austria
Old 01-17-2013 , 18:03   Re: get average ping
Reply With Quote #9

I think there are multiple definitions what a ping or latency actually is in relation with gameservers.

I think the value displayed in the scoreboard is an attempt of the source makers to somewhat give the player a pretty and good-looking value, but I doubt that it is the real physical value.

But since players only know this value, I would just use this value retrieved from Client_GetFakePing for your scripting, anything else will probably confuse the players.
I can't tell tho if Valve changed anything in that formula for CS:GO or in some updates, you have to try it out, but I don't think so.
__________________
Why reinvent the wheel ? Download smlib with over 350 useful functions.

When people ask me "Plz" just because it's shorter than "Please" I feel perfectly justified to answer "No" because it's shorter than "Yes"
powered by Core i7 3770k | 32GB DDR3 1886Mhz | 2x Vertex4 SSD Raid0
berni 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 21:28.


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