Help regarding /me command -
Josh23761 - 05.10.2014
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;
}
Re: Help regarding /me command -
dominik523 - 05.10.2014
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.
Re: Help regarding /me command -
Josh23761 - 05.10.2014
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?
Re: Help regarding /me command -
dominik523 - 05.10.2014
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.
Re: Help regarding /me command -
Josh23761 - 05.10.2014
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?
Re: Help regarding /me command -
Evocator - 05.10.2014
Do NOT use sscanf with a freaking one
string specifier.
Use the normal "params" instead...
Re: Help regarding /me command -
Josh23761 - 05.10.2014
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"?
Respuesta: Re: Help regarding /me command -
SickAttack - 05.10.2014
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.
Re: Help regarding /me command -
Josh23761 - 06.10.2014
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?
Re: Help regarding /me command -
Stinged - 06.10.2014
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.