Sscanf
#1

Hi everybody

So the other day I was trying to make a command which checks 2 parameters and then based on the second one it does something.

I wasn't able to successfully perform the command because the code just wasn't able to see the second parameter.

I did something like this:

Код:
CMD:v(playerid, params[])
{
    new cmd[64];
    format(cmd, sizeof(cmd), "%s", params);
    if(!strcmp(cmd, "lock", true, 4)) //I replaced strcmp with strfind and it works normally. That means that sscanf part is fine.
    {
        new id;
        if(sscanf(cmd, " i", id)) return SendCLientMessage(...);//I put a spacing before "i" because that's how sscanf can check for the second word/integer... and not the first one.
        vInfo[id][vDoors] = 1;
        return 1;
    }
    return 1;
}
So when I write in-game /v lock it says Usage: /v lock [ID] but when I put in an ID strcmp doesn't check for the lock command and it doesn't do anything.

Is there a way to do this with strcmp?

I did it with strfind and it works fine but I want to know how to use strcmp the right way...

By what I've read about strcmp my code should be working just fine but it's not.

Btw I shortened the code so you don't have to read a lot.

Thanks in advanced
Reply
#2

pawn Код:
if(sscanf(cmd, "{s[64]}i", id))
https://sampforum.blast.hk/showthread.php?tid=570927 - see "quiet" section.
Reply
#3

That's just an example and other way than Misiur proposed.
PHP код:
CMD:set(playerid, params[]) 
{ 
    new 
        
subcommand[6], 
        
scmd_params[28]; 
    if(
sscanf(params, "s[6]S()[28]", subcommand, scmd_params))  
        return 
SCM(playerid, -1, "/set [money/...]"); 
    if(!
strcmp(subcommand, "money", true)) 
    { 
        new 
targetid, 
            
money; 
        if(
sscanf(scmd_params, "ui", targetid, money))
            return 
SCM(playerid, -1, "/set money [playerid/name] [amount]"); 
        
// Other codes
    
} 
    return 
1; 
} 
Reply
#4

Thanks guys!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)