[Tutorial] How to make an simple ping kicker system
#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


Messages In This Thread
How to make an simple ping kicker system - by xTURBOx - 27.01.2016, 16:15
Re: How to make an simple ping kicker system - by Su37Erich - 27.01.2016, 17:03
Re: How to make an simple ping kicker system - by Untonyst - 29.01.2016, 09:53
Re: How to make an simple ping kicker system - by VVWVV - 30.01.2016, 08:57

Forum Jump:


Users browsing this thread: 1 Guest(s)