15.09.2016, 14:50
#resolvido
new AntiFloodCommand[MAX_PLAYERS][2];
public OnPlayerCommandPerformed(playerid, cmdtext[], success)
{
if(gettime() - AntiFloodCommand[playerid][0] >= 2)
{
AntiFloodCommand[playerid][1] = 0;
AntiFloodCommand[playerid][0] = gettime();
}
AntiFloodCommand[playerid][1]++;
if(AntiFloodCommand[playerid][1] > 10)
{
SendClientMessage(i, -1, "Vocк foi kickado por floodar 10 comandos em 2 segundos, os admins foram avisados !");
Kick(i);
}
return 1;
}
|
Muito mais fбcil e otimizado usando gettime():
Код:
new AntiFloodCommand[MAX_PLAYERS][2];
public OnPlayerCommandPerformed(playerid, cmdtext[], success)
{
if(gettime() - AntiFloodCommand[playerid][0] >= 2)
{
AntiFloodCommand[playerid][1] = 0;
AntiFloodCommand[playerid][0] = gettime();
}
AntiFloodCommand[playerid][1]++;
if(AntiFloodCommand[playerid][1] > 10)
{
SendClientMessage(i, -1, "Vocк foi kickado por floodar 10 comandos em 2 segundos, os admins foram avisados !");
Kick(i);
}
return 1;
}
|
|
@Edit
Testou o cуdigo? Toda a vez que for realizado um comando, a array AntiFloodCommand[playerid][1] vai aumentar independentemente se for digitado em mais ou menos de 2 segundos. E sim, este modo й o mais otimizado se nгo quiser mostrar quantos segundos faltam para digitar. |