Help regarding /me command
#1

I am using sscanf and zcmd for this. I am trying to make a me commend, everything works fine except the fact that it only allows me to enter about 20-30 characters before cutting it out. Console also displays a warning.

Here is the code, could someone please tell me where I went wrong for future reference and tell me how to fix it:
pawn Код:
COMMAND:me(playerid, params[])
{
    new action[128];
    new name[MAX_PLAYER_NAME];
    GetPlayerName(playerid, name, sizeof(name));
    if(sscanf(params, "ss", action, name))return SendClientMessage(playerid, WHITE, "/me [action]");
    else
    {
        new str[128];
        format(str, sizeof(action), "**%s %s**", name, action);
        SendClientMessage(playerid, PINK, str);
    }
    return 1;
}
Reply
#2

When putting specifier 's' you need to put how much characters it will take next to it. And also, /me command would look something like this:
pawn Код:
if(sscanf(params, "s[64]", action))return SendClientMessage(playerid, WHITE, "/me [action]");
        new str[128];
        format(str, sizeof(action), "**%s %s**", name, action);
        SendClientMessage(playerid, PINK, str);
EDIT: I forgot to add this. You don't need two specifiers in your sscanf because you are just taking text after '/me' and not players name.
Reply
#3

Quote:
Originally Posted by dominik523
Посмотреть сообщение
When putting specifier 's' you need to put how much characters it will take next to it. And also, /me command would look something like this:
pawn Код:
if(sscanf(params, "s[64]", action))return SendClientMessage(playerid, WHITE, "/me [action]");
        new str[128];
        format(str, sizeof(action), "**%s %s**", name, action);
        SendClientMessage(playerid, PINK, str);
EDIT: I forgot to add this. You don't need two specifiers in your sscanf because you are just taking text after '/me' and not players name.
Thanks, also, why did we need to remove the else statement?
Reply
#4

Well, since you are checking if the user entered anything after '/me', if that statement is not true, then he entered something and if it's true, you are sending them message about how to use command and ending the whole command.
Reply
#5

Quote:
Originally Posted by dominik523
Посмотреть сообщение
Well, since you are checking if the user entered anything after '/me', if that statement is not true, then he entered something and if it's true, you are sending them message about how to use command and ending the whole command.
Aha, I get it now, no need for the else statement at all. But one last thing, in my server console I seem to get the warning: "sscanf warning: String buffer overflow." any idea why this is or how to fix this?
Reply
#6

Do NOT use sscanf with a freaking one string specifier.
Use the normal "params" instead...
Reply
#7

Quote:
Originally Posted by Ralfie
Посмотреть сообщение
Do NOT use sscanf with a freaking one string specifier.
Use the normal "params" instead...
Dude, relax, I am new to this. Whats a one string specifier and how do I do this "normal "params" instead"?
Reply
#8

Quote:
Originally Posted by Josh23761
Посмотреть сообщение
Dude, relax, I am new to this. Whats a one string specifier and how do I do this "normal "params" instead"?
With SSCANF:
pawn Код:
CMD:me(playerid, params[])
{
    new string[144], action[128], name[MAX_PLAYER_NAME];
    GetPlayerName(playerid, name, sizeof(name));
    if(sscanf(params, "s[128]", action)) return SendClientMessage(playerid, WHITE, "Usage: /me [action].");
    format(string, sizeof(string), "** %s %s **", name, action);
    SendClientMessage(playerid, PINK, string);
    return 1;
}
Without SSCANF:
pawn Код:
#undef isnull
#define isnull(%1) ((!(%1[0])) || (((%1[0]) == '\1') && (!(%1[1]))))

CMD:me(playerid, params[])
{
    new string[144], name[MAX_PLAYER_NAME];
    GetPlayerName(playerid, name, sizeof(name));
    if(isnull(params)) return SendClientMessage(playerid, WHITE, "Usage: /me [action].");
    format(string, sizeof(string), "** %s %s **", name, action);
    SendClientMessage(playerid, PINK, string);
    return 1;
}
Quote:
Originally Posted by Josh23761
Посмотреть сообщение
Aha, I get it now, no need for the else statement at all. But one last thing, in my server console I seem to get the warning: "sscanf warning: String buffer overflow." any idea why this is or how to fix this?
You get this warning when the string is too small. Use 128 cells, it's the maximum length of characters you can insert in the chatbox.
Reply
#9

Quote:
Originally Posted by Ralfie
Посмотреть сообщение
Do NOT use sscanf with a freaking one string specifier.
Use the normal "params" instead...
What would be the harm in using SSCANF for one sting specifiers anyway?
Reply
#10

Quote:
Originally Posted by Josh23761
Посмотреть сообщение
What would be the harm in using SSCANF for one sting specifiers anyway?
1) No sscanf warnings if string passed limit.
2) Wasting cells / bytes as you don't need to create a new string array.
3) It's also faster as you can just use params.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)