sscanf problem
#1

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.
Reply
#2

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;
}
Reply
#3

Also, you should not make a global variable for the name if not necessary.
Reply
#4

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 ******
Reply
#5

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?
Reply
#6

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;
}
Reply
#7

They have to be optionals because of the other options.
Reply
#8

Can't find anything on it, can someone help me?
Reply
#9

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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)