[Include] cMd (command processor)
#1

~~~ cMd v0.1a ~~~
Hello guys!
Today, I release some very small command processor, like almost everyone else did

It's very fast and REALLY SMALL (some test returned a time of 3ms! Please test yourself xD)

Usage (also included to the include )

- Use "do_cMd;" in "OnPlayerCommandText" to call the command like that:
pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
    // code ...
    do_cMd;
    // code ...
}
- Define Commands like that (PLEASE USE LOWERCASE LETTERS):
pawn Код:
cMd:command_name;
{
    // code ...
}
... as a standalone function like public or stock.

- playerid and params[] are available in every command, params[] includes the command's parameters you can split with sscanf

(Optional: you can use the variable "cMd" after "do_cMd;" to check if a command was called. It should return 1 then.)

Changelog:
[v0.1a]:
  • Made commands non-casesensitive. Please define commands with lowercase names
[v0.1]:
  • First release
Here you go: Download.
Pastebin

Greetz


PS: Critics and comments are welcome
Reply
#2

pawn Код:
format(cmdtext, 128, "cMd_%s"
looks good but here ^, your using publics right, the max length of a public is like what.. 39? or something.. so no need for 128
Reply
#3

Quote:
Originally Posted by Kar
Посмотреть сообщение
pawn Код:
format(cmdtext, 128, "cMd_%s"
looks good but here ^, your using publics right, the max length of a public is like what.. 39? or something.. so no need for 128
it's 32, yes
I'll change it

EDIT: Please someone test the speed ... I really got 2-4 milliseconds (GetTickCount)
Reply
#4

Very nice.
Reply
#5

change
if(!strlen(cMdtMp[1]))
to
if(isnull(cMdtMp[1]))

or even
if(sscanf(cmdtext[1], "sS(' ')", cMdtMp[0], cMdtMp[1]))
THE CORRECT CODE WOULD BE:

pawn Код:
#define do_cMd; \
new cMdtMp[2][128], cMd;  \
sscanf(cmdtext[1], "sS(' ')", cMdtMp[0], cMdtMp[1]) format(cmdtext, 32, "cMd_%s", cMdtMp[0]);\
if(funcidx(cmdtext) != -1) { if(!cMd) { cMd = 1; CallLocalFunction(cmdtext, "ds", playerid, cMdtMp[1]); } }
Not sure how default string is defined in sscanf.
However, if you don't use optional string in sscanf, then cMdtMp[0] will also be empty if there were no params.
Cheers.

Edit: You should make it NON case sensitive.
Reply
#6

It looks very good, but do you have some proof to support your 3ms-story? This sounds amazing!
Reply
#7

I have been waiting for a command processor from you Meta! Good job

(if it really is 3 ms, I'm gonna use it )
Reply
#8

show us your benchmark results ... why would anyone use it if you don't show us your test results ... i recommend you to use this benchmarking https://sampforum.blast.hk/showthread.php?tid=218491
Reply
#9

Quote:
Originally Posted by Nenad
Посмотреть сообщение
show us your benchmark results ... why would anyone use it if you don't show us your test results ... i recommend you to use this benchmarking https://sampforum.blast.hk/showthread.php?tid=218491
That was i wanted to say
Reply
#10

I see where you get the speed, but where is the case sensitive?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)