sscanf sub-params help
#1

pawn Код:
CMD:house(playerid,params[])
{
    new param1[20];
    if(sscanf(params,"s[20]",param1))
    {
        SendClientMessage(playerid,COLOR_WHITE,"[Usage] /house [command]");
        SendClientMessage(playerid,COLOR_WHITE,"buy, sell, buylock, buyalarm");
        SendClientMessage(playerid,COLOR_WHITE,"setrent, evict, buybls, buycloset");
        if(PlayerInfo[playerid][pAdmin] > 3) { SendClientMessage(playerid,COLOR_WHITE,"create, delete, edit, reload"); }
        return 1;
    }
    if(!strcmp(param1,"buy"))
    {
        if(PlayerInfo[playerid][pHouse] == 999)
            return SendClientMessage(playerid,COLOR_WHITE,"You already own a house.");
        for(new h=0;h<MAX_HOUSES;h++)
        {
            if(!IsPlayerInRangeOfPoint(playerid,2.5,HouseInfo[h][hEntX],HouseInfo[h][hEntY],HouseInfo[h][hEntZ]))
                return SendClientMessage(playerid,COLOR_WHITE,"You're not near any house.");
            if(strcmp(HouseInfo[h][hOwnerName],"None") != 0 || strcmp(HouseInfo[h][hOwnerName],"Admin") != 0)
                return SendClientMessage(playerid,COLOR_WHITE,"That house isn't for sale.");
            if(HouseInfo[h][hPrice] > PlayerInfo[playerid][pCash])
                return SendClientMessage(playerid,COLOR_WHITE,"You don't have enough money.");
            PlayerInfo[playerid][pHouse] = h;
            HouseInfo[h][hOwner] = PlayerInfo[playerid][pID];
            HouseInfo[h][hOwnerName] = GetName(playerid);
            HouseInfo[h][hPrice] = 0;
            HouseInfo[h][hRent] = 100;
        }
    }
    if(!strcmp(param1,"create"))
    {
        new int, price;
        if(PlayerInfo[playerid][pAdmin] < 4)
            return 1;
        if(sscanf(params,"s[20]ii",param1,int,price))
            return SendClientMessage(playerid,COLOR_WHITE,"[Usage] /house create [interior] [price]");
        new query[180];
        new Float:p[3];
        GetPlayerPos(playerid,p[0],p[1],p[2]);
        format(query,sizeof(query),"INSERT INTO `houses` (`ownerid`,`price`,`locked`,`int`,`vw`,`rent`,`entx`,`enty`,`entz`,`extx`,`exty`,`exyz`,`ownername`) VALUES ('9999','999999','0','%i','%i','1','%.1f','%.1f','%.1f','%.1f','%.1f','%.1f','None'",int,random(20),p[0],p[1],p[2],HouseInts[int][0],HouseInts[int][1],HouseInts[int][2]);
        mysql_query(query);
    }
    if(strcmp(param1,"reload") == 0)
    {
        if(PlayerInfo[playerid][pAdmin] < 4)
            return 1;
        for(new i=0; i<MAX_HOUSES; i++)
        {
            LoadHouse(i);
        }
    }
    return 1;
}

I'm trying to make /house create [intid] [price], I tried a lot of methods and played with it but failed and it still does nothing when I /house create, it doesn't tell me to put in the params.

Please help.
Reply
#2

Код:
if(sscanf(params,"is[20]",param1))
Maybe this?
Reply
#3

Quote:
Originally Posted by David (Sabljak)
Посмотреть сообщение
Код:
if(sscanf(params,"is[20]",param1))
Maybe this?
What should I replace with this?
Reply
#4

Quote:
Originally Posted by ******
Посмотреть сообщение
The problem is that when you use "s" as the last parameter, it gets the whole of the remainder of the string - sub-command AND parameters in one. Instead use "s[20] " - the trailing space is VERY important, it used to trick sscanf in to not thinking that "s" was the last parameter, without actually doing anything; it still does that, only now it is a handy and supported feature rather than a trick.

Or try this:

pawn Код:
if (!sscanf(params, "'create'I(-1)I(-1)", int, price))
Combine the "strcmp" and "sscanf" phases in to one (and then check the parameters aren't -1).
Like this?
pawn Код:
if (!sscanf(params, "'create'I(-1)I(-1)", int, price))
    {
        if(PlayerInfo[playerid][pAdmin] < 4)
            return 1;
        if (sscanf(params, "ii",int,price))
            return SendClientMessage(playerid,COLOR_CYAN,"[Usage] /createhouse [int] [price]");
        new query[256];
        new Float:p[3];
        GetPlayerPos(playerid,p[0],p[1],p[2]);
        //INSERT INTO `houses` (`ownerid`,`price`,`locked`,`int`,`vw`,`rent`,`entx`,`enty`,`entz`,`extx`,`exty`,`exyz`,`ownername`) VALUES ('9999','999999','0','1','1','1','12.77777777','12.77777777','12.77777777','12.77777777','12.77777777','12.77777777','None')
        format(query,sizeof(query),"INSERT INTO `houses` (`ownerid`,`price`,`locked`,`int`,`vw`,`rent`,`entx`,`enty`,`entz`,`extx`,`exty`,`extz`,`ownername`) VALUES ('9999','%i','1','%i','%i',1,'%.1f','%.1f','%.1f','%.1f','%.1f','%.1f','None')",price,HInts[int],int*2,p[0],p[1],p[2],HouseInts[int][0],HouseInts[int][1],HouseInts[int][2],GetName(playerid));
        mysql_query(query);
        printf("query:",query);
        SendFormat(playerid,COLOR_GREEN,"[House Creation] {FFFFFF}You have just created a new house (InteriorID: %i | Price: %i",int,price);
    }
I tried but it still doesn't work.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)