SA-MP Forums Archive
SSCANF Issue - Still un-resolved (+ rep) - 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 Issue - Still un-resolved (+ rep) (/showthread.php?tid=314672)



SSCANF Issue - Still un-resolved (+ rep) - Dokins - 30.01.2012

Alright, Basically, this doesnt work, it wont return the SSCANF under "money". It should IN THEORY work.

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]",function)) return SendClientMessage(playerid, COLOUR_GREY, "Usage: /housestore [function] - Functions: Money, Weed, Cocaine.");

    else if(strcmp(function, "money", true))
    {
        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;
}

Please correct the code as appropriate. I'll + rep if it is fixed.


Re: SSCANF Issue - Still un-resolved (+ rep) - MP2 - 30.01.2012

You should do some debugging. Also, 'return' after sscanf stop the code - there's no need for an 'else'.


Re: SSCANF Issue - Still un-resolved (+ rep) - [HiC]TheKiller - 30.01.2012

If a string equals another string, strcmp will return 0. This wouldn't work anyway as your checking if the function is "money" then you're trying to also get a numerical value out of that string which just isn't there. You should be doing it more like 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 amount, string[128],function[16], sum;
    new houseid = GetPlayerHouseID(playerid);
    if(sscanf(params, "s[16]d",function, amount)) return SendClientMessage(playerid, COLOUR_GREY, "Usage: /housestore [function] [amount]- Functions: Money, Weed, Cocaine.");

    if(!strcmp(function, "money", true))
    {
        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);
        }
    }
    else if(!strcmp(function, "weed", true))
    {
        //If they store weed...
    }  
    else if(!strcmp(function, "cocaine", true))
    {
        //If they store cocaine...
    }
    else
    {
        //If the function did not match any of those strings...
    }  
    return 1;
}