SA-MP Forums Archive
[Include] [INC] zcmd 0.3.1 | Fast & Simple Command Processor (updated 30/10/2009) - 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: Filterscripts (https://sampforum.blast.hk/forumdisplay.php?fid=17)
+---- Forum: Includes (https://sampforum.blast.hk/forumdisplay.php?fid=83)
+---- Thread: [Include] [INC] zcmd 0.3.1 | Fast & Simple Command Processor (updated 30/10/2009) (/showthread.php?tid=91354)

Pages: 1 2 3 4 5 6


Re: [INC] zcmd - simple command system [updated] - nuriel8833 - 16.08.2009

Wait
is it like zcmd



Re: [INC] zcmd v0.2.2 - Sergei - 27.08.2009

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?


Re: [INC] zcmd v0.2.2 - Zeex - 27.08.2009

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;
}



Re: [INC] zcmd v0.2.2 - Sergei - 27.08.2009

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?


Re: [INC] zcmd v0.2.2 - Zeex - 27.08.2009

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


Re: [INC] zcmd v0.2.2 - Sergei - 27.08.2009

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;
}



Re: [INC] zcmd v0.2.2 - MenaceX^ - 28.08.2009

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


Re: [INC] zcmd v0.2.2 - member - 29.08.2009

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.


Re: [INC] zcmd v0.2.2 - Zeex - 29.08.2009

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



Re: [INC] zcmd v0.2.2 - member - 29.08.2009

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.


Re: [INC] zcmd v0.2.2 - Zeex - 29.08.2009

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.


Re: [INC] zcmd v0.2.2 - yezizhu - 29.08.2009

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


Re: [INC] zcmd v0.2.2 - Chris. - 01.09.2009

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


Re: [INC] zcmd v0.2.2 - cyber_punk - 01.09.2009

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.


Re: [INC] zcmd v0.2.2 - James_Alex - 01.09.2009

very nice job
this is really helpful for newbies and noobs


Re: [INC] zcmd | Fast & Simple Command Processor - Doktor - 24.10.2009

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?


Re: [INC] zcmd | Fast & Simple Command Processor - Dabombber - 24.10.2009

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?


Re: [INC] zcmd | Fast & Simple Command Processor - Danny_Costelo - 24.10.2009

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


Re: [INC] zcmd | Fast & Simple Command Processor - Zeex - 24.10.2009

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;
}



Re: [INC] zcmd | Fast & Simple Command Processor - Y_Less - 26.10.2009

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.