PDA

View Full Version : sscanf setting param to 114 if nothing is entered


Jack_Leslie
07/10/2011, 09:40 AM
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.

aRoach
07/10/2011, 10:08 AM
Well :
if( sscanf( params, "d(114)" amount ) ) return SendClientMessage( ... );

Jack_Leslie
07/10/2011, 10:11 AM
where would I put that aRoach?

aRoach
07/10/2011, 10:12 AM
So what is the command that you want to do this ?

Give us the Code...

Jack_Leslie
07/10/2011, 10:19 AM
So what is the command that you want to do this ?

Give us the Code...


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_PURPL E,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;
}

aRoach
07/10/2011, 10:22 AM
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_PURPL E,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...

Jack_Leslie
07/10/2011, 10:25 AM
Oh I understand what you mean, put a new if(sscanf(params.. call in the bit where I want it to be needed?

wups
07/10/2011, 10:52 AM
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:

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_PURPL E,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;
}

aRoach
07/10/2011, 10:55 AM
It works ?

Jack_Leslie
07/10/2011, 11:12 AM
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

wups
07/10/2011, 11:25 AM
if(sscanf(params, "s[128]S[128]D(0)", action, item, amount))
if(amount == 0)
{
return ...
}

Jack_Leslie
07/10/2011, 11:29 AM
if(sscanf(params, "s[128]S[128]D(0)", action, item, amount))
if(amount == 0)
{
return ...
}



It worked! Damn, thank you x69(er).