Help please....SSCANF issue.
#1

Alright what happens is.... when i type /housestore it says the first sscanf call "Usage: /housestore [function]"
When I type /housestore money it says /housestore money [amount] when I type the amount it shows the same message!

Can anyone advise me on this?
pawn Code:
CMD:housestore(playerid, params[])
{
    if(LoggedIn[playerid] == 0) return SendClientMessage(playerid, COLOUR_GREY, "You must be logged in to use this command.");

    new cashamount, string[128],function[16], sum;
    new houseid = GetPlayerHouseID(playerid);
    if(sscanf(params, "s[16]D", function, cashamount)) return SendClientMessage(playerid, COLOUR_GREY, "Usage: /housestore [function] Available functions: weapon(coming soon), money");

    if(strcmp(function, "money", true) == 0)
    {
        if(sscanf(function, "d", cashamount)) return SendClientMessage(playerid, COLOUR_GREY, "Usage: /housestore money [amount]");
        if(cashamount < 1 || cashamount > 500000) return SendClientMessage(playerid, COLOUR_GREY, "The amount must be between $0 and $500,000.");
        if(cashamount > PlayerMoney[playerid]) return SendClientMessage(playerid, COLOUR_GREY, "You do not have this much to store.");
        if(HouseOwned[playerid] == houseid)
        {
            printf("House Owned: %d", HouseOwned[playerid]);
            sum = HouseMoney[houseid] += cashamount;
            HouseSQLID[houseid] = MySQL_GetValue(HouseSQLID[houseid], "id", "houses");
            MySQL_SetInteger(HouseSQLID[houseid], "HouseMoney", sum, "houses");
            GivePlayerMoney(playerid, -cashamount);
            printf("Cash amount %d", cashamount);
            format(string, sizeof(string), "You have stored $%d in your house.", cashamount);
            SendClientMessage(playerid, COLOUR_ORANGE, string);
        }

    }
    return 1;
}
Reply
#2

Sure can! Take a look at my /give command as a reference.

pawn Code:
CMD:give(playerid, params[])
{
    new
        user,
        string[128],
        weaponname[32],
        amount,
        Float:Pos[3]
    ;
   
    if(isnull(params))
    {
        SendClientMessage(playerid, COLOR_WHITE, "[AVAILABLE ITEM NAMES]");
       
        //Items
       
        if(GetPlayerCash(playerid) > 0) { SendClientMessage(playerid, COLOR_LIME, "* Money"); }
        if(GetPlayerWeapon(playerid) != 0) { SendClientMessage(playerid, COLOR_LIME, "* Weapon"); }
        if(UserInfo[playerid][Sunglasses] == 1 && UserInfo[playerid][SunglassesType] != 0) { SendClientMessage(playerid, COLOR_LIME, "* Sunglasses"); }

        //Food
       
        if(UserInfo[playerid][Pizza] > 0) { SendClientMessage(playerid, COLOR_LIME, "* Pizza Slice"); }
        if(UserInfo[playerid][Soda] > 0) { SendClientMessage(playerid, COLOR_LIME, "* Soda"); }
        if(UserInfo[playerid][Doughnuts] > 0) { SendClientMessage(playerid, COLOR_LIME, "* Doughnut"); }
       
        //Ammo
       
        if(UserInfo[playerid][ExplosiveAmmo] > 0) { SendClientMessage(playerid, COLOR_LIME, "* ExplosiveAmmo"); }
        if(UserInfo[playerid][TazerDarts] > 0) { SendClientMessage(playerid, COLOR_LIME, "* TazerDart"); }
       
        SendClientMessage(playerid, COLOR_CMD, "Correct Usage: /Give [Item Name] [Player ID] [Amount]");
        return 1;
    }
   
    if(strcmp(params, "money", true, 5) == 0) {
        strdel(params, 0, 5);
       
        if(sscanf(params, "ui", user, amount))
            return SendClientMessage(playerid, COLOR_CMD, "Correct Usage: /Give Money [Player ID] [Amount]");

        new
            name[24],
            uname[24]
        ;

        GetPlayerNameEx(playerid, name, 24);
        GetPlayerNameEx(user, uname, 24);
       
        GetPlayerPos(playerid, Pos[0], Pos[1], Pos[2]);

        if(IsPlayerInRangeOfPoint(user, 5, Pos[0], Pos[1], Pos[2]))
        {
            if(GetPlayerCash(playerid) >= amount)
            {
                if(user == playerid)
                    return SendClientMessage(playerid, COLOR_ERROR, "< You cannot give yourself money!");
                   
                format(string, sizeof(string), "* %s hands %s some money.", name, uname);
                ProxDetector(20.0, playerid, string, COLOR_ACTION, COLOR_ACTION, COLOR_ACTION, COLOR_ACTION, COLOR_ACTION);

                format(string, sizeof(string), "* You have given %s $%d.", uname, amount);
                SendClientMessage(playerid, COLOR_SUCCESSFUL, string);
               
                format(string, sizeof(string), "* %s has given you $%d.", name, amount);
                SendClientMessage(user, COLOR_SUCCESSFUL, string);

                GivePlayerCash(playerid, -amount);
                GivePlayerCash(user, amount);
            }
            else return SendClientMessage(playerid, COLOR_ERROR, "< You do not have enough money!");
        }
        else return SendClientMessage(playerid, COLOR_ERROR, "< You're not close enough to that player!");
    }
   
    else if(strcmp(params, "weapon", true, 6) == 0) {
        strdel(params, 0, 6);
       
        new
            name[24],
            uname[24],
            gunname[42]
        ;
       
        GetPlayerPos(playerid, Pos[0], Pos[1], Pos[2]);
       
        if(sscanf(params, "us[32]", user, weaponname))
            return SendClientMessage(playerid, COLOR_CMD, "Correct Usage: /Give Weapon [Player ID] [Weapon Name]");
       
        if(GetWeaponModelIDFromName(weaponname) == GetPlayerWeapon(playerid))
        {
       
            /*if(user == playerid)
                return SendClientMessage(playerid, COLOR_ERROR, "< You can't give something to yourself!");*/

       
            if(IsPlayerInRangeOfPoint(user, 5, Pos[0], Pos[1], Pos[2]))
            {
                new Ammo;
                if(expAmmo[playerid] == -1)
                {
                        Ammo = GetPlayerAmmo(playerid);
                }
                else
                {
                        Ammo = UserInfo[playerid][w_TempAmmo];
                }
           
                GivePlayerWeapon(user, GetWeaponModelIDFromName(weaponname), Ammo);

                GivePlayerWeapon(playerid, GetWeaponModelIDFromName(weaponname), -Ammo);
                GetWeaponName(GetWeaponModelIDFromName(weaponname), gunname, 42);
               
                GetPlayerNameEx(playerid, name, 24);
                GetPlayerNameEx(user, uname, 24);
               
                format(string, sizeof(string), "* %s hands %s a %s.", name, uname, gunname);
                ProxDetector(20.0, playerid, string, COLOR_ACTION, COLOR_ACTION, COLOR_ACTION, COLOR_ACTION, COLOR_ACTION);
               
                if(UserInfo[playerid][w_TempAmmo] != 0)
                {
                    UserInfo[playerid][w_TempAmmo] = 0;
                    expAmmo[playerid] = -1;
                }
            }
            else return SendClientMessage(playerid, COLOR_ERROR, "< You're not close enough to that player!");
        }
        else return SendClientMessage(playerid, COLOR_ERROR, "< You can't give someone a weapon you don't have!");

    }
    return 1;
}
Reply
#3

pawn Code:
if(sscanf(params, "d",cashamount)) return SendClientMessage(playerid, -1, "Usage: /housestore [amount]");
Reply
#4

I've tried that before... it doesnt appear to work.
Reply
#5

I'm surprised you aren't receiving any messages from sscanf in the server console. First of all, you have an optional specifier in the sscanf line (D), change it to a lower-case letter (d). There's no reason for the optional specifier because they can't do anything without it!

And also, your strcmp line doesn't need to have "== 0" at the end. Just doing this will be fine:

pawn Code:
if(strcmp(function, "money", true))
If you still have problems with sscanf, it may be a good idea to download update 2.5 (or whatever the latest version is) because it works for all versions of SA-MP and doesn't have bugs like the previously released version for 0.3d did!
Reply
#6

I'm sure its an optional one because there are other parameters within the command that could be selected hence why I thought "D" was appropriate (optional integer) It basically returns the client message each time and I've tried an amount of changes to fix it.. I'll update the version.
Reply
#7

From what I can tell, the only "functions" you have are weapons and money, both probably not needing any further parameters
Reply
#8

1) how can sscanf know where the string ends, and where your amount value is? you forgot to provide a default value for the optional integer aswell:
pawn Code:
if(sscanf(params, "s[16]D"
the optional parameter should look like
pawn Code:
if(sscanf(params, "s[16]D(0)"
...but this is supposed to fail aswell, due to the unknown string end. ("money 123" is stored in the same string atm, where the cashamount=0, not scanned at all)

pawn Code:
if(strcmp(function, "money", true) == 0)
function and params contain the same string, you need sscanf to stop at the " " space char - try to experiment with the search function (here with the space)
pawn Code:
if(sscanf(params, "s[5]' 'D(0)"
...maybe parsing the exact stringlenght [5] will work, but the ' ' search is a neat thing ^^

i didnt try (yet, as its default set to) to scan strings with the space delimeter:
pawn Code:
if(sscanf(params, "p< >s[16]D(0)"
Reply
#9

Yeah, that still doesnt work.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)