This is gonna be a long bit of code, but it stores every ping into a table every five seconds for each player, then adds them all together, then divides it by how many pings each player has. so here goes ...
By the way, this script might teach some people about multidimensional tables. Also, adjust the MaxPing variable to your liking:
Some credits for this:
Idea from VetalYA
GetPlayersTable() from himselfe
function onScriptLoad()
{
MaxPing <- 400;
PingTimer <- NewTimer("CalculatePingAverage",5000,0);
PingTimer.Start();
PingInfo <- {};
}
function onPlayerConnect(player)
{
PingInfo[player.ID] <- {};
PingInfo[player.ID].PingCount <- 0;
PingInfo[player.ID].Average <- 0;
PingInfo[player.ID].TotalPing <- 0;
}
function CalculatePingAverage()
{
local players = GetPlayersTable();
foreach(player in players)
{
PingInfo[player.ID].PingCount <- PingInfo[player.ID].PingCount + 1;
local pingcount = PingInfo[player.ID].PingCount;
PingInfo[player.ID].Pings <- {};
PingInfo[player.ID].Pings[pingcount] <- {};
PingInfo[player.ID].Pings[pingcount].Ping <- player.Ping;
PingInfo[player.ID].TotalPing <- PingInfo[player.ID].TotalPing + PingInfo[player.ID].Pings[pingcount].Ping
PingInfo[player.ID].Average <- PingInfo[player.ID].TotalPing / pingcount;
if(PingInfo[player.ID].Average > MaxPing)
{
KickPlayer(player);
}
}
}
function GetPlayersTable()
{
local players = {};
for(local player,id = 0,count=GetMaxPlayers();id<count;id++)
{
if((player = FindPlayer(id)))
{
players.rawset(player.Name,player);
}
}
return players;
}
function onPlayerPart(player,reason)
{
PingInfo[player.ID] <- null;
}