[Include] [INC] zcmd 0.3.1 | Fast & Simple Command Processor (updated 30/10/2009)
#21

Wait
is it like zcmd
Reply
#22

Hey.

I'm thinking about moving from dcmd to zcmd, but I have one problem.

My current OnPlayerCommandText looks like this:
pawn Code:
public OnPlayerCommandText(playerid, cmdtext[])
{
    if(IsPlayerConnected(playerid) && gPlayerLogged[playerid] == 1)
    {
        ...
        dcmd(bla,3,cmdtext);
        ...
    }
    else
    {
        SendClientMessage(playerid,COLOR_RED,"[INFO:] Your not logged in, therefore you can not use any commands.");
        SendClientMessage(playerid,COLOR_RED,"[INFO:] Type your password to register/login.");
        return 1;
    }
    return 0;
}
I want to keep that checks, so I use method from note #1 about manually calling ZCMD_ProcessCommand. I did that and made test command /lol. When I came IG and used /lol it did what it was supposed to do, but on the end it returned 0 (SERVER: Unknown command).

pawn Code:
zcmd(lol,playerid,params[])
{
   #pragma unused params
   SendClientMessage(playerid,COLOR_WHITE,"It works");
   return 1;
}
I deleted manual calling ZCMD_ProcessCommand and left my default OnPlayerCommandText and everything worked fine (checks from OnPlayerCommandText were called and it didn't returned 0 on the end). I don't know if this is the best solution, so I would like to use that with manual calling more likely.

So what am I doing wrong here?
Reply
#23

Hi
If you want manually call ZCMD_ProcessCommand
pawn Code:
#define ZCMD_NO_CALLBACK

#include <zcmd>

public OnPlayerCommandText(playerid, cmdtext[])
{
    if (IsPlayerConnected(playerid) && gPlayerLogged[playerid] == 1)
    {
        return ZCMD_ProcessCommand(playerid, cmdtext);
    }
    SendClientMessage(playerid,COLOR_RED,"[INFO:] Your not logged in, therefore you can not use any commands.");
    SendClientMessage(playerid,COLOR_RED,"[INFO:] Type your password to register/login.");
    return 1;
}
but if you don't:
pawn Code:
#include <zcmd>


public OnPlayerCommandText(playerid, cmdtext[])
{
    if (!IsPlayerConnected(playerid) || gPlayerLogged[playerid] != 1)
    {
        SendClientMessage(playerid,COLOR_RED,"[INFO:] Your not logged in, therefore you can not use any commands.");
        SendClientMessage(playerid,COLOR_RED,"[INFO:] Type your password to register/login.");
        return 1;
    }
    return 0;
}
Reply
#24

Ah what a stupid mistake.
In first post it only says
Code:
  ...
  ZCMD_ProcessCommand(playerid, cmdtext);
  ...
so I didn't think about returning that

But second solution seems simplier, so I will be using that one.

Thanks for help.

----------------------------------------------
I'd like to make that for example when you type /l and /local it does the same thing. With dcmd I did like this:
pawn Code:
dcmd_l(playerid, params[])
{
    return dcmd_local(playerid, params);
}
If I try to do this with zcmd I get errors like:
Quote:

...(5560) : error 029: invalid expression, assumed zero
...(5560) : error 029: invalid expression, assumed zero
...(5561) : warning 209: function "zcmd_local" should return a value

What's the right way of doing that with zcmd?
Reply
#25

Do you have return 1; at the end of zcmd_local(...) ?
Reply
#26

All my commands end with 'return 1;'.

-----------------------------
Fixed it.

I had like this:
pawn Code:
zcmd(l,playerid,params[])
{
    return zcmd(local,playerid, params);
}
zcmd(local,playerid,cmdtext[])
{
     ....
     return 1;
}
but I have changed to this and it works:
pawn Code:
zcmd(l,playerid,params[])
{
    return zcmd_local(playerid, params);
}
zcmd(local,playerid,cmdtext[])
{
     ....
     return 1;
}
Reply
#27

A good release. Also it doesn't use strcmp which is bugged.
Reply
#28

Hi guys, i was recommended to try out zcmd, as i'm thinking of converting my commands which use the old and slow version (strcmp).

Only thing is, i don't know fully how to use it, and need some guidance. So far I've added the Include:
pawn Code:
#include <zcmd>
And I've added the function for the command as was given in the example on the first post.

pawn Code:
zcmd(mycommand, playerid, params[])
{
  // Do something
  return 1;
}
Am i correct in saying that the above should not be in the OnPlayerCommandText callback?

Right, now that I have that, how do i make a command with multiple parameters for instance, can someone give me an example of lets say, /givemoney <playerid> <amount> command. I haven't worked with dcmd either which may have helped, and also do i need Sscanf?

Thanks ur help is much appreciated.
Reply
#29

Hi
Quote:
Originally Posted by [B2K
Hustler ]
pawn Code:
zcmd(mycommand, playerid, params[])
{
  // Do something
  return 1;
}
Am i correct in saying that the above should not be in the OnPlayerCommandText callback?
Yes, it should be declared as separate function.
Quote:
Originally Posted by [B2K
Hustler ]
Right, now that I have that, how do i make a command with multiple parameters for instance, can someone give me an example of lets say, /givemoney <playerid> <amount> command. I haven't worked with dcmd either which may have helped, and also do i need Sscanf?
and yes, if you want create a command with multiple parameters it's recommended to use sscanf.

With zcmd and sscanf /givemoney will look like:
pawn Code:
#include <zcmd>
#include <sscanf>

zcmd(givemoney, byplayerid, params[]) // btw, it doesn't matter how last 2 parameters are named
{
    new
      playerid,
      money;
    if (!sscanf(params, "ii", playerid, money)) // sscanf returns 0 on success
    {
      new
        message[50];
      GivePlayerMoney(playerid, money);
      format(message, sizeof(message), "You got $%d from %s", money, ReturnPlayerName(byplayerid));
      SendClientMessage(playerid, 0x00FF00FF, message);
      format(message, sizeof(message), "You gave $%d to %s", money, ReturnPlayerName(playerid));
      SendClientMessage(byplayerid, 0xFFFF00FF, message);
    }
    else SendClientMessage(byplayerid, 0xFFFFFFFF, "Usage: /givemoney <playerid> <amount>");
    return 1;
}
I used ReturnPlayerName in this example which is not native but very useful, if you want use it you may take it here
Reply
#30

Thanks Zeex, I have a question what is the parameter format for this line?
pawn Код:
zcmd(givemoney, byplayerid, params[]) // btw it doesn't matter how last 2 parameters are named
I know it is:
pawn Код:
zcmd(commandname, what is this, params[]) // btw it doesn't matter how last 2 parameters are named
Does "byplayerid" have the same effect as
pawn Код:
new byplayerid; //?
and what do you mean that it doesn't matter how last 2 parameters are named?

Might be a stupid question.

Also, does the else statement execute if either parameters are not completed, or just the first one, and does it show this message if the format is incoorect, for instance if i type /givemoney 21 hello?

pawn Код:
else SendClientMessage(byplayerid, 0xFFFFFFFF, "Usage: /givemoney <playerid> <amount>");
Thanks.
Reply
#31

Quote:
Originally Posted by [B2K
Hustler ]
I know it is:
pawn Код:
zcmd(commandname, what is this, params[]) // btw it doesn't matter how last 2 parameters are named
Does "byplayerid" have the same effect as
pawn Код:
new byplayerid; //?
The second parameter of zcmd(...) macros is ID of the player who type that command
(it may be called as "playerid", "byplayerid" , etc. but I prefer to call it "byplayerid" since many commands have <playerid> parameter and I don't want to think new name every time like "banplayer" or "toplayerid" and so on )

Quote:
Originally Posted by [B2K
Hustler ]
Also, does the else statement execute if either parameters are not completed, or just the first one, and does it show this message if the format is incoorect, for instance if i type /givemoney 21 hello?
pawn Код:
else SendClientMessage(byplayerid, 0xFFFFFFFF, "Usage: /givemoney <playerid> <amount>");
Yes, that message will be shown in all cases you listed.
Reply
#32

Never thinked using callxx to check whether the cmd/func existed oe not before, well done ZeeX.
I'm planing to use it.
Reply
#33

Good job on this, I'm planning on using it.
Reply
#34

Thanks I was just about to redo my admin system with dcmd but after seeing the speed results its zcmd all the way. Nice work.
Reply
#35

very nice job
this is really helpful for newbies and noobs
Reply
#36

Quote:
Originally Posted by Dabombber
Quote:
Originally Posted by Doktor
How is something like this possible in zcmd? Do i have to use CallLocalFunction?
pawn Код:
zcmd(longcommand, playerid, params[])
{
    // ...
}

zcmd(shortcommand, playerid, params[])
{
    return zcmd_longcommand(shortcommand, playerid, params);
}
Quote:
Originally Posted by Doktor
And the Compiler outputs...
Maybe include zcmd?


Somewhat releated, what about using
pawn Код:
#define zcmd:%1(%2,%3)       \
            forward zcmd_%1(%2, %3); \
            public zcmd_%1(%2, %3)
instead (or as well as). That way if zcmd isn't included you get a bunch of unused function warnings which is more relevant than a differing prototype, and more importantly it doesn't ugly up the function list in notepad++ :P.
And what about if i want to call a Command from somewhere else? So What cann i do instead of
Код:
dcmd_callthiscommand(playerid, params);
I inlcluded zcmd. I think the problem is related because i use the commands like
Код:
zcmd(phone, playerid, params[])
instead of using it like
Код:
zcmd(phone, playerid, params)
But i need the [], as i said above, because i need to use strtok in some commands. Or is there any other way?
Reply
#37

Ah sorry, copy/paste bug there, what I meant was

pawn Код:
zcmd(shortcommand, playerid, params[])
{
    return zcmd_longcommand(playerid, params);
}
pawn Код:
dcmd_callthiscommand(playerid, params);
for zcmd would be
pawn Код:
zcmd_callthiscommand(playerid, params);
For your other problem,
pawn Код:
zcmd(phone, playerid, params[])
is the correct way to do it, maybe you're trying to use both?
Reply
#38

Can you explain how I can return my own Unknown command message? while having the commands in a separate function though.
Reply
#39

Quote:
Originally Posted by |№іі7
Can you explain how I can return my own Unknown command message? while having the commands in a separate function though.
Simply define ZCMD_NO_CALLBACK above include line and then edit OPCT code:
pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
  if (!ZCMD_ProcessCommand(playerid, cmdtext))
  {
    SendClientMessage(playerid, 0xFF0000FF, "Unknown command");
  }
  return 1;
}
Reply
#40

I don't really like macros with function names in the brackets as it makes them look like parameters, which can be confusing, however until recently I didn't have a better solution, but I do now so if people want:

pawn Код:
#define ZCMD:%1(%2) forward zcmd_%1(%2);public zcmd_%1(%2)
Then you just do:

pawn Код:
ZCMD:ban(playerid, cmdtext[])
{
    // Code goes here
}
Obviously the current method works perfectly fine, I just prefer this method as I think it looks nicer and it's more explicit as to what's going on and what are parameters and what is the function name.
Reply


Forum Jump:


Users browsing this thread: 12 Guest(s)