How can i do this? - 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)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: How can i do this? (
/showthread.php?tid=145220)
How can i do this? -
Torran - 01.05.2010
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?
Re: How can i do this? -
M4S7ERMIND - 01.05.2010
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.
Re: How can i do this? -
Torran - 01.05.2010
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?
Re: How can i do this? -
M4S7ERMIND - 01.05.2010
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))
{
...
}