sscanf problem -
Amator - 24.04.2013
Hello I'd like to know why is this showing me only one word when I do for example /p m Stop now it only show (Megaphone) My_Name says: Stop.
pawn Код:
CMD:p(playerid, params[]) {
new giveSz[32], param[128], param1[128], param2[128], param3[128], playerName[2][MAX_PLAYER_NAME], string[128];
if(sscanf(params,"s[32]S()[128]S()[128]S()[128]S()[128]", giveSz, param, param1, param2, param3)) {
SendClientMessage(playerid, COLOR_GREY, SYNTAX_MESSAGE"/p [Option]");
SendClientMessage(playerid, COLOR_GREY, "Options: m");
return 1;
}
if(strcmp(giveSz, "m", true) == 0) {
if(isnull(param)) return SendClientMessage(playerid, COLOR_GREY, SYNTAX_MESSAGE"/p m [Message]");
GetPlayerName(playerid, szPlayerName, MAX_PLAYER_NAME);
format(string, sizeof(string), "(Megaphone) %s says: %s", param);
nearByMessage(playerid, COLOR_HOTORANGE, string, 50.0);
}
return 1;
}
Thanks.
Re: sscanf problem -
Ballu Miaa - 24.04.2013
You missed szPlayerName while showing the main message. Maybe its cause of that. Try this one.
pawn Код:
CMD:p(playerid, params[]) {
new giveSz[32], param[128], param1[128], param2[128], param3[128], playerName[2][MAX_PLAYER_NAME], string[128];
if(sscanf(params,"s[32]S()[128]S()[128]S()[128]S()[128]", giveSz, param, param1, param2, param3)) {
SendClientMessage(playerid, COLOR_GREY, SYNTAX_MESSAGE"/p [Option]");
SendClientMessage(playerid, COLOR_GREY, "Options: m");
return 1;
}
if(strcmp(giveSz, "m", true) == 0) {
if(isnull(param)) return SendClientMessage(playerid, COLOR_GREY, SYNTAX_MESSAGE"/p m [Message]");
GetPlayerName(playerid, szPlayerName, MAX_PLAYER_NAME);
format(string, sizeof(string), "(Megaphone) %s says: %s",szPlayerName , param);
nearByMessage(playerid, COLOR_HOTORANGE, string, 50.0);
}
return 1;
}
Re: sscanf problem -
Unte99 - 24.04.2013
Also, you should not make a global variable for the name if not necessary.
Re: sscanf problem -
Ballu Miaa - 24.04.2013
Quote:
Originally Posted by ******
Because "S" only reads one word when not at the end.
|
I would like to see his code updated by you. We will get to learn lot of things by that. Thanks ******
Re : Re: sscanf problem -
Amator - 24.04.2013
Thanks, szPlayerName wasn't missing for me, it was a paste error.
Quote:
Originally Posted by ******
Because "S" only reads one word when not at the end.
|
Could explain it a little bit more please?
Re: sscanf problem -
Ballu Miaa - 24.04.2013
So this will be the correct code?
pawn Код:
CMD:p(playerid, params[]) {
new giveSz[32], param[128], param1[128], param2[128], param3[128], playerName[2][MAX_PLAYER_NAME], string[128];
if(sscanf(params,"s[32]s()[128]s()[128]s()[128]s()[128]", giveSz, param, param1, param2, param3)) {
SendClientMessage(playerid, COLOR_GREY, SYNTAX_MESSAGE"/p [Option]");
SendClientMessage(playerid, COLOR_GREY, "Options: m");
return 1;
}
if(strcmp(giveSz, "m", true) == 0) {
if(isnull(param)) return SendClientMessage(playerid, COLOR_GREY, SYNTAX_MESSAGE"/p m [Message]");
GetPlayerName(playerid, szPlayerName, MAX_PLAYER_NAME);
format(string, sizeof(string), "(Megaphone) %s says: %s",szPlayerName , param);
nearByMessage(playerid, COLOR_HOTORANGE, string, 50.0);
}
return 1;
}
Re : sscanf problem -
Amator - 24.04.2013
They have to be optionals because of the other options.
Re : sscanf problem -
Amator - 27.04.2013
Can't find anything on it, can someone help me?
Re: sscanf problem -
Chenko - 27.04.2013
Even if the other strings are optional this code won't work properly. If you write one word and hit space for the next word whatever is after the space goes into the next param variable. Your best bet would be to make separate commands instead of shoving it under /p like you are trying to do.