Hi all, today i will show how to create a function which will serve to "kick"a player with high ping.
First, define a "enum" where will be the ticket send player:
Now define a "new",which refers to the "enum" and whether to use the ticket "CheckPing":
NOTE: These last two should go to the top of your script.
Now, get to "public OnGameModeInt()" and put a timer wich is function to check player ping:
Follow this, make function check player ping:
Now, get to "public OnPlayerSpawn(playerid,classid,teamid)", and put ticket to send value 1, and thus in the function "public AntiLaag()", check if have value 1:
And put also ticket but with value 0 when a player leave server, this is in "OnPlayerDisconnect(playerid, reason)":
NOTE: if not have define "gPlayers", you need define, also if not have "FindPlayerIDFromString".
I hope something will help them in any problems please tell me.
Credits: YO ( Madara ).
Greetings
First, define a "enum" where will be the ticket send player:
Code Select
enum playerInfo
{
CheckPing,
}
Now define a "new",which refers to the "enum" and whether to use the ticket "CheckPing":
NOTE: These last two should go to the top of your script.
Code Select
new SpInfo[MAX_PLAYERS][playerInfo];
Now, get to "public OnGameModeInt()" and put a timer wich is function to check player ping:
Code Select
public OnGameModeInit()
{
SetTimer("AntiLaag",500,1);
return 1;
}
Follow this, make function check player ping:
Code Select
public AntiLaag()
{
for(new i = 0; i <= MAX_PLAYERS; i++) {
new sendmsn[256],plr = FindPlayerIDFromString(gPlayers[i]);
if (SpInfo[plr][CheckPing] == 1 && GetPlayerPing(plr) >= 1000) {
format(sendmsn,256, "Server - Kicked: %s, ID: %d, Reason:[ High Ping - %d ].",gPlayers[plr],plr,GetPlayerPing(plr));
SendClientMessageToAll(0x377DFFFF,sendmsn);
Kick(plr);
}
}
}
Now, get to "public OnPlayerSpawn(playerid,classid,teamid)", and put ticket to send value 1, and thus in the function "public AntiLaag()", check if have value 1:
Code Select
public OnPlayerSpawn(playerid,classid,teamid)
{
SpInfo[playerid][CheckPing] = 1;
return 1;
}
And put also ticket but with value 0 when a player leave server, this is in "OnPlayerDisconnect(playerid, reason)":
Code Select
public OnPlayerDisconnect(playerid, reason)
{
SpInfo[playerid][CheckPing] = 0;
return 1;
}
NOTE: if not have define "gPlayers", you need define, also if not have "FindPlayerIDFromString".
I hope something will help them in any problems please tell me.
Credits: YO ( Madara ).
Greetings