How can i do this?
#1

How can i use sscanf in this:

pawn Код:
CMD:test(playerid, params[])
{
if(strcmp(params, "test1", true) == 0)
{
return 1;
}
return SendClientMessage(playerid, COLOR_RED, "Usage: /test [option]");
}
I tried:

pawn Код:
CMD:test(playerid, params[])
{
if(strcmp(params, "test1", true) == 0)
{
if(sscanf(params, "i", test) return SendClientMessage(playerid, COLOR_RED, "Usage: /test test1 [seconds]");
return 1;
}
return SendClientMessage(playerid, COLOR_RED, "Usage: /test [option]");
}
When i type /test test1
It shows that usage
But when i type /test test1 5

It shows the Usage: /test [option]

How would i do it properly?
Reply
#2

pawn Код:
tmpstr[16];
sscanf(params, "s ", tmpstr);
if(!strcmp(tmpstr, "test", true))
{
  new value;
  if(sscanf(params[strlen(tmpstr)], "d", value)) return SendClientMessage(playerid, COLOR_RED, "Usage: /cmd test [seconds]");
  ...
}
else if(!strcmp(tmpstr, "test2", true) || !strcmp(tmpstr, "t2", true))
{
  new value;
  if(sscanf(params[strlen(tmpstr)], "d", value)) return SendClientMessage(playerid, COLOR_RED, "Usage: /cmd test2 [seconds]");
  ...
}
else return SendClientMessage(playerid, COLOR_RED, "Usage: /cmd [test/test2]");
It works with the non-plugin version of sscanf.. I dont know if it works with the plugin version.
Reply
#3

Quote:
Originally Posted by Mастерминд
pawn Код:
tmpstr[16];
sscanf(params, "s ", tmpstr);
if(!strcmp(tmpstr, "test", true))
{
  new value;
  if(sscanf(params[strlen(tmpstr)], "d", value)) return SendClientMessage(playerid, COLOR_RED, "Usage: /cmd test [seconds]");
  ...
}
else if(!strcmp(tmpstr, "test2", true) || !strcmp(tmpstr, "t2", true))
{
  new value;
  if(sscanf(params[strlen(tmpstr)], "d", value)) return SendClientMessage(playerid, COLOR_RED, "Usage: /cmd test2 [seconds]");
  ...
}
else return SendClientMessage(playerid, COLOR_RED, "Usage: /cmd [test/test2]");
It works with the non-plugin version of sscanf.. I dont know if it works with the plugin version.
Is there any other way?
Reply
#4

Quote:
Originally Posted by Joe Torran C
Is there any other way?
Yes, something like this is five times faster than sscanf:
pawn Код:
if(isnull(params)) return Message("Usage: /test [option]");
new tmp[32], idx, len = strlen(params);
while(params[idx] > ' ' && idx < len) idx++;
format(tmp, sizeof(tmp), "%.*s", idx, params);
if(!strcmp(tmp, "test", true))
{
  ...
}
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)