16.11.2012, 14:06
(
Последний раз редактировалось Dan.; 17.11.2012 в 12:08.
)
Hi,
I'll explaing to you how to make a ping-kicker, some people may have some lag spikes but this system wont kick you then. Well, let's start then!
How to:
1) Open pawno.exe
2) Make a new script file (CTRL+N)
3) Delete everything inside it
4) Now, let's make the script itself.
a) First you should add this on top of your script:
Now we can use the basic script functions like SendClientMessage and so on.
b) It would be annoying if you have to change the max ping inside the script, to prevent this, lets make a define. When we use this define "maxping" in anywhere in the script, it will replace it with the number you defined it with. Example:
Also lets define maxlagtimes, it will be explained later.
So, now our script should look like this:
c) Now we have to create a function, so we can check if the player ping is over the allowed.
d) But now we need to use it, we have the function, but we are not actually using it. For this, we do this thing:
e) Now the script is almost done, but think of one thing.. when a player gets kicked, then pLagTimes[playerid] will still be 5, and when the script checks the player, he gets kicked. So, how do we reset it? It's simple:
5) The script is now done, and it should look like this:
I hope this tutorial helped you!
Click here to download full script: Solidfiles
I'll explaing to you how to make a ping-kicker, some people may have some lag spikes but this system wont kick you then. Well, let's start then!
How to:
1) Open pawno.exe
2) Make a new script file (CTRL+N)
3) Delete everything inside it
4) Now, let's make the script itself.
a) First you should add this on top of your script:
pawn Код:
#include <a_samp>
b) It would be annoying if you have to change the max ping inside the script, to prevent this, lets make a define. When we use this define "maxping" in anywhere in the script, it will replace it with the number you defined it with. Example:
pawn Код:
if(playerping > maxping) // But the compiler will see it as..
if(playerping > 600) // Because we defined maxping as 600.
So, now our script should look like this:
pawn Код:
#include <a_samp>
#define maxping 600
#define maxlagtimes 5
pawn Код:
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.
}
}
}
}
}
pawn Код:
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;
}
pawn Код:
public OnPlayerConnect(playerid) // When a new player connects.
{
pLagTimes[playerid] = 0; // We set the amount of pLagTimes[playerid] to 0.
return 1;
}
pawn Код:
#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.
}
}
}
}
}
Click here to download full script: Solidfiles