sscanf setting param to 114 if nothing is entered
#1

So I have an optional param in my code, using sscanf, it's new amount; and it's an optional param (D). Although, there's a certain point in the code I need it to be entered, but it has to be optional because there's a part before it that I don't need it to be entered, but in the part I need it to be entered, if I don't put any 'amount' then it sets it to 114, but I need to ask if nothing is entered then return blablabla.
Reply
#2

Well :
pawn Код:
if( sscanf( params, "d(114)" amount ) ) return SendClientMessage( ... );
Reply
#3

where would I put that aRoach?
Reply
#4

So what is the command that you want to do this ?

Give us the Code...
Reply
#5

Quote:
Originally Posted by aRoach
Посмотреть сообщение
So what is the command that you want to do this ?

Give us the Code...
pawn Код:
if(strcmp(item, "pot") == 0)
        {
            new pot = CarInfo[car][vPot];
            //if no amount return SendClientMessage(playerid, COLOR_GREY, "* Usuage: /car get pot [amount]");
            if(amount < 0) return SendClientMessage(playerid, COLOR_GREY, "* Usuage: /car get pot [amount]");
            if(amount > pot) return SendClientMessage(playerid, COLOR_GREY, "* Your car does not have that much Pot !");

            CarInfo[car][vPot] -= amount;
            format(string, sizeof(string), "* %s takes out something from his vehicle.", PlayerName(playerid));
            ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);

            PlayerInfo[playerid][pPot] += amount;

            format(string, sizeof(string), "New amount after taking %d pot: %d", amount, CarInfo[car][vPot]);
            SendClientMessage(playerid, COLOR_LIGHTBLUE, string);

            return 1;
        }
Reply
#6

pawn Код:
if(strcmp(item, "pot") == 0)
{
    new pot = CarInfo[car][vPot];
    if( sscanf( item, "i(114)", amount ) ) return amount = 144;
    if(amount < 0) return SendClientMessage(playerid, COLOR_GREY, "* Usuage: /car get pot [amount]");
    if(amount > pot) return SendClientMessage(playerid, COLOR_GREY, "* Your car does not have that much Pot !");

    CarInfo[car][vPot] -= amount;
    format(string, sizeof(string), "* %s takes out something from his vehicle.", PlayerName(playerid));
    ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);

    PlayerInfo[playerid][pPot] += amount;

    format(string, sizeof(string), "New amount after taking %d pot: %d", amount, CarInfo[car][vPot]);
    SendClientMessage(playerid, COLOR_LIGHTBLUE, string);

    return 1;
}
PS: You better use ZCMD/Y_CMD with SSCANF...
Reply
#7

Oh I understand what you mean, put a new if(sscanf(params.. call in the bit where I want it to be needed?
Reply
#8

What the hell..? That was a bad example.
Give us more code, since i don't know where did this come from, and what is the input:
pawn Код:
if(strcmp(item, "pot") == 0)
        {
            new pot = CarInfo[car][vPot];
            //if no amount return SendClientMessage(playerid, COLOR_GREY, "* Usuage: /car get pot [amount]");
            if(amount < 0) return SendClientMessage(playerid, COLOR_GREY, "* Usuage: /car get pot [amount]");
            if(amount > pot) return SendClientMessage(playerid, COLOR_GREY, "* Your car does not have that much Pot !");

            CarInfo[car][vPot] -= amount;
            format(string, sizeof(string), "* %s takes out something from his vehicle.", PlayerName(playerid));
            ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);

            PlayerInfo[playerid][pPot] += amount;

            format(string, sizeof(string), "New amount after taking %d pot: %d", amount, CarInfo[car][vPot]);
            SendClientMessage(playerid, COLOR_LIGHTBLUE, string);

            return 1;
        }
Reply
#9

It works ?
Reply
#10

Quote:
Originally Posted by aRoach
Посмотреть сообщение
It works ?
No.. I don't want it to make the amount 144 like your code does. I want it to ask if there is no amount entered, if there's not, then return this message blablabla... whatever.

Whole command: http://pastebin.com/SyRWrFBY
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)