SSCANF error, command won't work correctly.
#1

Here I have a command, it is '/give' with optional parameters.

The command is: /give [player id or name] [drug/weapon/mats] [amount], but the amount isn't setting upon the "mats" section.

Here is the code:

[pawn]

pawn Код:
command(give, playerid, params[])
{
    new id, section[12], type[12], amount, string[128];
    if(sscanf(params, "us[12]S[12]I(0)", id, section, type, amount))
That's the sscanf line, here is the "mats" section:

pawn Код:
else if(strmatch(section, "mats"))
        {
            if(amount == 0)return SendClientMessage(playerid, GREY, "Usage: /give [player id or name] mats [amount]");
            if(Player[playerid][Materials] >= amount)
            {
                Player[playerid][Materials] -= amount;
                Player[id][Materials] += amount;
                format(string, sizeof(string), "%s has given you %d materials.", MaskName(playerid), amount);
                SendClientMessage(id, SHOUT, string);
                format(string, sizeof(string), "You have given %d materials to %s.", amount, MaskName(id));
                SendClientMessage(playerid, SHOUT, string);
                format(string, sizeof(string), "* %s hands over some materials to %s. *", MaskName(playerid), MaskName(id));
                CloseMessage(playerid, ACTION, string);
            }
            else return SendClientMessage(playerid, GREY, "You don't have that many materials.");
        }
It's not allowing me to change the "amount" parameter, please help.
Reply
#2

Do you have the latest version of sscanf plugin and include ?
Reply
#3

Yes, I do.
Reply
#4

You can't use the "S" parameter in the middle of the function ( SSCANF Language ).. and you don't even use it..
Try this:
pawn Код:
command(give, playerid, params[])
{
    new id, section[12], amount, string[128];
    if(unformat(params, "us[12]I(0)", id, section, amount))
    else if(strmatch(section, "mats"))
    {
        if(amount == 0)return SendClientMessage(playerid, GREY, "Usage: /give [player id or name] mats [amount]");
        if(Player[playerid][Materials] >= amount)
        {
            Player[playerid][Materials] -= amount;
            Player[id][Materials] += amount;
            format(string, sizeof(string), "%s has given you %d materials.", MaskName(playerid), amount);
            SendClientMessage(id, SHOUT, string);
            format(string, sizeof(string), "You have given %d materials to %s.", amount, MaskName(id));
            SendClientMessage(playerid, SHOUT, string);
            format(string, sizeof(string), "* %s hands over some materials to %s. *", MaskName(playerid), MaskName(id));
            CloseMessage(playerid, ACTION, string);
        }
        else return SendClientMessage(playerid, GREY, "You don't have that many materials.");
    }
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)