Command not working (maybe sscanf related)
#1

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?
Reply
#2

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];
Reply
#3

It still doesnt seem to work,/help anim does nothing and /help helpful says it doesnt exist o.O
Reply
#4

Try change
if(strcmp(option,"cheat",true) == 0)
to
if(!strcmp(option,"cheat",true)
Reply
#5

error 001: expected token: ")", but found "{"
Reply
#6

You don't need sscanf when you're using one parameter, that's exactly what isnull() is for.
PHP код:
CMD:help(playeridparams[])
{
    if(
isnull(params)) 
    {
        return 
SendClientMessage(playerid0xFFFFFFFF"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(playerid0xFFFFFFFF"Invalid Help Function!");
    }
    return 
1;

Reply
#7

Thanks to everyone who helped,especially Vincent.

That fixed it (except anim) but i fixed it,apparently the message on it was too long.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)