[Include] h_Cmd | Command processor
#1

h_Cmd


The h_Cmd has the primary purpose of processing commands with ease and still delete the famous use of sscanf in commands. It is based on CallLocalFunction and function Split (split by delimiters).


Attention:
I'm not good in english, are used the help of translator..
Functions
pawn Код:
SPLIT<number> //Used to get a string from a command argument.
SPLIT_INT<number> //Used to get a number from a command argument.
SPLIT_FLOAT<number> //Used to get a float from a command argument.
TOTAL_SPLIT<> //Returns the total of arguments placed in command .. Example: "/x [arg1] [arg2] [arg3]" returns the value 3.
forward OnPlayerExecuteCommand(playerid, cmdtext[], bool:sucess); //Callback designed to block or detect if the command does not exist.
Learn
pawn Код:
h_Cmd("/gta")
{
    SendClientMessage(playerid, -1, "I'm testing");
    return true;
}

h_Cmd("/telepos")
{
    if(TOTAL_SPLIT<> != 3) //TOTAL_SPLIT<> Returns the total amount of arguments in the example here is 3.
    {
        SendClientMessage(playerid, -1, "Uso: /telepos [X] [Y] [Z]");
        return true;
    }
    SetPlayerPos(playerid, SPLIT_FLOAT<1>, SPLIT_FLOAT<2>, SPLIT_FLOAT<3>); //SPLIT_FLOAT<number> returns the total amount of arguments in the example here is 3..
    return true;
}

h_Cmd("/ann")
{
    if(!TOTAL_SPLIT<>) //TOTAL_SPLIT<> returns the number of arguments after the command
    {
        SendClientMessage(playerid, -1, "Uso: /ann [Announce]");
        return true;
    }
    new string[144];
    format(string, 144, "ANNOUNCE: %s",SPLIT<1>); //SPLIT<number> get the number 1 used in the command argument. Ex: /ann [Argument 1].. Returns in string.
    SendClientMessageToAll(-1, string);
    return true;
}

h_Cmd("/number")
{
    if(!TOTAL_SPLIT<>) //TOTAL_SPLIT<> returns the number of arguments after the command
    {
        SendClientMessage(playerid, -1, "Uso: /number [your number]");
        return true;
    }
    new string[144];
    format(string, 144, "MY NUMBER: %d",SPLIT_INT<1>); //SPLIT_INT<number> get the number 1 used in the command argument. Ex: /number [Argument 1].. Returns in number.
    SendClientMessageToAll(-1, string);
    return true;
}

public OnPlayerExecuteCommand(playerid, cmdtext[], bool:sucess)
{
    if(sucess == false) return SendClientMessage(playerid, 0xFFFF00FF, "[INFO] UNKNOWN COMMAND"); //Example
    if(!strcmp(cmdtext, "/gta", true))//Example to block command
    {
        SendClientMessage(playerid, -1, "COMMAND INHIBIT");
        return false;
    }
    return true;
}
Important
  1. Like all other systems of the command processors, the h_Cmd will lock the controls created in OnPlayerCommandText(); in the script you are using is include.
Installation
  1. Enter the include after the include "a_samp".
Download Include Changelog
  • 0.1 Initial release.
Credits
Attention:
Not give permission for any alleged or posting on another forum of this forum.
Reply
#2

Nice. Hope to see more releases from you.
Going to test it and report you any bug, if found.
Reply
#3

Nice, I will test it
Reply
#4

Mind doing some test with ZCMD and y_cmds? Also, using split function is very slow as compared to sscanf, try to use sscanf and see the results.
Reply
#5

Quote:
Originally Posted by UnknownOwner
Посмотреть сообщение
Nice. Hope to see more releases from you.
Going to test it and report you any bug, if found.
Thank you, but there are other releases in the Portuguese area will translate soon

Quote:
Originally Posted by FailerZ
Посмотреть сообщение
Nice, I will test it
Thanks "bro"

Quote:
Originally Posted by iZN
Посмотреть сообщение
Mind doing some test with ZCMD and y_cmds? Also, using split function is very slow as compared to sscanf, try to use sscanf and see the results.
Its introduction has already warned that the use is not required .. I'm still optimizing is more include any claim of bug is acceptable at this time ...
Reply
#6

I really don't see the need for more command processors on top of that this offers nothing better than what is already available.
Reply
#7

Quote:
Originally Posted by [uL]Pottus
Посмотреть сообщение
I really don't see the need for more command processors on top of that this offers nothing better than what is already available.
I believe that there will always be an evolution... this system has a facility to create commands with arguments..
Reply
#8

This maybe a somehow good. But i dont think so sscanf can be compete due to its unique features example: optional parameter / combined arguments / and more..
However this is a basic implementation of some of functionality.

And yes some comparison will be helpful.
Reply
#9

Using sscanf and y_cmd its much faster than use this

Anyway nice work.
Reply
#10

Quote:
Originally Posted by PT
Посмотреть сообщение
Using sscanf and y_cmd its much faster than use this

Anyway nice work.
It's faster that way but in his defense it's pointless to even measure command processing speed because you'll never have more than a few commands per second even on a large server speed measurements don't even come close to real world practice.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)