How to make a check timer (will check laggers) -
Eth - 27.04.2014
What do you need is:
a_samp
Ok let's start , first of all we have to define the max ping and the max pl allowed in your server (pl = pocket loss)
so at the top of you script:
you can edit it with your own ping and packet loss:
pawn Code:
#define MAX_PING 1000 // Max Ping
#define MAX_PL 1.0 // Max Packet Loss
forward CheckStats();//for the timer
new Timer;//the define for the timer
#define COLOR_RED 0xFF0000AA //the color we are going to use on this tutorial
on gamemodeinit:
pawn Code:
Timer = SetTimer("CheckStats", 1000, true);//will start the timer when the server starts
and now the last thing, the timer
![Tongue](images/smilies/razz.gif)
ut it in any place in your gamemode:
pawn Code:
public CheckStats()
{
for (new i = 0; i != MAX_PLAYERS; ++ i)
{
if (IsPlayerConnected(i))
{
if(GetPlayerPing(i) > MAX_PING)//get the player ping more than the maximum ping allowed in server
{
new string[257];
format(string,sizeof(string),"{FF0000}Player{FFFFFF}[%s] has been kicked for exceeding ping limit [%d/%d]",GetName(i),GetPlayerPing(i),MAX_PING);//the format for a message to all players
SendClientMessageToAll(COLOR_RED,string);//and the message
Kick(i);//will kick him
}
if(GetPlayerPacketLoss(i) > MAX_PL)//get the player pl more than the maximum pl allowed in server
{
new string[257];
format(string,sizeof(string),"{FF0000}Player{FFFFFF}[%s] has been kicked for exceeding packetloss limit [%d/%d]",GetName(i),GetPlayerPacketLoss(i),MAX_PL);//the format for a message to all players
SendClientMessageToAll(COLOR_RED,string);//the message
Kick(i);//will kick him
}
}
return 1;
}
and the last thing:
pawn Code:
forward Float:GetPlayerPacketLoss(playerid);//forward for the packetloss
stock Float:GetPlayerPacketLoss(playerid)//the stock
{
new stats[401], stringstats[70];//those are the variables we will need in the stock
GetPlayerNetworkStats(playerid, stats, sizeof(stats));//this one will get the net stats
new len = strfind(stats, "Packetloss: ");//and this one will get the packetloss
new Float:packetloss = 0.0;//the float for the packetloss
if(len != -1)
{
strmid(stringstats, stats, len, strlen(stats));
new len2 = strfind(stringstats, "%");
if(len != -1)
{
strdel(stats, 0, strlen(stats));
strmid(stats, stringstats, len2-3, len2);
packetloss = floatstr(stats);
}
}
return packetloss;
}
it's just a simple timer to kick laggers, if there is no admin online :d ty for checking my post.
Edit:
special thanks to : Djole1337 for telling me the bug on this tutorial
Re: How to make a check timer (will check laggers) -
PrinceKumar - 27.04.2014
Nice tutorial i will give 8.5 points out of 10 ,
btw u need to explain a little about packet loss.
Re: How to make a check timer (will check laggers) -
nickdodd25 - 27.04.2014
Quote:
Originally Posted by Eth
pawn Code:
Timer = SetTimerEx("CheckStats",1000,1,"i");//will start the timer when the server starts
|
I think you might be missing something, also from experience don't kick players from the first high ping event. Your better off to give a few warnings if they are above the ping limit than kick them instantly. Same for packet loss.
Re: How to make a check timer (will check laggers) -
dusk - 27.04.2014
pawn Code:
Timer = SetTimerEx("CheckStats",1000,1,"i");//will start the timer when the server starts
You use the 'i' specifier but you don't pass anything to it so why not just use SetTimer?
Re: How to make a check timer (will check laggers) -
Eth - 27.04.2014
Quote:
Originally Posted by dusk
pawn Code:
Timer = SetTimerEx("CheckStats",1000,1,"i");//will start the timer when the server starts
You use the 'i' specifier but you don't pass anything to it so why not just use SetTimer?
|
i need the "playerid" to get the ping and the packet loss of the player but the ongamemodeinit doesn't have playerid so i used "i" instead
Quote:
Originally Posted by nickdodd25
I think you might be missing something, also from experience don't kick players from the first high ping event. Your better off to give a few warnings if they are above the ping limit than kick them instantly. Same for packet loss.
|
no i am not missing anything, and a warn will be added
![Smiley](images/smilies/smile.png)
ty for telling me
Quote:
Originally Posted by PrinceKumar
Nice tutorial i will give 8.5 points out of 10 ,
btw u need to explain a little about packet loss.
|
ty dude
![Wink](images/smilies/wink.png)
and i am going to edit this post and explain more about pl.
Re: How to make a check timer (will check laggers) -
Djole1337 - 27.04.2014
It won't even work...
pawn Code:
public OnGameModeInit()
{
SetTimer("CheckStats", 1000, true);
return 1;
}
forward CheckStats();
public CheckStats()
{
for (new i = 0; i != MAX_PLAYERS; ++ i)
{
if (IsPlayerConnected(i))
{
// check code
}
}
return 1;
}
Never post untested code...
EDIT:
OnPlayerPacketLoss is not even SA-MP native function.
Re: How to make a check timer (will check laggers) -
Vince - 27.04.2014
Quote:
Originally Posted by PrinceKumar
btw u need to explain a little about packet loss.
|
Test it here:
http://www.pingtest.net/ (you will need to temporarily allow Java)
http://www.pingtest.net/learn.php#components
Anything greater than 0% is bad.
Re: How to make a check timer (will check laggers) -
Eth - 27.04.2014
ty Djole1337 i was going to school at that time and i didn't check it well, topic modified..
fixed the bugs. ty for telling me.
Re: How to make a check timer (will check laggers) -
satafinix - 01.05.2014
Finaly Something Good
![Wink](images/smilies/wink.png)
+Rep
Re: How to make a check timer (will check laggers) -
Deathlane - 01.05.2014
Hmm? I don't think stock functions doesn't need to be forwarded..