25.06.2012, 16:30
I want that every command can be used only every 3 seconds by a player. So that their chat box will not flood like this.
![](http://s14.postimage.org/f7ljutohd/untitled.png)
This will just block the player to chat/cmds for 3 seconds.
pawn Code:
|
public OnPlayerCommandReceived(playerid, cmdtext[])
public OnPlayerCommandPerformed(playerid, cmdtext[], success)
//success is equal to the value returned from the command.
new lastcommand[MAX_PLAYERS];
new lastcommand[MAX_PLAYERS];
public OnPlayerCommandReceived(playerid, cmdtext[]){
if( lastcommand[playerid]!=0 && gettime()-lastcommand[playerid]<3 ){
//This will make sure last command is not 0 (will be 0 if the player hasn't typed a command yet)
//And make sure 3 seconds have NOT passed since the player last typed a command using a UNIX timestamp- see below for details
SendClientMessage(playerid,0xFF0000FF,"You can only type ONE command every THREE seconds!");
return 0;
}
return 1;
}
public OnPlayerCommandPerformed(playerid, cmdtext[], success){
if(success){
lastcommand[playerid]=gettime();
//sets the variable to the current UNIX timestamp- see below for details
}
}
public OnPlayerDisconnect(playerid,reason){
lastcommand[playerid]=0;
//reset the variable so the next player who connects will not experience issues
return 1;
}
public OnPlayerCommandPerformed(playerid, cmdtext[], success){
if(success){
lastcommand[playerid]=gettime();
//sets the variable to the current UNIX timestamp- see below for details
}
}
public OnPlayerCommandPerformed(playerid, cmdtext[], success){
if(success){
lastcommand[playerid]=gettime();
//sets the variable to the current UNIX timestamp- see below for details
}
return 1;//Forgot this!
}
Oh sorry.
Change pawn Code:
pawn Code:
|
new lastcommand[MAX_PLAYERS];
public OnPlayerCommandReceived(playerid, cmdtext[]){
if( lastcommand[playerid]!=0 && gettime()-lastcommand[playerid]<3 ){
//This will make sure last command is not 0 (will be 0 if the player hasn't typed a command yet)
//And make sure 3 seconds have NOT passed since the player last typed a command using a UNIX timestamp- see below for details
SendClientMessage(playerid,0xFF0000FF,"You can only type ONE command every THREE seconds!");
return 0;
}
return 1;
}
public OnPlayerCommandPerformed(playerid, cmdtext[], success){
if(success){
lastcommand[playerid]=gettime();
//sets the variable to the current UNIX timestamp- see below for details
}
return 1;
}
public OnPlayerDisconnect(playerid,reason){
lastcommand[playerid]=0;
//reset the variable so the next player who connects will not experience issues
return 1;
}