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

Quote:
Originally Posted by Y_Leѕѕ
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.
I like that method, infact. I'm going to use this one with a lil change.
Reply
#42

Quote:
Originally Posted by Y_Leѕѕ
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.
Yeah, this one doesn't look so ugly
I will add this now, but keepiing the old macros though, for compatibility and those who like it more (if any).
Thanks.
Reply
#43

I guess I should have given an example oh well, next suggestion. What about including a YSI style help system? I'm not 100% percent sure but public functions seem to be ok if you pass extra arguments, so you could change the local function calls from
pawn Код:
CallLocalFunction(funcname, "is", playerid, cmdtext[pos])
to
pawn Код:
CallLocalFunction(funcname, "isi", playerid, cmdtext[pos], false)
without any compatibility problems. If you prefer it could be a compile option, but it shouldn't be necessary.

Then all that's needed is a function like
pawn Код:
stock ZCMD_FunctionHelp(const playerid, const command[])
{
    new funcname[MAX_COMM_FUNC_NAME] = "zcmd_";
    for(new pos = 5; pos < sizeof(funcname) - 1 && command[pos - 5] > ' '; pos++) {
        funcname[pos] = tolower(command[pos - 5]);
    }
    return CallLocalFunction(funcname, "isi", playerid, "\1", true);
}
and if the scripters want, they can do stuff like
pawn Код:
ZCMD:something(playerid, params[], bool:help)
{
    if(help) {
        SendClientMessage(playerid, 0x00FF00FF, "This command does something");
        return 1;
    }
    // do something
    return 1;
}

ZCMD:help(playerid, params[], bool:help)
{
    if(help) {
        SendClientMessage(playerid, 0x00FF00FF, "This command displays help");
    } else if(isnull(params)) {
        SendClientMessage(playerid, 0x00FF00FF, "Server info or something...");
    } else if(!ZCMD_FunctionHelp(playerid, params)) {
        SendClientMessage(playerid, 0x00FF00FF, "Unknown command. Type /commands for a list of commands");
    }
    return 1;
}
As long as they don't use the ZCMD_FunctionHelp function the ZCMD:command(playerid, params[]) format should work as before.
Reply
#44

Updated again, check the frist post please.


@Dabombber, you can do this instead:
pawn Код:
COMMAND:something(playerid, params[])
{
    if (!strcmp(params, "help", true, 4)) {
        SendClientMessage(playerid, 0x00FF00FF, "This command does something");
        return 1;
    }
    // do something
    return 1;
}
Edit:
You can do even better, with a simple define:
pawn Код:
#define HELP (!strcmp(params, "help", true, 4))
COMMAND:something(playerid, params[])
{
    if (HELP) {
        SendClientMessage(playerid, 0x00FF00FF, "This command does something");
        return 1;
    }
    // do something
    return 1;
}
Reply
#45

This is so simple to use and really effective, nice on Zeex.

Also, the admin system I recently released uses it, nice one.
Reply
#46

Oh yes, i using servermoneyGM.
Eh, anybody know how reconcile servermoneyGM and zcmd?

edit:
how to change default SERVER: Unknown Command?
Reply
#47

Quote:
Originally Posted by pziemczyk
Oh yes, i using servermoneyGM.
Eh, anybody know how reconcile servermoneyGM and zcmd?
You can ignore that warning, but I hope that include's author will fix it somewhen.

Quote:
Originally Posted by pziemczyk
how to change default SERVER: Unknown Command?
pawn Код:
public OnPlayerCommandPerformed(playerid, cmdtext[], success)
{
    if (!success)
    {
        SendClientMessage(playerid, 0xFF0000FF, "your message here");
    }
    return 1;
}
Reply
#48

With strcmp you can easily make 2 commands that do the same thing like this:

pawn Код:
if (strcmp("/mycommand", cmdtext, true, 10) == 0 || strcmp("/mycmd", cmdtext, true, 10) == 0)
{
    // Do something here
    return 1;
}
How do you do this with zcmd please?
Reply
#49

Quote:
Originally Posted by radhakr
With strcmp you can easily make 2 commands that do the same thing like this:

pawn Код:
if (strcmp("/mycommand", cmdtext, true, 10) == 0 || strcmp("/mycmd", cmdtext, true, 10) == 0)
{
    // Do something here
    return 1;
}
How do you do this with zcmd please?
I'm interessted, too
Reply
#50

pawn Код:
COMMAND:cmd1(playerid,params[])
{
    return 1;
}
COMMAND:cmd2(playerid,params[])
{
    return cmd_cmd1(playerid,params[]);
}
Reply
#51

Yea, I know that. But there's no simplified way, but
pawn Код:
COMMAND:cmd1(playerid,params[])
{
    return 1;
}
COMMAND:cmd2(playerid,params[])
{
    return cmd_cmd1(playerid,params[]);
}
Reply
#52

Actually you can make it a bit better:

pawn Код:
COMMAND:cmd1(playerid,params[])
{
    return 1;
}
CMD:cmd2(playerid,params[]) return cmd_cmd1(playerid,params[]);
Reply
#53

You can also add simple macro like this:
pawn Код:
#define ALTCOMMAND:%1->%2;           \
            COMMAND:%1(playerid, params[])   \
                return cmd_%2(playerid, params);
and then do:
pawn Код:
COMMAND:cmd1(playerid, params[])
{
    SendClientMessage(playerid, 0xFFFFFFFF, "test message");
    return 1;
}

ALTCOMMAND:cmd2->cmd1;
ALTCOMMAND:cmd3->cmd1;
Reply
#54

Hey, here's mine first zcmd + sscanf command (/getip).
It is really easy to use sscanf (+zcmd).
pawn Код:
COMMAND:getip(playerid,params[])
{
    new   ip[32],
        string[128],
        pName[MAX_PLAYER_NAME],
        player;
   
    if(sscanf(params,"u",player)) return SendClientMessage(playerid,0xFFFFFFAA,"USAGE: /getip [playerid/name]");
    else if(player == INVALID_PLAYER_ID) return SendClientMessage(playerid,0xFFFFFFAA,"Invalid player ID!");
    else
    {
      GetPlayerIp(playerid,ip,sizeof(ip));
        GetPlayerName(player,pName,sizeof(pName));
       
        if(player == playerid) format(string,sizeof(string),"Your IP is %s.",ip);
        else format(string,sizeof(string),"%s's IP is %s",pName,ip);
       
        SendClientMessage(playerid,0xFFFFFFAA,string);
    }
    return 1;
}
Without looking at wiki or forum
Reply
#55

Quote:
Originally Posted by RealCop228
Посмотреть сообщение
command(/goto, playerid, params[])... How dumb of a question was that?
command(goto, playerid, params[])... How dumb suggestion was that?
Reply
#56

Quote:
Originally Posted by Sergei
Посмотреть сообщение
command(goto, playerid, params[])... How dumb suggestion was that?
OMG ? And cmd 'll be //Goto ? I don't think so.
Reply
#57

Quote:
Originally Posted by FreshDoubleX
Посмотреть сообщение
Hey, I need help.
How can I do cmd with ZCMD like //GOTO ..etc, not /GOTO.
Quote:
Originally Posted by Sergei
Посмотреть сообщение
command(goto, playerid, params[])... How dumb suggestion was that?
You should learn to read.


pawn Код:
CMD:/goto(playerid, params[])
Can also be used.
Reply
#58

Oke, Thank you, I know it now
Reply
#59

Quote:
Originally Posted by xNiteX
Посмотреть сообщение
I don't get it.. How are we supposed to use ZCMD with other command processors? Like I wanna use zcmd, dcmd & strcmp, but friend of mine told me that if I use zcmd only zcmd commands will work.. I also tried that, and only zcmd commands worked..
ZCMD isn't natively compatible with strcmp, or dcmd. You have to make it work with it, which I'm not sure how to do. Why would you want to use the two slowest command processors, with the fasted command processor? It doesn't make any sense.
Reply
#60

Quote:
Originally Posted by Nero_3D
Посмотреть сообщение
Yes they are all compatible, you just need to know how they work

strcmp
Can be used everywhere
dcmd
Can be used everywhere, too
zcmd
Implants code on OnPlayerCommandText and disable the public (that's mentioned in the zcmd topic, too)
Before version 0.3 (of zcmd) you could have used OnPlayerCommandText
But now just add OnPlayerCommandReceived or OnPlayerCommandPerformed

And here an example that should work with all three types (yes you just could put both say commands together...)

pawn Код:
cmd_say(playerid, params[]) //zcmd
{
  new string[154]; //max input (124) + MAX_PLAYER_NAME (24) + " says " (6)
  GetPlayerName(playerid, string, MAX_PLAYER_NAME);
  format(string, sizeof string, "%s says %s", string, params);
  return SendClientMessage(playerid, GetPlayerColor(playerid), string);
}

public OnPlayerCommandReceived(playerid, cmdtext[]) //zcmd public
{
  if(IsPlayerAdmin(playerid))
  {
    if(strcmp("say", cmdtext[1], true, 3) == 0) //needed cuz of this public
    {
      dcmd(say, 3, cmdtext);
      return 0;
    }
  }
  return 1;
}

dcmd_say(playerid, params[]) //dcmd
{
  new string[135]; //max input (124) + "ADMIN says " (11)
  format(string, sizeof string, "ADMIN says %s", params);
  return !SendClientMessage(playerid, 0x0000BBAA, string);
}
Yeah there compatible, check this.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)