SA-MP Forums Archive
Need help with sscanf in cmd - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Need help with sscanf in cmd (/showthread.php?tid=536774)



Need help with sscanf in cmd - Reim - 12.09.2014

Hi all, need help with command.

/test1 drugs - Work
/test1 mats - return SCM(playerid,-1,"USE: /test1 mats [1-2] 1"); (Work)
/test1 mats 1-2 - Doesn't work (message "mats OK" not show)
or if i write instead 1-2: 0 or 3+ this too doesn't work


Can anyone help7

PHP код:
CMD:test1(playerid,params[])
{
    new 
test[10];
    if(
sscanf(params,"s[10]",test)) return SCM(playerid,-1,"USE: /test1");
    if(!
strcmp(test,"drugs",true))
    {
        
SCM(playerid,-1,"drugs OK");
        return 
true;
    }
    else if(!
strcmp(test,"mats",true))
    {
        new 
slot;
        if(
sscanf(params,"{s[10]}d",slot)) return SCM(playerid,-1,"USE: /test1 mats [1-2] 1");
        if(
slot || slot 1) return SCM(playerid,-1,"USE: /test1 mats [1-2] 2");
        
SCM(playerid,-1,"mats OK");
        return 
true;
    }
    return 
true;




Re: Need help with sscanf in cmd - krytans - 12.09.2014

Try
pawn Код:
if(slot < 2 || slot > 1)



Re: Need help with sscanf in cmd - Reim - 12.09.2014

Quote:
Originally Posted by krytans
Посмотреть сообщение
Try
pawn Код:
if(slot < 2 || slot > 1)
this doesn't work


Re: Need help with sscanf in cmd - MikeEd - 12.09.2014

I dont think this code works in any way, i've tried countless solutions and results are the same. So i'd suggest using a different method for this command. you could do something like this

pawn Код:
CMD:test1(playerid,params[])
{
    new item[10];
    if(sscanf(params,"s[10]", item)) return SendClientMessage(playerid, -1, "USE: /test1");
    if(!strcmp(params, "drugs"))
    {
        SendClientMessage(playerid,-1,"drugs OK");
    }
    return 1;
}
pawn Код:
CMD:mats(playerid,params[])
{
    new slot;
    if(sscanf(params,"i", slot)) return SendClientMessage(playerid, -1, "USE: /mats [1-2]");
    if(!strcmp(params, "1"))
    {
        SendClientMessage(playerid,-1,"mats 1 OK");
    }
    if(!strcmp(params, "2"))
    {
        SendClientMessage(playerid,-1,"mats 2 OK");
    }
    return 1;
}



Re: Need help with sscanf in cmd - Reim - 12.09.2014

Quote:
Originally Posted by MikeEd
Посмотреть сообщение
I dont think this code works in any way, i've tried countless solutions and results are the same. So i'd suggest using a different method for this command. you could do something like this

pawn Код:
CMD:test1(playerid,params[])
{
    new item[10];
    if(sscanf(params,"s[10]", item)) return SendClientMessage(playerid, -1, "USE: /test1");
    if(!strcmp(params, "drugs"))
    {
        SendClientMessage(playerid,-1,"drugs OK");
    }
    return 1;
}
pawn Код:
CMD:mats(playerid,params[])
{
    new slot;
    if(sscanf(params,"i", slot)) return SendClientMessage(playerid, -1, "USE: /mats [1-2]");
    if(!strcmp(params, "1"))
    {
        SendClientMessage(playerid,-1,"mats 1 OK");
    }
    if(!strcmp(params, "2"))
    {
        SendClientMessage(playerid,-1,"mats 2 OK");
    }
    return 1;
}
Thank you, but this is not an option

without sscanf it work, but i need with sscanf

PHP код:
if(!strcmp(cmdtext,"/irc",true))

    new 
x_nr[256];
    
x_nr strtok(cmdtextidx);
    if(!
strlen(x_nr)) return SCM(playerid,-1,"USE: /test1"); 
    if(!
strcmp(x_nr,"drugs",true)) 
    { 
        
SCM(playerid,-1,"drugs OK"); 
        return 
true
    } 
    else if(!
strcmp(x_nr,"mats",true)) 
    { 
        
tmp strtok(cmdtextidx);
        if(!
strlen(tmp)) return SCM(playerid,-1,"USE: /test1 mats [1-2] 1"); 
        if(
slot || slot 1) return SCM(playerid,-1,"USE: /test1 mats [1-2] 2"); 
        
SCM(playerid,-1,"mats OK"); 
        return 
true
    } 
    return 
true




Re: Need help with sscanf in cmd - MikeEd - 12.09.2014

I am sorry, but thats the only way i know around it, if you manage to find a solution it'll great for you and me, its always good to learn new stuff... looking forward to someone else's reply


Re: Need help with sscanf in cmd - Reim - 12.09.2014

Quote:
Originally Posted by ******
Посмотреть сообщение
Use "s[10] " not "s[10]", otherwise sscanf will copy the whole of the input in to your "test" variable. Using only "s" in a specifier is completely wrong, and will be a warning in the future.
Thank you!

It work

PHP код:
CMD:test1(playerid,params[])
{
    new 
test[10];
    if(
sscanf(params,"s[10] ",test)) return SCM(playerid,-1,"USE: /test1");
    if(!
strcmp(test,"drugs",true))
    {
        
SCM(playerid,-1,"drugs");
        return 
true;
    }
    else if(!
strcmp(test,"mats",true))
    {
        new 
slot;
        if(
sscanf(params,"{s[10]}d",slot)) return SCM(playerid,-1,"USE: /test1 mats [1-5] 1");
        if(!(
<= slot <= 5)) return SCM(playerid,-1,"USE: /test1 mats [1-5] 2");
        
SCM(playerid,-1,"mats");
        return 
true;
    }
    return 
true;