#define COLOR_RED 0xAA3333AA
#define COLOR_YELLOW 0xFFFF00AA
new MPing = 250;
SetTimerEx("PingTimer", 10000, true, "i", playerid);
forward PingTimer();
public PingTimer()
{
for(new i = 0; i < MAX_PLAYERS; i ++)
{
if(IsPlayerConnected(i))
{
if(!IsPlayerAdmin(i))
{
new ping = GetPlayerPing(i);
if(ping > MPing)
{
new name[MAX_PLAYER_NAME];
GetPlayerName(i, name, sizeof(name));
new string[128];
new plrIP[16];
GetPlayerIp(i, plrIP, sizeof(plrIP));
format(string, sizeof(string), "* %s[%d] has been auto-kicked for having a high ping [%d/%d]", name, i, ping, MPing);
SendClientMessageToAll(COLOR_YELLOW, string);
SetTimerEx("KickTimer", 1000, false, "i", i);
}
}
}
}
return 1;
}
forward PingTimer();
public PingTimer()
for(new i = 0; i < MAX_PLAYERS; i ++)
{
if(IsPlayerConnected(i))
{
if(!IsPlayerAdmin(i))
new ping = GetPlayerPing(i);
if(ping > MPing)
new name[MAX_PLAYER_NAME];
GetPlayerName(i, name, sizeof(name));
new string[128];
format(string, sizeof(string), "* %s[%d] has been auto-kicked for having a high ping [%d/%d]", name, i, ping, MPing);
SendClientMessageToAll(COLOR_YELLOW, string);
SetTimerEx("KickTimer", 1000, false, "i", i);
public KickTimer(playerid)
{
Kick(playerid);
return 1;
}
CMD:setping(playerid, params[]) {
if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, COLOR_RED, "[ADMIN] - Only admins can use this command!");
new string[128];
new newlimit;
if(sscanf(params, "i", newlimit)) return SendClientMessage(playerid, COLOR_RED, "[USAGE] - /setping [PING-LIMIT]");
MPing = newlimit;
new pName[MAX_PLAYER_NAME];
GetPlayerName(playerid, pName, sizeof(pName));
format(string, sizeof(string), "[ADMIN] - %s[%d] has used SETPING - New limit - %i", pName, playerid, newlimit);
SendMessageToAdmins(string);
format(string, sizeof(string), "[PING] - Admin %s[%d] has changed the ping-limit to %i!", pName, playerid, newlimit);
SendClientMessageToAll(COLOR_YELLOW, string);
return 1;
}
CMD:setping(playerid, params[]) {
if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, COLOR_RED, "[ADMIN] - Only admins can use this command!");
new string[128];
new newlimit;
if(sscanf(params, "i", newlimit)) return SendClientMessage(playerid, COLOR_RED, "[USAGE] - /setping [PING-LIMIT]");
if(sscanf(params, "i", newlimit)) return SendClientMessage(playerid, COLOR_RED, "[USAGE] - /setping [PING-LIMIT]");
MPing = newlimit;
new pName[MAX_PLAYER_NAME];
GetPlayerName(playerid, pName, sizeof(pName));
format(string, sizeof(string), "[ADMIN] - %s[%d] has used SETPING - New limit - %i", pName, playerid, newlimit);
SendMessageToAdmins(string);
format(string, sizeof(string), "[PING] - Admin %s[%d] has changed the ping-limit to %i!", pName, playerid, newlimit);
SendClientMessageToAll(COLOR_YELLOW, string);
new pName[MAX_PLAYER_NAME];
GetPlayerName(playerid, pName, sizeof(pName));
format(string, sizeof(string), "[ADMIN] - %s[%d] has used SETPING - New limit - %i", pName, playerid, newlimit);
SendMessageToAdmins(string);
format(string, sizeof(string), "[PING] - Admin %s[%d] has changed the ping-limit to %i!", pName, playerid, newlimit);
SendClientMessageToAll(COLOR_YELLOW, string);
stock SendMessageToAdmins(text[])
{
for(new i = 0; i < MAX_PLAYERS; i++)//loops trough players
{
if(IsPlayerAdmin(i)) //if is a RCON password
{
SendClientMessage(i, 0xCA3FBFAA, text);//he will receive the message.
}
}
}
//Local variable
new MPing = 250;//Sets default Max-Ping to 250
//OnPlayerSpawn
SetTimerEx("PingTimer", 10000, true, "i", playerid);//Starts the Timer that will check if a players ping is greater(more) than the max-ping limit
//==============[ANTI-PING TIMER]==============
forward PingTimer(); //forwards the timer : According to wiki: 'So the server can 'see' it'
public PingTimer() //The timer function
{
for(new i = 0; i < MAX_PLAYERS; i ++)//loops through the players
{
if(IsPlayerConnected(i)) //if is connect
{
if(!IsPlayerAdmin(i)) //if he is NOT a RCON admin
{
new ping = GetPlayerPing(i);
if(ping > MPing) //if his ping is greater(higher) than the Ping Limit
{
new name[MAX_PLAYER_NAME]; //Gets the players name
GetPlayerName(i, name, sizeof(name));
new string[128]; //creating a string
format(string, sizeof(string), "* %s[%d] has been auto-kicked for having a high ping [%d/%d]", name, i, ping, MPing); //formatting a message
SendClientMessageToAll(COLOR_YELLOW, string); //sending the message to everyone
SetTimerEx("KickTimer", 1000, false, "i", i); //starting the kick timer
}
}
}
}
return 1;
}
//KICK TIMER
public KickTimer(playerid)
{
Kick(playerid);//Kicks the player
return 1;
}
//CMD
CMD:setping(playerid, params[]) {
if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, COLOR_RED, "[ADMIN] - Only admins can use this command!");//If the person who is not a RCON admin he will receive this message ^
new string[128]; //creating a string
new newlimit; //new ping limit
if(sscanf(params, "i", newlimit)) return SendClientMessage(playerid, COLOR_RED, "[USAGE] - /setping [PING-LIMIT]"); //if he typed '/setping' he will receive the message above
MPing = newlimit; //If there were no errors etc then the MPing(maxping) will be set to what he wrote in /setping NewLimitHere
new pName[MAX_PLAYER_NAME]; //Gets players name
GetPlayerName(playerid, pName, sizeof(pName));
format(string, sizeof(string), "[ADMIN] - %s[%d] has used SETPING - New limit - %i", pName, playerid, newlimit); //formats a message
SendMessageToAdmins(string); //sends the message to the online admins
format(string, sizeof(string), "[PING] - Admin %s[%d] has changed the ping-limit to %i!", pName, playerid, newlimit); //formats another message
SendClientMessageToAll(COLOR_YELLOW, string); //sends message to everyone
return 1;
}
//SendMessageToAdmins stock
stock SendMessageToAdmins(text[])
{
for(new i = 0; i < MAX_PLAYERS; i++)//loops through the players
{
if(IsPlayerAdmin(i))//if he is a RCON admins
{
SendClientMessage(i, 0xCA3FBFAA, text);//he will receive this message
}
}
}
Why you're declaring "playerid" parameter in function? Do you actually know what you're doing?
|