What is better?
#1

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...
Reply
#2

you can use this:
PHP код:
new AntiSpam[MAX_PLAYERS]; 
PHP код:
if(gettime() < AntiSpam[playerid]) {
    
AntiSpam[playerid] = gettime() + 4;
}
else {
    
//here to send him to he is spaming

Reply
#3

Okey, thank you...
Quote:

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?
Reply
#4

pawn Код:
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();
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)