29.09.2011, 08:56
Lorenc_'s solution will be the best, but sscanf is not needed:
strcmp is not designed to comp are if two string completely matches (since it also returns 1 or -1 depends on the string length).
Also, if you do this:
it will always return 0.
You may try my strcmpex function, which don't have such problems, and it is slightly faster in case insensitive checks:
pawn Код:
CMD:anim(playerid, params[])
{
new aStr[32]
// All animations in one command.
if(isnull(params)) return SendClientMessage(playerid, COLOR_WHITE, "USAGE: /anim [animation]");
if (strcmp("rsmg", aStr, true) == 0 || strcmp("rm4", aStr, true) == 0 || strcmp("rak", aStr, true) == 0) OnePlayAnim(playerid, "UZI", "UZI_reload", 4.0, 0, 0, 0, 0, 0);
else if (strcmp("rdeagle", aStr, true) == 0) OnePlayAnim(playerid, "COLT45", "colt45_reload", 4.0, 0, 0, 0, 0, 1);
else if (strcmp("carjacked1", aStr, true) == 0) LoopingAnim(playerid, "PED", "CAR_jackedLHS", 4.0, 0, 1, 1, 1, 0);
else if (strcmp("carjacked2", aStr, true) == 0) LoopingAnim(playerid, "PED", "CAR_jackedRHS", 4.0, 0, 1, 1, 1, 0);
else SendClientMessage(playerid, COLOR_WHITE, "USAGE: /anim [animation]");
return 1;
}
Also, if you do this:
pawn Код:
strcmp("", "asdasd", true)
You may try my strcmpex function, which don't have such problems, and it is slightly faster in case insensitive checks:
pawn Код:
stock strcmpex(const string1[],const string2[],bool:ignorecase = false,length = cellmax)
{
if(!isnull(string1) && !isnull(string2))
{
new len1 = strlen(string1),len2 = strlen(string2);
if(len1 == len2 || length != cellmax)
{
if(length > len1) length = len1;
if(!ignorecase)
{
for(new i = 0;i < length;i++)
if(string1[i] != string2[i]) return 1;
}
else
{
for(new i = 0;i < length;i++)
if(string1[i] != string2[i])
{
switch(string1[i])
{
case 'A'..'Z','a'..'z':
{
switch(string2[i])
{
case 'A'..'Z','a'..'z': if((string1[i] | 0x20) != (string2[i] | 0x20)) return 1;
default: return 1;
}
}
default: return 1;
}
}
}
return 0;
}
}
else if(isnull(string1) && isnull(string2)) return 0;
return 1;
}
#if defined strcmp
#undef strcmp
#endif
#define strcmp strcmpex