Multiple sscanf lines in one command
#1

PHP код:
        new string[200], tstring[30], cstring[360];
    if(
WorkingTruck[playerid] == false) return SCM(playeridCOLOR_LIGHTRED"You are not working.");
    new 
choice[50];
    new 
choice2;
    if(
sscanf(params,"s[50]"choice)) return SCM(playeridCOLOR_GREY,"[Usage:] /trucker [order/info/orders/take_order/deliver/place/cancel].");
{
if(
strcmp(choice"take_order"true) == 0)
    {
        if(
sscanf(params"i"choice2)) return SendClientMessage(playeridCOLOR_LIGHTRED"USAGE: /trucker take_order [page]");//THIS LINE        
        
if(choice2 == -1) return SendClientMessage(playeridCOLOR_LIGHTRED"/trucker take_order [page]");
        if(
Delivering[playerid] == true) return SCM(playeridCOLOR_LIGHTRED"You're in the middle of a delivery");
        if(
IsBizDelivering[playerid] == true) return SCM(playeridCOLOR_LIGHTRED"You're in the middle of a business delivery");
        
        new 
id choice2;
        if(
id && id 6)
        {
            new 
border[50];
            
format(bordersizeof(border), order[id][business_order]);
            new 
ostring[50];
            if(
strcmp(border"Weaponry Stocks"true))
            {
                
productneeded[playerid] = 11;
                
format(ostringsizeof(ostring), "Weaponry Stocks");
            }
            if(
strcmp(border"Vehicle Supplies"true))
            {
                
productneeded[playerid] = 12;
                
format(ostringsizeof(ostring), "Vehicle Supplies");
            }
            if(
strcmp(border"Furniture Parts"true))
            {
                
productneeded[playerid] = 13;
                
format(ostringsizeof(ostring), "Furniture Parts");
            }
            if(
strcmp(border"Grocery Products"true))
            {
                
productneeded[playerid] = 14;
                
format(ostringsizeof(ostring), "Grocery Products");
            }
            for(new 
i=0i<17i++)
            {
                if(
IsPlayerInRangeOfPoint(playerid7.0TruckingZones[i][Factory_Area][0], TruckingZones[i][Factory_Area][1], TruckingZones[i][Factory_Area][2]))
                {
                    for(new 
c=1c<14c++)
                    {
                        if(
TruckingZones[i][Factory_Type] == c)
                        {
                            
cargotype[playerid] = c;
                        }
                    }
                }
            }
            
format(stringsizeof(string), "You have took the order of %s with the certain product: %s"order[id][business_name], ostring);
            
SendClientMessage(playeridCOLOR_ORANGEstring);
            
format(stringsizeof(string), "Deliver the products to %s"order[id][business_location]);
            
SendClientMessage(playeridCOLOR_ORANGEstring);
            
strdel(order[id][business_name], 050);
            
strdel(order[id][business_location], 040);
            
strdel(order[id][business_order], 030);
            
strdel(order[id][business_type], 030);
            
order[id][business_id] = 0;
            
Delivering[playerid] = false;
            
IsBizDelivering[playerid] = true;
        } 
Results to a
Код:
sscanf warning: No default value found.
EDIT: As you can see, 2 sscanf lines are used
PHP код:
if(sscanf(params,"s[50]"choice)) return SCM(playeridCOLOR_GREY,"[Usage:] /trucker [order/info/orders/take_order/deliver/place/cancel].");
{
if(
strcmp(choice"take_order"true) == 0)
    {
        if(
sscanf(params"i"choice2)) return SendClientMessage(playeridCOLOR_LIGHTRED"USAGE: /trucker take_order [page]");//THIS LINE 
Reply
#2

You're checking if the parameter is a string and in the next sscanf line you're checking if it's an integer. It can't be string and integer at the same time.

Use optional parameters

Код:
if(sscanf(params,"s[50]I(-1)", choice,choice2)
Now the second parameter (integer) is optional
If a person uses take order but doesn't give a value for choice2​ , it defaults to -1.
However if they choose a valid number the remaining codes are executed.

Also remove the second sscanf line.
Reply
#3

Got it to work, thanks!
Reply
#4

Quote:
Originally Posted by DavidBilla
Посмотреть сообщение
You're checking if the parameter is a string and in the next sscanf line you're checking if it's an integer. It can't be string and integer at the same time.

Use optional parameters

Код:
if(sscanf(params,"s[50]I(-1)", choice,choice2)
Now the second parameter (integer) is optional
If a person uses take order but doesn't give a value for choice2​ , it defaults to -1.
However if they choose a valid number the remaining codes are executed.

Also remove the second sscanf line.
A horrible way to create a command that has arguments which vary. What you should do is use params to check for the first argument (the option), then use sscanf with {s[5]}{s[6]}i if equal to "take order" then your command can be /cmd take order (number).

Ez pz lemon sqz
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)