sscanf command problem
#1

Hey, I'm experiencing some problems with my /v [other thing] command using sccanf.
So ofcourse the reason I'm here is that I'm seeking help with it.

Code:
pawn Код:
dcmd_v(playerid, params[])
{
    new choice[20];
    if(sscanf(params,"s[20]",choice))
    {
        SendClientMessage(playerid,COLOR_YELLOW,"Usage: /v [action]");
        SendClientMessage(playerid,COLOR_YELLOW,"Actions: buy - get");
        return 1;
    }
    else
    {
        if(equal(params,"buy"))
        {
            new id;
            if(sscanf(params,"s[20]i",choice,id)) return SendClientMessage(playerid,COLOR_YELLOW,"Usage: /v buy [modelid] to get more information");
            else
            {
//Taken this out for it to look more smooth
            }
        }
        else if(equal(params,"get"))
        {
            new id;
            if(sscanf(params,"s[20]i",choice,id)) return SendClientMessage(playerid,COLOR_YELLOW,"Usage: /v get [1-3]");
            else
            {
             //Taken this out for it to look more smooth
            }
        }
    }
    return 1;
}
Okay so what the problem is that, /v works, /v buy shows the return sendclientmessage, but if I do the /v buy and a modelid so for example

/v buy 401

It does nothing.

Exactly the same for /v get
works with /v get shows the return, but if I do /v get 1 it doesn't do the thing it's supposed to do

It can't be the code inside any of them as far as I know, it worked when I only had /v buy but today I started scripting the /v get and that's when it happen that I had to change everything and now I've come across this which I'm unable to fix myself.
Reply
#2

Try using silent strings. After all, you already know the 'choice':
pawn Код:
if(sscanf(params, "{s[20]}i", id)) return blabla();
Reply
#3

Didn't do it sadly But thanks for trying man! Appreciate it.
Reply
#4

As I know s can't be before i, d, u. so, try

if( sscanf( params, "is[20]", id, choice ) )
Reply
#5

Nope didn't do it either, tho thanks for trying.
Reply
#6

Try, (Not sure)
pawn Код:
if(sscanf(params,"dd",choice,id))
Reply
#7

if(equal(params,"buy"))
else if(equal(params,"get"))

to

if(equal(choice, "buy))
else if(equal(choice,"get"))

?
Reply
#8

Quote:
Originally Posted by Gh0sT_
Посмотреть сообщение
As I know s can't be before i, d, u. so, try

if( sscanf( params, "is[20]", id, choice ) )
There is nothing anywhere that says that.
Reply
#9

Quote:
Originally Posted by Chιrι
Посмотреть сообщение
if(equal(params,"buy"))
else if(equal(params,"get"))

to

if(equal(choice, "buy))
else if(equal(choice,"get"))

?
Already attempted that myself
Reply
#10

Well think about what you're comparing for a second, look at this:

pawn Код:
if(equal(params,"buy"))
So you type "/v buy", then obviously params and buy match, so that if statement returns true, then it continues down into your sscanf check and sscanf says there's no second integer parameter, and it returns the message. So then you type "/v buy 50", then it goes to compare params and "buy" again, and it's no longer going to return true, because now params contains "buy 50".

So what can you do? Well actually you pretty much already have it solved, you just need to change one little thing:

pawn Код:
if(equal(choice,"buy"))
Hope that explains it and helps.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)