[Solved] Multiple optional sscanf parameters
#1

Basically I want the command /gas to work like this.
You can /gas create, which works fine.
Also when you type /gas delete, it will ask you for an ID so it would be /gas delete 1 for example.
However /gas delete [id] is not working

PHP код:
CMD:gas(playeridparams[])
{
    if(
pInfo[playerid][Admin] < 6) return No(playerid);
    new 
item[70];
    new 
stringe[128];
    if(
sscanf(params"s[70]"item)){
        
m(playerid, -1"{A3A1A0}Usage: /gas [operation]");
        
m(playerid, -1"{A3A1A0}Operations: create, delete");
        return 
1;
    }
    if(
strcmp(item"create"truestrlen(item)) == 0)
    {
        
// This works
    
}
    else if(
strcmp(item"delete"truestrlen(item)) == 0)
    {
        new 
id;
        if(
sscanf(params"d"id)) return m(playerid, -1"{A3A1A0}Usage: /gas delete [id]");
        
// this doesnt work
    
}
    return 
1;

Reply
#2

If I remember correctly, you cannot actually do this. I think ****** replied to one of my threads about this same issue basically saying at the time you could do this it was a bug and shouldn't have been possible.
Reply
#3

Try this:

PHP код:
CMD:gas(playeridparams[]) 

    if(
pInfo[playerid][Admin] < 6) return No(playerid); 
    new 
item[10], stringe[128],id
    if(
sscanf(params"s[10]I(-1)"item,id)){ 
        
m(playerid, -1"{A3A1A0}Usage: /gas [operation]"); 
        
m(playerid, -1"{A3A1A0}Operations: create, delete"); 
        return 
1
    } 
    if(!
strcmp(item"create"true)) 
    { 
        
// This works 
    

    else if(!
strcmp(item"delete"true)) 
    { 
        
//Here you can work with id
        
if(id == -1) return m(playerid,-1,"Invalid ID!");
    } 
    return 
1

Reply
#4

It can be done as I seen it on many servers. I will try to find a way
Reply
#5

Quote:
Originally Posted by Kaliber
Посмотреть сообщение
Try this:

PHP код:
CMD:gas(playeridparams[]) 

    if(
pInfo[playerid][Admin] < 6) return No(playerid); 
    new 
item[10], stringe[128],id
    if(
sscanf(params"s[10]I(-1)"item,id)){ 
        
m(playerid, -1"{A3A1A0}Usage: /gas [operation]"); 
        
m(playerid, -1"{A3A1A0}Operations: create, delete"); 
        return 
1
    } 
    if(!
strcmp(item"create"true)) 
    { 
        
// This works 
    

    else if(!
strcmp(item"delete"true)) 
    { 
        
//Here you can work with id
        
if(id == -1) return m(playerid,-1,"Invalid ID!");
    } 
    return 
1

Wow, that worked! Thanks so much, didn't actually think it would be possible
Reply
#6

Believe it or not, but this actually works.

pawn Код:
CMD:gas(playerid, params[])
{
    if(pInfo[playerid][Admin] < 6) return No(playerid);
    if(!strcmp(params, "create", true))
    {
        // Create here...
    }
    else
    {
        new id = -1;
        if(!sscanf(params, "'delete'D(-1)", id))
        {
            if(id == -1) return m(playerid, -1, "{A3A1A0}Usage: /gas delete [id]");
            // Delete here...
        }
        else
        {
            m(playerid, -1, "{A3A1A0}Usage: /gas [operation]");
            m(playerid, -1, "{A3A1A0}Operations: create, delete");
            return 1;
        }
    }
    return 1;
}
Reply
#7

Quote:
Originally Posted by Threshold
Посмотреть сообщение
Believe it or not, but this actually works.
My example is better, because delete is not case sensitive
Reply
#8

Well I wouldn't say "better", but yes, yours works too.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)