SA-MP Forums Archive
SSCANF error, command won't work correctly. - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: SSCANF error, command won't work correctly. (/showthread.php?tid=409216)



SSCANF error, command won't work correctly. - iGetty - 20.01.2013

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.


Re: SSCANF error, command won't work correctly. - Red_Dragon. - 20.01.2013

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


Re: SSCANF error, command won't work correctly. - iGetty - 20.01.2013

Yes, I do.


Re: SSCANF error, command won't work correctly. - Roach_ - 20.01.2013

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