[Tutorial] How to make a check timer (will check laggers)
#1

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 timerut 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
Reply
#2

Nice tutorial i will give 8.5 points out of 10 ,
btw u need to explain a little about packet loss.
Reply
#3

Quote:
Originally Posted by Eth
View Post
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.
Reply
#4

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?
Reply
#5

Quote:
Originally Posted by dusk
View Post
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
View Post
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 ty for telling me
Quote:
Originally Posted by PrinceKumar
View Post
Nice tutorial i will give 8.5 points out of 10 ,
btw u need to explain a little about packet loss.
ty dude and i am going to edit this post and explain more about pl.
Reply
#6

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.
Reply
#7

Quote:
Originally Posted by PrinceKumar
View Post
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.
Reply
#8

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.
Reply
#9

Finaly Something Good +Rep
Reply
#10

Hmm? I don't think stock functions doesn't need to be forwarded..
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)