Quote:
Originally Posted by Makaveli93
Place this on top of your code
pawn Код:
forward Cooldown(playerid); new bool:UsedChat[MAX_PLAYERS] = false;
Place this on OnPlayerText for example
pawn Код:
if(UsedChat[playerid]) return SendClientMessage(playerid, 0xFFFFFF, "You have used the chat, wait 6 seconds."); UsedChat[playerid] = true; SetTimerEx("Cooldown", 6000, false, "i", playerid);
Place this somewhere in your GM/FS
pawn Код:
public Cooldown(playerid) { UsedChat[playerid] = false; return 1; }
|
There's no need to use timers for that, all you would need is to compare UNIX timestamps, it leads to more functionality, cleaner and more efficient code.
For example:
pawn Код:
new lastChat[MAX_PLAYERS];
public OnPlayerText(playerid, text[])
{
if((gettime() - lastChat[playerid]) <= 6)
{
SendClientMessage(playerid, 0xFFFFFF, "You can only send a message every 6 seconds!");
return 0;
}
lastChat[playerid] = gettime();
return 1;
}
Doesn't that make a lot more sense? No use of timers, no callback created just for the purpose of changing a single variable's value and if you wanted too, you could even tell the player exactly how long they have left to wait before they can send a message again.
Using timers for limiting things like commands/text or anything along those lines is silly!
Finally, as for a "sophisticated" way of detecting IPs, URLs or other stuff you don't want people posting in your chat, then you should make use of the
Regular Expression plugin and create regular expressions to accurately detect what you want to block.