Question help: Chat
#1

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

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;
}
Reply
#3

Thanks, and how to create a sophisticated,

Anti spam url, ip...

look this: http://en.wikipedia.org/wiki/List_of...-level_domains
Reply
#4

Not sure, but this can help you: https://sampwiki.blast.hk/wiki/Strfind
Reply
#5

Quote:
Originally Posted by Makaveli93
Посмотреть сообщение
Not sure, but this can help you: https://sampwiki.blast.hk/wiki/Strfind
yes is a very very simple.. but not better
Reply
#6

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

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,
Reply
#8

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
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)