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 > 2 || slot < 1) return SCM(playerid,-1,"USE: /test1 mats [1-2] 2");
SCM(playerid,-1,"mats OK");
return true;
}
return true;
}
if(slot < 2 || slot > 1)
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;
}
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;
}
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 Код:
pawn Код:
|
if(!strcmp(cmdtext,"/irc",true))
{
new x_nr[256];
x_nr = strtok(cmdtext, idx);
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(cmdtext, idx);
if(!strlen(tmp)) return SCM(playerid,-1,"USE: /test1 mats [1-2] 1");
if(slot > 2 || slot < 1) return SCM(playerid,-1,"USE: /test1 mats [1-2] 2");
SCM(playerid,-1,"mats OK");
return true;
}
return true;
}
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.
|
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(!(1 <= slot <= 5)) return SCM(playerid,-1,"USE: /test1 mats [1-5] 2");
SCM(playerid,-1,"mats");
return true;
}
return true;
}