Sscanf
#1

pawn Код:
if(strcmp(Option, "joinrank", true) == 0)
        {
            if(sscanf(params, "n", RankID))
            {
                if(PlayerInfo[playerid][pRank] >= 2)
                {
                    SendClientMessage(playerid, COLOR_RED, "You're not high enough to set joinrank.");
                    return 1;
                }
                    format(string, sizeof(string), "[FACTION] Join rank is now set too %s.", RankID);
                    SendFactionMessage(faction, COLOR_LIGHTRED, string);
                    DynamicFactions[faction][fJoinRank] = ID;
                    return 1;
            }
        }
I'm learning ZCMD/sscanf, and this part of the code is weird, it winds up setting the join rank to like 65538 or something. When I try setting it to 7, whats wrong?
Reply
#2

While 'n' is number, people will only really be inputting integers, so you may as well change it to 'i'.

Asides from that, to get to the actual problem, 'params' includes EVERYTHING after the command, including the 'joinrank' 'sub-command'. You haven't shown the entire command so I'm not sure what it's meant to be, but for example '/set joinrank <rank>', you're passing the entire 'params' string in to sscanf, which includes the 'joinrank' part of the string.
Reply
#3

Check for 'i' not 'n'
Reply
#4

Код:
new Option2[10];
if(strcmp(Option, "joinrank", true) == 0)
        {
            if(sscanf(Option2, "i", RankID))
            {
                if(PlayerInfo[playerid][pRank] >= 2)
                {
                    SendClientMessage(playerid, COLOR_RED, "You're not high enough to set joinrank.");
                    return 1;
                }
                    DynamicFactions[faction][fJoinRank] = RankID;
                    format(string, sizeof(string), "[FACTION] Join rank is now set too %s.", RankID);
                    SendFactionMessage(faction, COLOR_LIGHTRED, string);
                    return 1;
            }
        }
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)