SA-MP Forums Archive
Help command with categories. - 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)
+--- Thread: Help command with categories. (/showthread.php?tid=560493)



Help command with categories. - xX4m4zingXx - 28.01.2015

I want to create a help command with different categories.
If you type help without params it says the categories.
If you type help with any of the params it will say all commands for that category.
I tried something, but it didn't work.
pawn Код:
CMD:help(playerid, params[])
{
    if (isnull(params))
    {
    SendClientMessage(playerid, COL_LIGHTBLUE, ".:| Help |:.");
    SendClientMessage(playerid, COL_ORANGE, "How to use: /Help [NAME]");
    SendClientMessage(playerid, COL_ORANGE, "General|Vehicle|Player|Properties");
    SendClientMessage(playerid, COL_LIGHTBLUE, ".:| Help |:.");
    }
   
    else if (params == "general")
    {
        SendClientMessage(playerid, COL_LIGHTBLUE, ".:| General help |:.");
        SendClientMessage(playerid, COL_ORANGE, "Helpme");
        SendClientMessage(playerid, COL_LIGHTBLUE, ".:| General help |:.");
    }
    return 1;
}
When I type /help general, then the SendClientMessage messages doesn't show up, but it doesn't say that the command isn't recognized.


Re: Help command with categories. - HazardouS - 28.01.2015

You should use sscanf plugin with your ZCMD commands to delimitate parameters easier.
https://sampforum.blast.hk/showthread.php?tid=120356

The first parameter is stored in params[0], the second one is stored in params[1] and so on. Also, you should use "strcmp", not "==".
pawn Код:
if(strcmp(params[0], "general", true) == 0) //or !strcmp(params[0], "general", true)
{
    //player typed "/help general"
}



Re: Help command with categories. - xX4m4zingXx - 28.01.2015

Quote:
Originally Posted by HazardouS
Посмотреть сообщение
You should use sscanf plugin with your ZCMD commands to delimitate parameters easier.
https://sampforum.blast.hk/showthread.php?tid=120356

The first parameter is stored in params[0], the second one is stored in params[1] and so on. Also, you should use "strcmp", not "==".
pawn Код:
if(strcmp(params[0], "general", true) == 0) //or !strcmp(params[0], "general", true)
{
    //player typed "/help general"
}
Okay, but how would I do it with sscanf?
I already have sscanf. Sorry for not telling it.


Re: Help command with categories. - xX4m4zingXx - 29.01.2015

Bump


AW: Help command with categories. - Nero_3D - 29.01.2015

you could do it like that
pawn Код:
CMD:help(playerid, params[])
{
    new
        type[32]
    ;
    if (sscanf(params, "s[32]S()[128]", type, params))
    {
        SendClientMessage(playerid, COL_LIGHTBLUE, ".:| Help |:.");
        SendClientMessage(playerid, COL_ORANGE, "How to use: /Help [NAME]");
        SendClientMessage(playerid, COL_ORANGE, "General|Vehicle|Player|Properties");
        SendClientMessage(playerid, COL_LIGHTBLUE, ".:| Help |:.");
    }
    else if (strcmp(type, "general", true) == 0)
    {
        SendClientMessage(playerid, COL_LIGHTBLUE, ".:| General help |:.");
        SendClientMessage(playerid, COL_ORANGE, "Helpme");
        SendClientMessage(playerid, COL_LIGHTBLUE, ".:| General help |:.");
    }
    return 1;
}
That will extract the first word from params and copy it into type
Lets say I think it does, I didn't test that


Re: AW: Help command with categories. - xX4m4zingXx - 29.01.2015

Quote:
Originally Posted by Nero_3D
Посмотреть сообщение
you could do it like that
pawn Код:
CMD:help(playerid, params[])
{
    new
        type[32]
    ;
    if (sscanf(params, "s[32]S()[128]", type, params))
    {
        SendClientMessage(playerid, COL_LIGHTBLUE, ".:| Help |:.");
        SendClientMessage(playerid, COL_ORANGE, "How to use: /Help [NAME]");
        SendClientMessage(playerid, COL_ORANGE, "General|Vehicle|Player|Properties");
        SendClientMessage(playerid, COL_LIGHTBLUE, ".:| Help |:.");
    }
    else if (strcmp(type, "general", true) == 0)
    {
        SendClientMessage(playerid, COL_LIGHTBLUE, ".:| General help |:.");
        SendClientMessage(playerid, COL_ORANGE, "Helpme");
        SendClientMessage(playerid, COL_LIGHTBLUE, ".:| General help |:.");
    }
    return 1;
}
That will extract the first word from params and copy it into type
Lets say I think it does, I didn't test that
Can you explain this line
pawn Код:
if (sscanf(params, "s[32]S()[128]", type, params))
fully?


AW: Re: AW: Help command with categories. - Nero_3D - 29.01.2015

Quote:
Originally Posted by xX4m4zingXx
Посмотреть сообщение
Can you explain this line
pawn Код:
if (sscanf(params, "s[32]S()[128]", type, params))
fully?
Short Version:

s[x] is the parameter for a string and x is its maximal size
S(x)[y] is the optinal string, x is the default value and y the maximal size again

Also sscanf splits by default at each space, would be equivalent to "p< >"
And the last parameter (in my case S) takes everything after the last split = rest

Because S is an optinal parameter you don't need it to fulfil the if statment with sscanf

Long Version:

https://github.com/Y-Less/sscanf/wiki


Re: AW: Re: AW: Help command with categories. - xX4m4zingXx - 29.01.2015

Quote:
Originally Posted by Nero_3D
Посмотреть сообщение
Short Version:

s[x] is the parameter for a string and x is its maximal size
S(x)[y] is the optinal string, x is the default value and y the maximal size again

Also sscanf splits by default at each space, would be equivalent to "p< >"
And the last parameter (in my case S) takes everything after the last split = rest

Because S is an optinal parameter you don't need it to fulfil the if statment with sscanf

Long Version:

https://github.com/Y-Less/sscanf/wiki
And I just use strcmp for the different types(types are the categories, right?)?


Re: Help command with categories. - Sime30 - 29.01.2015

Yeah