SA-MP Forums Archive
sscanf setting param to 114 if nothing is entered - 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 setting param to 114 if nothing is entered (/showthread.php?tid=288298)



sscanf setting param to 114 if nothing is entered - Jack_Leslie - 07.10.2011

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.


Re: sscanf setting param to 114 if nothing is entered - aRoach - 07.10.2011

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



Re: sscanf setting param to 114 if nothing is entered - Jack_Leslie - 07.10.2011

where would I put that aRoach?


Re: sscanf setting param to 114 if nothing is entered - aRoach - 07.10.2011

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

Give us the Code...


Re: sscanf setting param to 114 if nothing is entered - Jack_Leslie - 07.10.2011

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



Re: sscanf setting param to 114 if nothing is entered - aRoach - 07.10.2011

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...


Re: sscanf setting param to 114 if nothing is entered - Jack_Leslie - 07.10.2011

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


Re: sscanf setting param to 114 if nothing is entered - wups - 07.10.2011

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



Re: sscanf setting param to 114 if nothing is entered - aRoach - 07.10.2011

It works ?


Re: sscanf setting param to 114 if nothing is entered - Jack_Leslie - 07.10.2011

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