PDA

View Full Version : What is better?


DusanInfinity
11/10/2015, 12:23 PM
Hi!
In my script, i have this part:

if(PlayerInfo[playerid][pAdmin] < 1) Commands[playerid] ++;
if(Commands[playerid] >= 1)
{
KillTimer_H(CommandsTimer[playerid]);
CommandsTimer[playerid] = SetTimerEx("ResetCommands",4000,false,"i",playerid);
}
if(Commands[playerid] == 3) SendClientMessage(playerid, COLOR_LIGHTBLUE,"* Slow down with commands!");
if(Commands[playerid] == 5)
{
SendClientMessage(playerid,COLOR_LIGHTRED, "You are kicked!");
KillTimer_H(CommandsTimer[playerid]);
Kick(playerid);
}

And i need your help... Is that good, or is better to create one global timer in OnGameModeInit, and it will work like this:

public Timer()
{
foreach(Player, i)
{
If(Commands[i] > 0) Commands[i] = 0;
}
return 1;
}
And timer will repeat every 4 seconds, for ex...


I need your help, because i think, when 300 players enter any command, automatically will be activated 300 Timers, and that timers will slow server too much... I think this foreach looping will be better...

Dusan01
11/10/2015, 12:26 PM
you can use this: new AntiSpam[MAX_PLAYERS];
if(gettime() < AntiSpam[playerid]) {
AntiSpam[playerid] = gettime() + 4;
}
else {
//here to send him to he is spaming
}

DusanInfinity
11/10/2015, 12:45 PM
Okey, thank you...
when 300 players enter any command, automatically will be activated 300 Timers, and that timers will slow server too much
Is this true?

Edit: if(gettime() < AntiSpam[playerid]) {
AntiSpam[playerid] = gettime() + 4;
}
else {
//here to send him to he is spaming
}

This not working good.
Why? - gettime is always > 1, and antispam is 0, we will use for ex, gettime() = 1000,
if(gettime() < AntiSpam[playerid]) >>> 1000 < 0, it will automatically go to else {
//here to send him to he is spaming
}
And player will be warned just for 1 command, but if we change this: if(gettime() > AntiSpam[playerid])
it will do this, AntiSpam[playerid] = gettime() + 4;
but if player enter 1 command more in next 3 seconds, he will get warn, and i don't want it, i want to player get warn at 3rd command, and at 5. to get kick...


Anyone else to help me?

Jefff
11/10/2015, 01:22 PM
new
AntiSpam[MAX_PLAYERS],
Commands[MAX_PLAYERS char]
;

if(PlayerInfo[playerid][pAdmin] < 1)
{
if((gettime() - AntiSpam[playerid]) < 4)
{
if(++Commands{playerid} > 4)
{
SendClientMessage(playerid,COLOR_LIGHTRED, "You are kicked!");
return !Kick(playerid);
}
if(Commands{playerid} > 2)
{
AntiSpam[playerid] = gettime();
return !SendClientMessage(playerid, COLOR_LIGHTBLUE,"* Slow down with commands!");
}
}
else
Commands{playerid} = 0;

AntiSpam[playerid] = gettime();
}