Invalid Command Lenght: Exceeding 50 characters
#1

I was doing some testing in my gamemode, and this command always worked before.
Now if i type /ooc [somethinglongerthenXchars] it says this in red.

As you can see i'm using ZCMD+sscanf (2.0)

pawn Код:
COMMAND:ooc(playerid,params[])
{
    new string[164];
    if (!sscanf(params,"s[164]",string))
    {
        if(pData[playerid][pMuted] != 1)
        {
            new str[128];
            new log[128];
            new month[12];
            new hh,mm,ss,y,m,d;
            gettime(hh,mm,ss);
            getdate(y,m,d);
            format(month, 12, "%s", Months[m-1]);
            format(str,sizeof(str),"OOC | %s: %s",PlayerName(playerid),string);
            format(log,sizeof(log),"[%s %d, %d, %d:%d:%d] %s: %s\r\n",month,d,y,hh,mm,ss,PlayerName(playerid),string);
            new File:lfile = fopen("TPRP/Logs/OOC-Chat.log",io_append);
            fwrite(lfile,log);
            fclose(lfile);
            SendClientMessageToAll(COLOR_DARKSLATEGRAY,str);
        }
        else return SendClientMessage(playerid,COLOR_RED,"ERROR: You have been muted by Staff.");
    }
    else return SendClientMessage(playerid,-1,"USAGE: /gm [message]");
    return 1;
}
Reply
#2

It can refeer to the callback OnPlayerCommandPerformed.
Reply
#3

There's nothing in there that can cause this. This is from my own script, so i know there's nothing in my script that would cause this error message,
if there isn't anything wrong with my command above, that is.
Reply
#4

Delete the code that you DON'T need.

pawn Код:
COMMAND:ooc(playerid,params[]) {
    if(isnull(params))
        return SendClientMessage(playerid, -1, "USAGE: /gm [message]");
       
    if(pData[playerid][pMuted] != 1) {
        new str[128];
        new log[128];
        new month[12];
        new hh,mm,ss,y,m,d;
        gettime(hh,mm,ss);
        getdate(y,m,d);
        format(month, 12, "%s", Months[m-1]);
        format(str,sizeof(str),"OOC | %s: %s",PlayerName(playerid),params);
        format(log,sizeof(log),"[%s %d, %d, %d:%d:%d] %s: %s\r\n",month,d,y,hh,mm,ss,PlayerName(playerid),params);
        new File:lfile = fopen("TPRP/Logs/OOC-Chat.log",io_append);
        fwrite(lfile,log);
        fclose(lfile);
        SendClientMessageToAll(COLOR_DARKSLATEGRAY,str);
    }
    else return SendClientMessage(playerid,COLOR_RED,"ERROR: You have been muted by Staff.");
    return 1;
}
Reply
#5

Quote:
Originally Posted by Calg00ne
Посмотреть сообщение
Delete the code that you DON'T need.

pawn Код:
COMMAND:ooc(playerid,params[]) {
    if(isnull(params))
        return SendClientMessage(playerid, -1, "USAGE: /gm [message]");
       
    if(pData[playerid][pMuted] != 1) {
        new str[128];
        new log[128];
        new month[12];
        new hh,mm,ss,y,m,d;
        gettime(hh,mm,ss);
        getdate(y,m,d);
        format(month, 12, "%s", Months[m-1]);
        format(str,sizeof(str),"OOC | %s: %s",PlayerName(playerid),params);
        format(log,sizeof(log),"[%s %d, %d, %d:%d:%d] %s: %s\r\n",month,d,y,hh,mm,ss,PlayerName(playerid),params);
        new File:lfile = fopen("TPRP/Logs/OOC-Chat.log",io_append);
        fwrite(lfile,log);
        fclose(lfile);
        SendClientMessageToAll(COLOR_DARKSLATEGRAY,str);
    }
    else return SendClientMessage(playerid,COLOR_RED,"ERROR: You have been muted by Staff.");
    return 1;
}
It's almost the same amount of code, also i have my own style of coding which i suppose everybody has, and i'd not like to change it unless it's causing any problems.

How did my coding cause this message, and how did your edit fix it?
Thanks.
Reply
#6

You don't need to use sscanf to split params when you only need 1 parameter. You can use isnull to confirm there's anything typed after the command and params contains the main string, so you can just use params if you want a string, or you can use strval(params) to convert the params string into an integer.
Reply
#7

Quote:
Originally Posted by Calg00ne
Посмотреть сообщение
You don't need to use sscanf to split params when you only need 1 parameter. You can use isnull to confirm there's anything typed after the command and params contains the main string, so you can just use params if you want a string, or you can use strval(params) to convert the params string into an integer.
Oh, i didn't think about that, will start doing it. So me creating another string and using it instead of params caused this issue?
I can see how i can save memory by not creating new strings and also how it increases the performance on the command.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)