Question help: Chat - Solved -
Speed++ - 28.06.2012
how to limit the messages in the chat?
for example, only 6 seconds send a message.
if the player sends the message immediately.. return 0 in the chat..
Re: Question help: Chat -
Makaveli93 - 28.06.2012
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;
}
Re: Question help: Chat -
Speed++ - 28.06.2012
Thanks, and how to create a sophisticated,
Anti spam url, ip...
look this:
http://en.wikipedia.org/wiki/List_of...-level_domains
Re: Question help: Chat -
Makaveli93 - 28.06.2012
Not sure, but this can help you:
https://sampwiki.blast.hk/wiki/Strfind
Re: Question help: Chat -
Speed++ - 28.06.2012
Quote:
Originally Posted by Makaveli93
|
yes is a very very simple.. but not better
Re: Question help: Chat -
JaTochNietDan - 28.06.2012
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.
Re: Question help: Chat -
Speed++ - 28.06.2012
Quote:
Originally Posted by JaTochNietDan
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.
|
Thanks,
Re: Question help: Chat -
Makaveli93 - 28.06.2012
Quote:
Originally Posted by JaTochNietDan
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.
|
Wow this is nice, didn't knew you can do it so simple. Thanks man