SA-MP Forums Archive
Two things about DCMD - 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: Two things about DCMD (/showthread.php?tid=90381)



Two things about DCMD - Sergei - 07.08.2009

Hello

I have decided to check out dcmd and I have got two questions about it.

1. Is it possible to add two commands which do the same thing? Like normally you do:
Код:
if(strcmp(cmd, "/something", true) == 0 || strcmp(cmd, "/somethingelse", true) == 0)
But is i possible to do something like that with dcmd?

2. Another thing is about commands with more than one parameter. For example I would like to do command /give which would have options something and somethingelse and it would affect selected player id (/give [option] [playerid])
Normally you would do something like that:
pawn Код:
if(strcmp(cmd, "/give", true) == 0)
    {
      if(IsPlayerConnected(playerid))
      {
              new x_nr[256];
                    x_nr = strtok(cmdtext, idx);
                    if(!strlen(x_nr)) {
                        SendClientMessage(playerid, COLOR_LIGHTYELLOW2, "[USAGE:] /give [item] [playerid]");
                        SendClientMessage(playerid, COLOR_LIGHTYELLOW2, "[ITEM:] something, somethingelse");
                        return 1;
                    }
                  if(strcmp(x_nr,"something",true) == 0)
                    {
                      tmp = strtok(cmdtext, idx);
                        if(!strlen(tmp)) {
                            SendClientMessage(playerid, COLOR_LIGHTYELLOW2, "[USAGE:] /give something [playerid]");
                            return 1;
                        }
                        giveplayerid = ReturnUser(tmp);
                        if(IsPlayerConnected(giveplayerid))
                        {
// and other stuff
As you can see, when I write only '/give something' it shows me different message as when I write only '/give.' If I use sscanf with dcmd and I write only '/give something' it will still show me the first message until I fill out all the parameters.
So how could I make that when I fill up only one parameter it will already show me the message I choose?

Thanks for help


Re: Two things about DCMD - MadeMan - 07.08.2009

Answer to your first question:

pawn Код:
dcmd_somethingelse(playerid, params[])
{
    return dcmd_something(playerid, params);
}
But I'm not sure what you mean with that other thing.


Re: Two things about DCMD - Sergei - 07.08.2009

Thanks for the first solution

Okay, about second thing.

I would like to make a command '/give'.
When someone types '/give' it will show him client message "/give [option] [playerid]" (options are something and something else). If he types '/give nothing' he will get client message "Wrong option". If he writes '/give something' he will get client message "/give something [playerid]".

Basically I want to set client message for each parameter filled up. If I use sscanf it will always show "/give [option] [playerid]" until all the parameters are filled up and then it will look further for any if's.


Re: Two things about DCMD - MadeMan - 07.08.2009

Well yeah I'm not sure if you can make it with sscanf. You can use dcmd + strtok. Only then it would be strtok(params, idx);


Re: Two things about DCMD - Sergei - 07.08.2009

I will play around that tomorrow then


Re: Two things about DCMD - Ez - 08.08.2009

Код:
dcmd_test(playerid, cmdtext[])
{
  new option[256], index;

  option = strtok(cmdtext, index);

  if (!strcmp(option, "one", true))
  { 
    SendClientMessage(playerid, COLOR, "You typed one!");
  }

 else if (!strcmp(option, "two", true))
 {
   SendClientMessage(playerid, COLOR, "You typed two!");
 }

 return 1;
}
Something like this would work, you'd then just have to use strtok again to get the next peice (id)


Re: Two things about DCMD - ruarai - 08.08.2009

using strtok in dcmd is fail.
Just use scanff



Re: Two things about DCMD - Sergei - 08.08.2009

Quote:
Originally Posted by яυαяαι
using strtok in dcmd is fail.
Just use scanff
As I said, if I use sscanf I need to fill up all the parameters (so it returns 0) to let command execute all the if's (custom things). I'd like to have custom messages for each of the options.