#include <a_samp>
if(playerping > maxping) // But the compiler will see it as..
if(playerping > 600) // Because we defined maxping as 600.
#include <a_samp>
#define maxping 600
#define maxlagtimes 5
new pLagTimes[MAX_PLAYERS]; // We make this variable to store the amount of times the system has detected lag on a player.
forward CheckPing(); // If we make a public function, we have to forward it or it wouldn't work.
public CheckPing() // This is the function, we use dont need CheckPing(playerid) because we loop the players inside the function already.
{
new string[128], pName[MAX_PLAYER_NAME]; // We make strings to hold the message, and the player name.
new pPing; // We make a new variable and store that players ping in it.
// I put these outside of the loop, so the loop would be faster.
for(new i = 0; i < MAX_PLAYERS;i++) // This loops through all player slots in the server.
{
if(IsPlayerConnected(i)) // If it detects a player is connected in that player slot..
{
pPing = GetPlayerPing(i); // We put the players ping in a variable.
if(pPing > maxping) // If player's ping is over the allowed amount, then..
{
pLagTimes[i]++; // We add 1 lag time. When he reaches 5 lag times, player will get kicked.
// This is useful, because a lag spike can happen, but when he lags 5 times I'm sure the player is lagging.
if(pLagTimes[i] == maxlagtimes) // Now we check if players lag times have reached the maxlagtimes. You can edit maxlagtimes, so people have more chance to not be kicked.
{
GetPlayerName(i, pName, sizeof(pName)); // With this we get the players name and store it in the string.
format(string, sizeof string, "User %s has been kicked because of high ping! (%d/%d)", pName, pPing, maxping); // Now we format the message, because we use strings in the message we have to format it.
SendClientMessageToAll(-1, string); // We send it to all the players, -1 is the color white.
Kick(i); // We kick the player.
}
}
}
}
}
public OnFilterScriptInit() // When the filterscript starts in the game.
{
SetTimer("Checkping", 1000*5, 1); // It will set a timer, the function CheckPing will execute in every 5 secs. 1 in the end means, that it will repeat.
return 1;
}
public OnPlayerConnect(playerid) // When a new player connects.
{
pLagTimes[playerid] = 0; // We set the amount of pLagTimes[playerid] to 0.
return 1;
}
#include <a_samp>
#define maxping 600
#define maxlagtimes 5
new pLagTimes[MAX_PLAYERS]; // We make this variable to store the amount of times the system has detected lag on a player.
public OnFilterScriptInit() // When the filterscript starts in the game.
{
SetTimer("Checkping", 1000*5, 1); // It will set a timer, the function CheckPing will execute in every 5 secs. 1 in the end means, that it will repeat.
return 1;
}
public OnPlayerConnect(playerid) // When a new player connects.
{
pLagTimes[playerid] = 0; // We set the amount of pLagTimes[playerid] to 0.
return 1;
}
forward CheckPing(); // If we make a public function, we have to forward it or it wouldn't work.
public CheckPing() // This is the function, we use dont need CheckPing(playerid) because we loop the players inside the function already.
{
new string[128], pName[MAX_PLAYER_NAME]; // We make strings to hold the message, and the player name.
new pPing; // We make a new variable and store that players ping in it.
// I put these outside of the loop, so the loop would be faster.
for(new i = 0; i < MAX_PLAYERS;i++) // This loops through all player slots in the server.
{
if(IsPlayerConnected(i)) // If it detects a player is connected in that player slot..
{
pPing = GetPlayerPing(i); // We put the players ping in a variable.
if(pPing > maxping) // If player's ping is over the allowed amount, then..
{
pLagTimes[i]++; // We add 1 lag time. When he reaches 5 lag times, player will get kicked.
// This is useful, because a lag spike can happen, but when he lags 5 times I'm sure the player is lagging.
if(pLagTimes[i] == maxlagtimes) // Now we check if players lag times have reached the maxlagtimes. You can edit maxlagtimes, so people have more chance to not be kicked.
{
GetPlayerName(i, pName, sizeof(pName)); // With this we get the players name and store it in the string.
format(string, sizeof string, "User %s has been kicked because of high ping! (%d/%d)", pName, pPing, maxping); // Now we format the message, because we use strings in the message we have to format it.
SendClientMessageToAll(-1, string); // We send it to all the players, -1 is the color white.
Kick(i); // We kick the player.
}
}
}
}
}
The SendClientMessageToAll only gets sent when a players ping is over the allowed..
|
GetPlayerName(playerid,pName,sizeof(pname));
PingCheck();