Anti-Command text
#1

Hi peoples.I need some help with anti-command text.I want to that when player use any command he can use again after 3 sec.
Reply
#2

pawn Код:
new cSpam[MAX_PLAYERS];
pawn Код:
forward AntiSpam(playerid);
public AntiSpam(playerid)
{
    if(cSpam(playerid) == 1)
    {
        cSpam[playerid] = 0;
    }
    return 1;
}
At the bottom of OnPlayerCommandText put this:

pawn Код:
cSpam[playerid] = 1;
SetTimerEx("AntiSpam", 3000, 0, "i", playerid);
at the top of OnPlayerCommandText put this:

pawn Код:
if(cSpam[playerid] == 1) return SendClientMessage(playerid, color, "Error message here");
Reply
#3

And an example would be?
Reply
#4

Quote:
Originally Posted by ******
Посмотреть сообщение
I'll say this here, like I say it every time someone gives that as a solution to this issue - you're wrong (I've given up being nice on this point). The VASTLY simpler way of doing this is just compare "GetTickCount"s.
Never thought of this! Thank you ******!
Reply
#5

Yes, ****** - example please?
Reply
#6

Quote:
Originally Posted by ******
Посмотреть сообщение
I'll say this here, like I say it every time someone gives that as a solution to this issue - you're wrong (I've given up being nice on this point). The VASTLY simpler way of doing this is just compare "GetTickCount"s.
Try to be calmer .


Well, acording to this article of the SA-MP wiki:


pawn Код:
"GetTickCount will cause problems on servers with uptime of over 24 days (physical server, not SA:MP server) as GetTickCount will eventually warp past the integer size constraints"

A comparison of "gettime"s without arguments :

pawn Код:
gettime()

Should be better than the GetTickCount method, once it is less dangerous .


An example to everybody :


pawn Код:
new x[MAX_PLAYERS]; //A global variable


//In the command:
if(x[playerid] != 0 && x[playerid] < gettime()) return SendClientMessage(playerid, 0xFFFFFFAA, "Wait ! :D");
x[playerid] = gettime()+3;


I hope that i have helped .
Reply
#7

^ Example please?
Reply
#8

Yes i have do that,but problem i don't know where is onplayercommandtext callback? on zcmd+sscanf?
Reply
#9

rjjj, most people restart their servers within 24 days anyway. An example using GetTickCount would be as follows:

pawn Код:
new
    g_iCmdTickCount[MAX_PLAYERS];

public OnPlayerCommandText(playerid, cmdtext[]) {
    if(g_iCmdTickCount[playerid] + 3000 > GetTickCount() && g_iCmdTickCount[playerid] > 0) { // GetTickCount returns the uptime of the actual server in milliseconds. 1 second = 1000 MS.
        SendClientMessage(playerid, 0, "[error message]");
        return 1;
    }
   
    g_iCmdTickCount[playerid] = GetTickCount();
   
    /*  Your commands.... */
    return 1;
}
budelis, you must implement the code inside your OnPlayerCommandReceived callback. If you haven't created a public yet for it, here's the header:

pawn Код:
public OnPlayerCommandReceived(playerid, cmdtext[])
Reply
#10

OnPlayerCommandReceived for ZCMD.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)