Command spams
#1

Hello, anyone know how to make a delay to a command if was spammed more than 5 times in 2 seconds, or something like that.

And i saw on some servers, if i spam a command, it will show the message of the command only at a second, it will not send the message in same second
Reply
#2



Please be more clear i have no idea what you're saying here...

EDIT: okay now i understand you after your edit, gimme a sec gonna edit this again,

EDIT#2: Okay here's an example script:
You'll do this at OnPlayerCommand text with a few variables:
PHP код:
new TextTickOne[MAX_PLAYERS];
new 
TextTickTwo[MAX_PLAYERS]; 
#define MAX_WAIT_TIME 500 //max waiting time in MS (half a second here) 
public OnPlayerCommandText(playeridcmdtext[])

    if(
TextTickTwo[playerid] == && TextTickOne[playerid] ==TextTickOne[playerid] = GetTickCount();//if he hasn't used a cmd for a while
    
else if(TextTickOne[playerid] != && TextTickTwo[playerid] == 0TextTickTwo[playerid] = GetTickCount();//if he used a cmd once
    
else if(TextTickOne[playerid] != && TextTickTwo[playerid] != && TextTickTwo[playerid] - TextTickOne[playerid] < MAX_WAIT_TIME//if he messaged for the 2nd time check if last time was lower than the max time (500 ms)
    

        
SendClientMessage(playerid, -1" Hi, stop spamming you asshole"); 
        
TextTickOne[playerid] = 0///reset
        
TextTickTwo[playerid] = 0//Same ^^
        
return 0
    } 
    else if(
TextTickOne[playerid] != && TextTickTwo[playerid] != && TextTickTwo[playerid] - TextTickOne[playerid] >= MAX_WAIT_TIME//if it took him long enough to use a cmd again
    

            
TextTickOne[playerid] =0//reset
            
TextTickTwo[playerid] =0//Same ^^
    

    return 
1

public 
OnPlayerDisconnect(playeridreason

    
TextTickOne[playerid] =0//reset in case of disconnection
    
TextTickTwo[playerid] =0//Same ^^
    
return 1

Reply
#3

The edit is another thing that i want.

So, when a player spam a command more than 5 times, it will make a 60 seconds delay to use again the command.
Reply
#4

Quote:
Originally Posted by C0oL3r
Посмотреть сообщение
The edit is another thing that i want.

So, when a player spam a command more than 5 times, it will make a 60 seconds delay to use again the command.
The code i posted above will not allow any commands to be spammed in less than half a second
Reply
#5

it will send me the message and Unknown Command if i spam, i use ZCMD and the function is not OnPlayerCommandText, is OnPlayerCommandPerformed
Reply
#6

Quote:
Originally Posted by C0oL3r
Посмотреть сообщение
it will send me the message and Unknown Command if i spam, i use ZCMD and the function is not OnPlayerCommandText, is OnPlayerCommandPerformed
Doesn't matter buddy, it's the same,
PHP код:
new TextTickOne[MAX_PLAYERS]; 
new 
TextTickTwo[MAX_PLAYERS];  
#define MAX_WAIT_TIME 500 //max waiting time in MS (half a second here)  
public OnPlayerCommandPerformed(playeridcmdtext[], success)
{  
    if(
TextTickTwo[playerid] == && TextTickOne[playerid] ==TextTickOne[playerid] = GetTickCount();//if he hasn't used a cmd for a while 
    
else if(TextTickOne[playerid] != && TextTickTwo[playerid] == 0TextTickTwo[playerid] = GetTickCount();//if he used a cmd once 
    
else if(TextTickOne[playerid] != && TextTickTwo[playerid] != && TextTickTwo[playerid] - TextTickOne[playerid] < MAX_WAIT_TIME//if he messaged for the 2nd time check if last time was lower than the max time (500 ms) 
    
{  
        
SendClientMessage(playerid, -1" Hi, stop spamming you asshole");  
        
TextTickOne[playerid] = 0///reset 
        
TextTickTwo[playerid] = 0//Same ^^ 
        
return 1;  
    }  
    else if(
TextTickOne[playerid] != && TextTickTwo[playerid] != && TextTickTwo[playerid] - TextTickOne[playerid] >= MAX_WAIT_TIME//if it took him long enough to use a cmd again 
    
{  
        
TextTickOne[playerid] =0//reset 
        
TextTickTwo[playerid] =0//Same ^^ 
    
}  
    if(!
success)  return 0;
    else return 
1;
}  
public 
OnPlayerDisconnect(playeridreason)  
{  
    
TextTickOne[playerid] =0//reset in case of disconnection 
    
TextTickTwo[playerid] =0//Same ^^ 
    
return 1;  

You can also change the MAX_WAIT_TIME to the amount of time you want.
Reply
#7

I edited the last part in the onplayercommandperformed (success return value) so please re-check my code.
Reply
#8


i want to work like that, to don't say anything, i can send the wrong command, or anything, 2 times in one second
Reply
#9

anyone?
Reply
#10

Why don't you just save the timestamp and check if a number of seconds didn't pass yet.
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)