#define MAX_PING 1000 //so this can be changed easily
public OnGameModeInit()
{
SetTimer("PingKick",5000,1);//Setting a timer to check for the players ping..5000 miliseconds = 5 secs
return 1;
}
public PingKick()
{
for(new i = 0, j = GetPlayerPoolSize(); i <= j; i++)//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(playerid, name, sizeof(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
}
}
}
}
#tryinclude <sscanf2>
#define MAX_PLAYER_PING (1000)
public OnGameModeInit()
{
SetTimer("@__CheckPlayersPing", 5_000, 1);
}
@__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 i = GetPlayerPoolSize() + 1; i-- != 0; ) if (IsPlayerConnected(i))
#endif
{
if ((GetPlayerPing(i) > MAX_PLAYER_PING) && (GetPlayerPing(i) != 65535))
{
GetPlayerName(i, str, MAX_PLAYER_NAME + 1);
format(str, sizeof(str), fmt_str, str, GetPlayerPing(i), MAX_PLAYER_PING);
Kick(i);
}
}
SendClientMessageToAll(-1, str);
}
Why are you create variables and send message for all players in a cycle? Here is my version ^-^
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 i: Player)
#else
for (new i = GetPlayerPoolSize(), ping; --i != -1; ) if (GetPlayerName(i, str, MAX_PLAYER_NAME + 1) != 0)
#endif
{
if (((ping = GetPlayerPing(i)) > MAX_PLAYER_PING) && (ping != 65535))
{
format(i, sizeof str, fmt_str, ping);
Kick(i);
}
}
SendClientMessageToAll(-1, str);
}