Command not working (maybe sscanf related) -
[p3]pr0t0typ3 - 20.10.2012
Before i start keep in mind i know nearly nothing about sscanf.
I decided to make a help command with categories:
Код:
CMD:help(playerid, params[])
{
new option[5];
if(!sscanf(params, "s", option))
{
if(strcmp(option,"cheat",true) == 0)
{
SendClientMessage(playerid,COLOR_YELLOW, "CHEAT COMMANDS: stuff");
return 1;
}
if(strcmp(option,"fun",true) == 0)
{
SendClientMessage(playerid,COLOR_YELLOW, "FUN COMMANDS: stuff");
return 1;
}
if(strcmp(option,"prop",true) == 0)
{
SendClientMessage(playerid,COLOR_YELLOW, "PROP COMMANDS: stuff");
return 1;
}
if(strcmp(option,"anim",true) == 0)
{
SendClientMessage(playerid,COLOR_YELLOW, "ANIMATION COMMANDS: stuff");
return 1;
}
if(strcmp(option,"helpful",true) == 0)
{
SendClientMessage(playerid,COLOR_YELLOW, "HELPFUL COMMANDS: stuff");
return 1;
}
else return SendClientMessage(playerid, 0xFFFFFFFF, "Invalid Help Function!");
}
else return SendClientMessage(playerid, 0xFFFFFFFF, "Usage: /help [stuff here]");
}
and most of the time it works (except anim and sometimes helpful) but i recently noticed this in the logs whenever someone types the command:
Код:
sscanf warning: Strings without a length are deprecated, please add a destination
Can someone with more experience please help?
Re: Command not working (maybe sscanf related) -
Memoryz - 20.10.2012
Change:
pawn Код:
if(!sscanf(params, "s", option))
to:
pawn Код:
if(!sscanf(params, "s[5]", option))
The [5] represents the size of the array of new option[5];
Re: Command not working (maybe sscanf related) -
[p3]pr0t0typ3 - 21.10.2012
It still doesnt seem to work,/help anim does nothing and /help helpful says it doesnt exist o.O
Re: Command not working (maybe sscanf related) -
newbienoob - 21.10.2012
Try change
if(strcmp(option,"cheat",true) == 0)
to
if(!strcmp(option,"cheat",true)
Re: Command not working (maybe sscanf related) -
[p3]pr0t0typ3 - 21.10.2012
error 001: expected token: ")", but found "{"
Re: Command not working (maybe sscanf related) -
ReneG - 21.10.2012
You don't need sscanf when you're using one parameter, that's exactly what isnull() is for.
PHP код:
CMD:help(playerid, params[])
{
if(isnull(params))
{
return SendClientMessage(playerid, 0xFFFFFFFF, "Usage: /help [stuff here]");
}
if(strcmp(params,"cheat",true) == 0)
{
SendClientMessage(playerid,COLOR_YELLOW, "CHEAT COMMANDS: stuff");
return 1;
}
if(strcmp(params,"fun",true) == 0)
{
SendClientMessage(playerid,COLOR_YELLOW, "FUN COMMANDS: stuff");
return 1;
}
if(strcmp(params,"prop",true) == 0)
{
SendClientMessage(playerid,COLOR_YELLOW, "PROP COMMANDS: stuff");
return 1;
}
if(strcmp(params,"anim",true) == 0)
{
SendClientMessage(playerid,COLOR_YELLOW, "ANIMATION COMMANDS: stuff");
return 1;
}
if(strcmp(params,"helpful",true) == 0)
{
SendClientMessage(playerid,COLOR_YELLOW, "HELPFUL COMMANDS: stuff");
return 1;
}
else
{
SendClientMessage(playerid, 0xFFFFFFFF, "Invalid Help Function!");
}
return 1;
}
Re: Command not working (maybe sscanf related) -
[p3]pr0t0typ3 - 21.10.2012
Thanks to everyone who helped,especially Vincent.
That fixed it (except anim) but i fixed it,apparently the message on it was too long.