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

Description

This is just a little include that uses OnPlayerCommandText() to process players' commands. Each command has a separate function like in dcmd, but zcmd calls them directly via CallLocalFunction(). Such method is much faster than when you successively compare the text player entered to each command you have in your script (especially if he send a nonexistent cmd, you pass though all then) and its superiority over the old way is proportional to the number of commands. I did a speed test when I've just statrted thinking about this approach, you can find its results here.


Usage

All you need to add a command is just make a public function using special pre-defined macro, like this:

pawn Code:
COMMAND:mycommand(playerid, params[]) // or CMD:mycommand(playerid, params[])
{
  // Do something
  return 1;
}
or (old style):

pawn Code:
command(mycommand, playerid, params[]) // or cmd(mycommand, playerid, params[])
{
  // Do something
  return 1;
}
Here params[] is the parameters string, playerid is an ID of the player who send this command.
That's all! Very easy, isn't it?


Important: Since v0.3 OnPlayerCommandText cannot be used anymore (also ZCMD_NO_CALLBACK option has been removed), but there are two new callbacks instead:

pawn Code:
OnPlayerCommandReceived(playerid, cmdtext[])
This one is called when someone sends a command. If you return 0 here, the command won't be performed.

pawn Code:
OnPlayerCommandPerformed(playerid, cmdtext[], success)
And this one gets called after command execution, here if you do "return 0" the player will see standard "Unknown command" message. The "success" parameter is equal to value returned by command function returns (if it doesn't exist success will be 0).

Note that it's not necessary to add these callbacks to your script if you don't use them.


How to make two different commands doing the same thing

For example, you have /something cmd:

pawn Code:
COMMAND:something(playerid, params[])
{
  // some stuff here
  return 1;
}
and you want to create another one such as /another that does what /something does. The simpliest way of doing that is:

pawn Code:
COMMAND:another(playerid, params[])
{
  return cmd_something(playerid, params);
}

Note #1: If you want to use zcmd in a filterscript, put this define before including:

pawn Code:
#define FILTERSCRIPT
Note #2: If you want to check whether parameters string is empty you should not do it like:

pawn Code:
if (!strlen(params))
{
  // no parameters
}
or :

pawn Code:
if (!params[0])
because its length is never null (read more here), simply use isnull() included into zcmd:

pawn Code:
if (isnull(params))
Actually, if you use sscanf you don't need to do this as it has built-in isnull checking.

Here is an example of how you can make /givemoney command using zcmd with sscanf:

pawn Code:
COMMAND:givemoney(playerid, params[])
{
    if (IsPlayerAdmin(playerid))
    {
        new
          toplayerid, // the player we want to give money to
          amount;
        // extracting player's ID and amount from params
        if (!sscanf(params, "ii", toplayerid, amount))
        {
          if (toplayerid != INVALID_PLAYER_ID)
          {
            new
              message[40];
            GivePlayerMoney(toplayerid, amount);
            format(message, sizeof(message), "You got $%d from admin!", amount);
            SendClientMessage(toplayerid, 0x00FF00FF, message);
          }
          else SendClientMessage(playerid, 0xFF0000FF, "That player is not connected");
        }
        else SendClientMessage(playerid, 0xFFFFFFFF, "Usage: /givemoney <playerid> <amount>");
    }
    else SendClientMessage(playerid, 0xFF0000FF, "Only admins can use this command!");
    return 1;
}
Download

Special thanks to:
- ******
Reply


Messages In This Thread
[INC] zcmd 0.3.1 | Fast & Simple Command Processor (updated 30/10/2009) - by Zeex - 14.08.2009, 12:59
Re: [INC] zcmd - simple command system - by MatrixBoY - 14.08.2009, 13:13
Re: [INC] zcmd - simple command system - by nuriel8833 - 14.08.2009, 13:15
Re: [INC] zcmd - simple command system - by Zeex - 14.08.2009, 13:18
Re: [INC] zcmd - simple command system - by Agent_Smith - 14.08.2009, 13:36
Re: [INC] zcmd - simple command system - by .::: Ecko :::. - 14.08.2009, 21:23
Re: [INC] zcmd - simple command system [updated] - by Zeex - 15.08.2009, 03:15
Re: [INC] zcmd - simple command system [updated] - by Gappy - 15.08.2009, 04:53
Re: [INC] zcmd - simple command system [updated] - by Gappy - 15.08.2009, 06:11
Re: [INC] zcmd - simple command system [updated] - by Gappy - 15.08.2009, 06:34
Re: [INC] zcmd - simple command system [updated] - by Zeex - 15.08.2009, 07:01
Re: [INC] zcmd - simple command system [updated] - by Gappy - 15.08.2009, 07:15
Re: [INC] zcmd - simple command system [updated] - by Zeex - 15.08.2009, 08:07
Re: [INC] zcmd - simple command system [updated] - by Gappy - 15.08.2009, 08:38
Re: [INC] zcmd - simple command system [updated] - by [MeTalgEaR] - 15.08.2009, 13:23
Re: [INC] zcmd - simple command system [updated] - by GTA_Rules - 15.08.2009, 13:32
Re: [INC] zcmd - simple command system [updated] - by .::: Ecko :::. - 15.08.2009, 18:27
Re: [INC] zcmd - simple command system [updated] - by RayPoda - 16.08.2009, 02:16
Re: [INC] zcmd - simple command system [updated] - by Google63 - 16.08.2009, 10:16
Re: [INC] zcmd - simple command system [updated] - by kc - 16.08.2009, 10:32
Re: [INC] zcmd - simple command system [updated] - by nuriel8833 - 16.08.2009, 19:10
Re: [INC] zcmd v0.2.2 - by Sergei - 27.08.2009, 11:49
Re: [INC] zcmd v0.2.2 - by Zeex - 27.08.2009, 12:12
Re: [INC] zcmd v0.2.2 - by Sergei - 27.08.2009, 12:17
Re: [INC] zcmd v0.2.2 - by Zeex - 27.08.2009, 15:25
Re: [INC] zcmd v0.2.2 - by Sergei - 27.08.2009, 21:15
Re: [INC] zcmd v0.2.2 - by MenaceX^ - 28.08.2009, 15:01
Re: [INC] zcmd v0.2.2 - by member - 29.08.2009, 15:11
Re: [INC] zcmd v0.2.2 - by Zeex - 29.08.2009, 15:45
Re: [INC] zcmd v0.2.2 - by member - 29.08.2009, 16:05
Re: [INC] zcmd v0.2.2 - by Zeex - 29.08.2009, 16:46
Re: [INC] zcmd v0.2.2 - by yezizhu - 29.08.2009, 18:43
Re: [INC] zcmd v0.2.2 - by Chris. - 01.09.2009, 10:01
Re: [INC] zcmd v0.2.2 - by cyber_punk - 01.09.2009, 11:18
Re: [INC] zcmd v0.2.2 - by James_Alex - 01.09.2009, 13:53
Re: [INC] zcmd | Fast & Simple Command Processor - by Doktor - 24.10.2009, 13:55
Re: [INC] zcmd | Fast & Simple Command Processor - by Dabombber - 24.10.2009, 14:07
Re: [INC] zcmd | Fast & Simple Command Processor - by Danny_Costelo - 24.10.2009, 15:27
Re: [INC] zcmd | Fast & Simple Command Processor - by Zeex - 24.10.2009, 15:41
Re: [INC] zcmd | Fast & Simple Command Processor - by Y_Less - 26.10.2009, 12:28
Re: [INC] zcmd | Fast & Simple Command Processor - by MenaceX^ - 26.10.2009, 13:11
Re: [INC] zcmd | Fast & Simple Command Processor - by Zeex - 26.10.2009, 13:19
Re: [INC] zcmd | Fast & Simple Command Processor - by Dabombber - 26.10.2009, 23:55
Re: [INC] zcmd | Fast & Simple Command Processor - by Zeex - 27.10.2009, 14:41
Re: [INC] zcmd | Fast & Simple Command Processor - by NeRoSiS - 27.10.2009, 14:43
Re: [INC] zcmd 0.3.1 | Fast & Simple Command Processor (updated 30/10/2009) - by pziemczyk - 02.11.2009, 08:50
Re: [INC] zcmd 0.3.1 | Fast & Simple Command Processor (updated 30/10/2009) - by Zeex - 02.11.2009, 11:35
Re: [INC] zcmd 0.3.1 | Fast & Simple Command Processor (updated 30/10/2009) - by radhakr - 02.11.2009, 17:41
Re: [INC] zcmd 0.3.1 | Fast & Simple Command Processor (updated 30/10/2009) - by Luka P. - 02.11.2009, 17:55
Re: [INC] zcmd 0.3.1 | Fast & Simple Command Processor (updated 30/10/2009) - by Sergei - 02.11.2009, 17:57
Re: [INC] zcmd 0.3.1 | Fast & Simple Command Processor (updated 30/10/2009) - by Luka P. - 02.11.2009, 17:59
Re: [INC] zcmd 0.3.1 | Fast & Simple Command Processor (updated 30/10/2009) - by Sergei - 02.11.2009, 18:33
Re: [INC] zcmd 0.3.1 | Fast & Simple Command Processor (updated 30/10/2009) - by Zeex - 02.11.2009, 18:38
Re: [INC] zcmd 0.3.1 | Fast & Simple Command Processor (updated 30/10/2009) - by Luka P. - 02.11.2009, 18:55
Re: [INC] zcmd 0.3.1 | Fast & Simple Command Processor (updated 30/10/2009) - by Sergei - 23.11.2010, 14:43
Re: [INC] zcmd 0.3.1 | Fast & Simple Command Processor (updated 30/10/2009) - by FreshDoubleX - 23.11.2010, 14:45
Re: [INC] zcmd 0.3.1 | Fast & Simple Command Processor (updated 30/10/2009) - by Scenario - 23.11.2010, 14:46
Re: [INC] zcmd 0.3.1 | Fast & Simple Command Processor (updated 30/10/2009) - by FreshDoubleX - 23.11.2010, 14:48
Re: [INC] zcmd 0.3.1 | Fast & Simple Command Processor (updated 30/10/2009) - by Scenario - 23.11.2010, 15:29
Respuesta: [INC] zcmd 0.3.1 | Fast & Simple Command Processor (updated 30/10/2009) - by anonymousx - 23.11.2010, 23:52
Re: Respuesta: [INC] zcmd 0.3.1 | Fast & Simple Command Processor (updated 30/10/2009) - by Scenario - 24.11.2010, 01:13
Re: [INC] zcmd 0.3.1 | Fast & Simple Command Processor (updated 30/10/2009) - by IstuntmanI - 28.11.2010, 17:55
Respuesta: [INC] zcmd 0.3.1 | Fast & Simple Command Processor (updated 30/10/2009) - by [SOB]Chris - 30.11.2010, 04:36
Re: [INC] zcmd 0.3.1 | Fast & Simple Command Processor (updated 30/10/2009) - by IstuntmanI - 30.11.2010, 16:08
Respuesta: [INC] zcmd 0.3.1 | Fast & Simple Command Processor (updated 30/10/2009) - by [SOB]Chris - 01.12.2010, 03:21
Re: [INC] zcmd 0.3.1 | Fast & Simple Command Processor (updated 30/10/2009) - by Miguel - 21.01.2011, 20:03
AW: [INC] zcmd 0.3.1 | Fast & Simple Command Processor (updated 30/10/2009) - by Johann95 - 23.02.2011, 19:27
Re: [INC] zcmd 0.3.1 | Fast & Simple Command Processor (updated 30/10/2009) - by TheArcher - 09.09.2012, 10:57
Re: [INC] zcmd 0.3.1 | Fast & Simple Command Processor (updated 30/10/2009) - by NoahF - 09.09.2012, 11:47
Re: [INC] zcmd 0.3.1 | Fast & Simple Command Processor (updated 30/10/2009) - by Seven_of_Nine - 09.09.2012, 17:37
Re: [INC] zcmd 0.3.1 | Fast & Simple Command Processor (updated 30/10/2009) - by TheArcher - 09.09.2012, 17:52
Re: [INC] zcmd 0.3.1 | Fast & Simple Command Processor (updated 30/10/2009) - by Camacorn - 11.09.2012, 02:33
Re: [INC] zcmd 0.3.1 | Fast & Simple Command Processor (updated 30/10/2009) - by Tez2k7 - 24.09.2012, 22:47
Re: [INC] zcmd 0.3.1 | Fast & Simple Command Processor (updated 30/10/2009) - by TheArcher - 25.09.2012, 15:54
Re: [INC] zcmd 0.3.1 | Fast & Simple Command Processor (updated 30/10/2009) - by Yiin - 25.09.2012, 17:38
Re: [INC] zcmd 0.3.1 | Fast & Simple Command Processor (updated 30/10/2009) - by Plovix - 28.10.2012, 11:38
Re: [INC] zcmd 0.3.1 | Fast & Simple Command Processor (updated 30/10/2009) - by Lorenc_ - 20.11.2012, 08:01
Re: [INC] zcmd 0.3.1 | Fast & Simple Command Processor (updated 30/10/2009) - by Lightning[SV] - 20.11.2012, 17:08
Re: [INC] zcmd 0.3.1 | Fast & Simple Command Processor (updated 30/10/2009) - by Lorenc_ - 21.11.2012, 07:02
Re: [INC] zcmd 0.3.1 | Fast & Simple Command Processor (updated 30/10/2009) - by betopiaia - 24.11.2012, 14:45
Re: [INC] zcmd 0.3.1 | Fast & Simple Command Processor (updated 30/10/2009) - by shaPP - 24.11.2012, 15:02
Re: [INC] zcmd 0.3.1 | Fast & Simple Command Processor (updated 30/10/2009) - by betopiaia - 24.11.2012, 15:08
Re: [INC] zcmd 0.3.1 | Fast & Simple Command Processor (updated 30/10/2009) - by TheArcher - 24.11.2012, 16:39
Re: [INC] zcmd 0.3.1 | Fast & Simple Command Processor (updated 30/10/2009) - by Curtehs - 15.04.2013, 09:05
Re: [INC] zcmd 0.3.1 | Fast & Simple Command Processor (updated 30/10/2009) - by vent - 23.05.2015, 21:16
Re: [INC] zcmd 0.3.1 | Fast & Simple Command Processor (updated 30/10/2009) - by Yashas - 30.05.2015, 16:14
Re: [INC] zcmd 0.3.1 | Fast & Simple Command Processor (updated 30/10/2009) - by ownager122 - 23.06.2015, 11:59
Re: [INC] zcmd 0.3.1 | Fast & Simple Command Processor (updated 30/10/2009) - by Yashas - 23.06.2015, 15:21
Re: [INC] zcmd 0.3.1 | Fast & Simple Command Processor (updated 30/10/2009) - by Crayder - 23.06.2015, 17:38
Re: [INC] zcmd 0.3.1 | Fast & Simple Command Processor (updated 30/10/2009) - by dugi - 24.06.2015, 15:41
Re: [INC] zcmd 0.3.1 | Fast & Simple Command Processor (updated 30/10/2009) - by GShock - 24.06.2015, 17:18
Re: [INC] zcmd 0.3.1 | Fast & Simple Command Processor (updated 30/10/2009) - by Crayder - 24.06.2015, 17:30
Re: [INC] zcmd 0.3.1 | Fast & Simple Command Processor (updated 30/10/2009) - by Khanz - 24.06.2015, 20:45
Re: [INC] zcmd 0.3.1 | Fast & Simple Command Processor (updated 30/10/2009) - by Crayder - 24.06.2015, 21:20
Re : [INC] zcmd 0.3.1 | Fast & Simple Command Processor (updated 30/10/2009) - by Mehdi16 - 01.07.2015, 01:54
Re: Re : [INC] zcmd 0.3.1 | Fast & Simple Command Processor (updated 30/10/2009) - by XxBaDxBoYxX - 01.07.2015, 02:13
Re: [INC] zcmd 0.3.1 | Fast & Simple Command Processor (updated 30/10/2009) - by jamal1992 - 21.08.2015, 13:15
Re: [INC] zcmd 0.3.1 | Fast & Simple Command Processor (updated 30/10/2009) - by MBilal - 31.08.2015, 16:45
Re: [INC] zcmd 0.3.1 | Fast & Simple Command Processor (updated 30/10/2009) - by Alexv001 - 11.11.2015, 19:53
Re: [INC] zcmd 0.3.1 | Fast & Simple Command Processor (updated 30/10/2009) - by Ritzy2K - 11.11.2015, 20:05
Re: [INC] zcmd 0.3.1 | Fast & Simple Command Processor (updated 30/10/2009) - by N0FeaR - 12.11.2015, 06:54
Re: [INC] zcmd 0.3.1 | Fast & Simple Command Processor (updated 30/10/2009) - by Rokzlive - 13.01.2016, 20:09
Re: [INC] zcmd 0.3.1 | Fast & Simple Command Processor (updated 30/10/2009) - by Crayder - 13.01.2016, 20:11
Re: [INC] zcmd 0.3.1 | Fast & Simple Command Processor (updated 30/10/2009) - by Mobtiesgangsa - 28.05.2017, 00:00
Re: [INC] zcmd 0.3.1 | Fast & Simple Command Processor (updated 30/10/2009) - by metelicgamer - 08.10.2017, 13:00
Re: [INC] zcmd 0.3.1 | Fast & Simple Command Processor (updated 30/10/2009) - by RoyalEmpire - 08.10.2017, 13:50
Re: [INC] zcmd 0.3.1 | Fast & Simple Command Processor (updated 30/10/2009) - by whadez - 08.10.2017, 14:31
Re: [INC] zcmd 0.3.1 | Fast & Simple Command Processor (updated 30/10/2009) - by Variable™ - 08.10.2017, 15:04
Re: [INC] zcmd 0.3.1 | Fast & Simple Command Processor (updated 30/10/2009) - by Gabi3 - 29.01.2019, 15:29
Re: [INC] zcmd 0.3.1 | Fast & Simple Command Processor (updated 30/10/2009) - by Botato - 23.06.2019, 21:54
Re: [INC] zcmd 0.3.1 | Fast & Simple Command Processor (updated 30/10/2009) - by bielgera1 - 11.05.2020, 06:34

Forum Jump:


Users browsing this thread: 2 Guest(s)