[Tutorial] How to make an simple ping kicker system
#1

THIS TUTORIALS IS FOR NEWBIES
1)first lets define the max ping(so you can change it easily)
PHP Code:
#define MAX_PING        1000 //so this can be changed easily 
2)setting a timer to check for the ping (under ongamemodeint or onfilterscriptint)
PHP Code:
public OnGameModeInit()
{
    
SetTimer("PingKick",5000,1);//Setting a timer to check for the players ping..5000 miliseconds = 5 secs
    
return 1;

3)PingKick function
PHP Code:
public PingKick()
{
    for(new 
0GetPlayerPoolSize(); <= ji++)//looping through players
    
{
        if(
IsPlayerConnected(i))//to see whether the player is connected
        
{
            if(
GetPlayerPing(i) > MAX_PING)//checking for the ping( and continuing if ping is above max ping)
            
{
                new 
string[128],name[MAX_PLAYER_NAME];//some variables for string and playername
                
GetPlayerName(playeridnamesizeof(name));//formatting the variable name with the name of the player
                
format(string,sizeof(string),"PING-KICK:%s(%d) has automatically been kicked. Reason: {00FFFF}High Ping(%d / %d)",name,i,GetPlayerPing(i),MAX_PING);//formatting a message to send
                
SendClientMessageToAll(-1,string);//sending the formatted messaage
                
Kick(i);//kicking the player with High ping
            
}
        }
     }

hope you learned something
Reply
#2

Suggestion: some people get the 65535 ping bug so you should add in the condition:
if(GetPlayerPing(i) > MAX_PING && GetPlayerPing(i) != 65535)
Reply
#3

Why are you create variables and send message for all players in a cycle? Here is my version ^-^

PHP Code:
#tryinclude <sscanf2>
#define MAX_PLAYER_PING (1000)
public OnGameModeInit()
{
    
SetTimer("@__CheckPlayersPing"5_0001);
}
@
__CheckPlayersPing();
@
__CheckPlayersPing()
{
    static const 
        
fmt_str[] = "[Server] %s has been kicked. Reason: {00FFFF}High Ping(%d / %d)";
    new 
        
str[sizeof(fmt_str)-2*3+(MAX_PLAYER_NAME+1)+5*2];
        
#if (defined foreach) && (defined Player@YSII_Ag) 
    
foreach (new i:Player
#else 
    
for (new GetPlayerPoolSize() + 1i-- != 0; ) if (IsPlayerConnected(i)) 
#endif
    
{
        if ((
GetPlayerPing(i) > MAX_PLAYER_PING) && (GetPlayerPing(i) != 65535))
        {
            
GetPlayerName(istrMAX_PLAYER_NAME 1);
            
format(strsizeof(str), fmt_strstrGetPlayerPing(i), MAX_PLAYER_PING);
            
Kick(i);
        }
    }
    
SendClientMessageToAll(-1str);

My version I haven't tested, but should work
Reply
#4

Quote:
Originally Posted by Untonyst
View Post
Why are you create variables and send message for all players in a cycle? Here is my version ^-^

PHP Code:
#tryinclude <sscanf2>
#define MAX_PLAYER_PING (1000)
public OnGameModeInit()
{
    
SetTimer("@__CheckPlayersPing"5_0001);
}
@
__CheckPlayersPing();
@
__CheckPlayersPing()
{
    static const 
        
fmt_str[] = "[Server] %s has been kicked. Reason: {00FFFF}High Ping(%d / %d)";
    new 
        
str[sizeof(fmt_str)-2*3+(MAX_PLAYER_NAME+1)+5*2];
        
#if (defined foreach) && (defined Player@YSII_Ag) 
    
foreach (new i:Player
#else 
    
for (new GetPlayerPoolSize() + 1i-- != 0; ) if (IsPlayerConnected(i)) 
#endif
    
{
        if ((
GetPlayerPing(i) > MAX_PLAYER_PING) && (GetPlayerPing(i) != 65535))
        {
            
GetPlayerName(istrMAX_PLAYER_NAME 1);
            
format(strsizeof(str), fmt_strstrGetPlayerPing(i), MAX_PLAYER_PING);
            
Kick(i);
        }
    }
    
SendClientMessageToAll(-1str);

My version I haven't tested, but should work
PHP Code:
@__CheckPlayerPing();
@
__CheckPlayerPing()
{
    static const
        
fmt_str[] = "[Server] %s has been kicked. Reason: {00FFFF}High Ping(%d / "#MAX_PLAYER_PING")";
    
static
        
str[sizeof fmt_str -2*3+(MAX_PLAYER_NAME+1)+5];
#if defined foreach
    
foreach (new iPlayer)
#else
    
for (new GetPlayerPoolSize(), ping; --!= -1; ) if (GetPlayerName(istrMAX_PLAYER_NAME 1) != 0)
#endif
    
{
        if (((
ping GetPlayerPing(i)) > MAX_PLAYER_PING) && (ping != 65535))
        {
            
format(isizeof strfmt_strping);
            
Kick(i);
        }
    }
    
SendClientMessageToAll(-1str);

Speed! Yes, it's very fast.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)